Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Expand inlined delegate calls in correct order #89175

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4958,9 +4958,14 @@ GenTree* Lowering::LowerDelegateInvoke(GenTreeCall* call)

GenTree* newThis = comp->gtNewIndir(TYP_REF, newThisAddr);

BlockRange().InsertAfter(thisExpr, newThisAddr, newThis);

// Insert the new 'this' arg right before the call to get the correct null
// behavior (the NRE that would logically happen inside Delegate.Invoke
// should happen after all args are evaluated). We must also move the
// PUTARG_REG node ahead.
thisArgNode->AsOp()->gtOp1 = newThis;
BlockRange().Remove(thisArgNode);
BlockRange().InsertBefore(call, newThisAddr, newThis, thisArgNode);

ContainCheckIndir(newThis->AsIndir());

// the control target is
Expand Down
38 changes: 38 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_75832/Runtime_75832.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.CompilerServices;
using Xunit;

public class Runtime_75832
{
[Fact]
public static int TestEntryPoint()
{
try
{
Test(0);
Console.WriteLine("FAIL: No exception thrown");
}
catch (DivideByZeroException)
{
return 100;
}
catch (Exception ex)
{
Console.WriteLine("FAIL: Caught {0}", ex.GetType().Name);
}

return 101;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test(int i)
{
GetAction()(100 / i);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static Action<int> GetAction() => null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<DebugType>None</DebugType>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>