-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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: Late expansion of delegate calls can reorder null checks with other argument exceptions #75832
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsThe JIT inlines delegate calls, which is done in lowering by inserting indirections to fetch the instance and target from the delegate object. However, the indirection that fetches the instance is inserted right after the existing 'this' argument node. This can reorder the null-check of the delegate object with exceptions thrown by other arguments. For example, the following example throws public static void Main()
{
Test(0);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test(int i)
{
GetAction()(100 / i);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static Action<int> GetAction() => null;
|
Expand delegate calls in morph to allow CSE'ing and hoisting of delegate targets/instances. Fix dotnet#75832 Close dotnet#75255
The access of the target instance was incorrectly inserted right after the location of the delegate instance. Since this indirection can throw a NRE this is incorrect; to get the proper inlined behavior, the indirection must happen only after all arguments have been evaluated. Fix dotnet#75832
The access of the target instance was incorrectly inserted right after the location of the delegate instance. Since this indirection can throw a NRE this is incorrect; to get the proper inlined behavior, the indirection must happen only after all arguments have been evaluated. Fix #75832
The JIT inlines delegate calls, which is done in lowering by inserting indirections to fetch the instance and target from the delegate object. However, the indirection that fetches the instance is inserted right after the existing 'this' argument node. This can reorder the null-check of the delegate object with exceptions thrown by other arguments.
For example, the following example throws
NullReferenceException
in release. It should throwDivisionByZeroException
(as it does in debug).category:correctness
theme:delegates
skill-level:intermediate
cost:small
impact:small
The text was updated successfully, but these errors were encountered: