Skip to content

Commit

Permalink
Fix mono arm assert with large return structs (#77854)
Browse files Browse the repository at this point in the history
* Fix mono arm assert with large return structs

When the return struct is large the store instruction offset is too
large. When this happens, put the large offset in a register.

* Adding JIT test for large return structs
  • Loading branch information
bholmes committed Nov 6, 2022
1 parent 096cce9 commit 94cbc49
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mono/mono/mini/mini-arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6313,8 +6313,12 @@ mono_arch_emit_prolog (MonoCompile *cfg)
if (cinfo->ret.storage == RegTypeStructByAddr) {
ArgInfo *ainfo = &cinfo->ret;
inst = cfg->vret_addr;
g_assert (arm_is_imm12 (inst->inst_offset));
ARM_STR_IMM (code, ainfo->reg, inst->inst_basereg, inst->inst_offset);
if (arm_is_imm12 (inst->inst_offset)) {
ARM_STR_IMM (code, ainfo->reg, inst->inst_basereg, inst->inst_offset);
} else {
code = mono_arm_emit_load_imm (code, ARMREG_LR, inst->inst_offset);
ARM_STR_REG_REG (code, ainfo->reg, inst->inst_basereg, ARMREG_LR);
}
}

if (sig->call_convention == MONO_CALL_VARARG) {
Expand Down
37 changes: 37 additions & 0 deletions src/tests/JIT/Regression/JitBlue/GitHub_77854/GitHub_77854.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;
using System.Runtime.InteropServices;

public class Program
{
public static int Main(string[] args)
{
new Program().TestFunction();
return 100;
}

private TestStruct CreateStruct(FourKStruct s, int i)
{
return new TestStruct { s = s, i = i };
}

private TestStruct TestFunction()
{
return CreateStruct(new FourKStruct(), 42);
}

private struct TestStruct
{
public FourKStruct s;
public int i;
}
}

[StructLayout(LayoutKind.Sequential, Size=4096)]
public partial struct FourKStruct
{
internal byte bytes;
}
12 changes: 12 additions & 0 deletions src/tests/JIT/Regression/JitBlue/GitHub_77854/GitHub_77854.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 94cbc49

Please sign in to comment.