Skip to content

Commit

Permalink
Do not assume return type ABIs match in RETURN(CALL) (dotnet#72285)
Browse files Browse the repository at this point in the history
* Do not assume calling conventions match

When importing GT_RETURN.

* Add a test

* Disable the test on Mono
  • Loading branch information
SingleAccretion committed Jul 21, 2022
1 parent cf7685b commit 8c6c5ad
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11052,7 +11052,7 @@ GenTree* Compiler::impFixupStructReturnType(GenTree* op,
return op;
}

if (op->gtOper == GT_CALL)
if (op->IsCall() && (op->AsCall()->GetUnmanagedCallConv() == unmgdCallConv))
{
return op;
}
Expand Down
31 changes: 31 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_72265/Runtime_72265.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

unsafe class Runtime_72265
{
private static int Main()
{
var unmanaged = ((delegate* unmanaged<StructWithIndex>)&GetStructUnmanaged)();
var managed = GetStructManaged();

return !unmanaged.Equals(managed) ? 101 : 100;
}

[UnmanagedCallersOnly]
private static StructWithIndex GetStructUnmanaged()
{
return GetStructManaged();
}

[MethodImpl(MethodImplOptions.NoInlining)]
static StructWithIndex GetStructManaged() => new StructWithIndex { Index = 10, Value = 11 };

struct StructWithIndex
{
public int Index;
public int Value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,9 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_34587/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_72265/**">
<Issue>https://github.com/dotnet/runtime/issues/72016</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/VS-ia64-JIT/V1.2-M02/b10828/**">
<Issue>needs triage</Issue>
</ExcludeList>
Expand Down

0 comments on commit 8c6c5ad

Please sign in to comment.