Skip to content

Commit

Permalink
[NativeAOT-LLVM] Fix missing helper info for CORINFO_UNBOX_TYPETEST (
Browse files Browse the repository at this point in the history
…dotnet#2659)

* Add a test

* Fix missing helper info for CORINFO_UNBOX_TYPETEST
  • Loading branch information
SingleAccretion committed Aug 13, 2024
1 parent fec5053 commit d04118c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/jit/llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ bool Llvm::helperCallMayPhysicallyThrow(CorInfoHelpFunc helperFunc) const
{ FUNC(CORINFO_HELP_BOX) CORINFO_TYPE_CLASS, { CORINFO_TYPE_PTR, CORINFO_TYPE_BYREF }, HFIF_SS_ARG },
{ FUNC(CORINFO_HELP_BOX_NULLABLE) CORINFO_TYPE_CLASS, { CORINFO_TYPE_PTR, CORINFO_TYPE_BYREF }, HFIF_SS_ARG },
{ FUNC(CORINFO_HELP_UNBOX) CORINFO_TYPE_BYREF, { CORINFO_TYPE_PTR, CORINFO_TYPE_CLASS }, HFIF_SS_ARG },
{ FUNC(CORINFO_HELP_UNBOX_TYPETEST) },
{ FUNC(CORINFO_HELP_UNBOX_TYPETEST) CORINFO_TYPE_VOID, { CORINFO_TYPE_PTR, CORINFO_TYPE_PTR }, HFIF_SS_ARG },
{ FUNC(CORINFO_HELP_UNBOX_NULLABLE) CORINFO_TYPE_VOID, { CORINFO_TYPE_BYREF, CORINFO_TYPE_PTR, CORINFO_TYPE_CLASS }, HFIF_SS_ARG },

// Implemented in "CoreLib\src\Internal\Runtime\CompilerHelpers\TypedReferenceHelpers.cs".
Expand Down
21 changes: 21 additions & 0 deletions src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ private static unsafe int Main(string[] args)

TestJitUseStruct();

TestStackAllocatedBox();

TestMismatchedStructLocalFieldStore();

TestUnsafe();
Expand Down Expand Up @@ -476,6 +478,25 @@ private unsafe static void TestJitUseStruct()
EndTest(res.Index == structWithIndex.Index && res.Value == structWithIndex.Value);
}

private static void TestStackAllocatedBox()
{
StartTest("Test a stack-allocated box");

// Step 1: allocate the box.
object box = DayOfWeek.Friday;
// Step 2: make sure it appears used to Roslyn, etc.
static void Use(ref object _) { }
Use(ref box);
// Step 3: unbox it as a different type to make sure the Jit
// uses the unbox type test helper.
if (Environment.GetEnvironmentVariable("NEVER") is "HIT")
{
_ = (long)box;
}
// Add in another tricky type test for good measure.
EndTest((int)box == (int)DayOfWeek.Friday);
}

public struct StructWrapper
{
public readonly Guid WrappedStruct;
Expand Down

0 comments on commit d04118c

Please sign in to comment.