-
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: Fix constrained call dereferences happening too early #86638
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/tests/JIT/Regression/JitBlue/Runtime_73615/Runtime_73615.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Reference source for Runtime_73615.il. | ||
|
||
using InlineIL; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
|
||
public class Runtime_73615 | ||
{ | ||
[Fact] | ||
public static int TestEntryPoint() | ||
{ | ||
Foo(new C(101)); | ||
|
||
if (Result == 100) | ||
{ | ||
Console.WriteLine("PASS"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("FAIL: Got result {0}", Result); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the autogenerated harness will already display failure information. |
||
|
||
return Result; | ||
} | ||
|
||
public static int Result; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static void Foo(C arg) | ||
{ | ||
IL.Emit.Ldarga(nameof(arg)); | ||
IL.Emit.Ldarga(nameof(arg)); | ||
IL.Emit.Call(new MethodRef(typeof(Runtime_73615), nameof(Bar))); | ||
IL.Emit.Constrained<C>(); | ||
IL.Emit.Callvirt(new MethodRef(typeof(C), nameof(arg.Baz))); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static int Bar(ref C o) | ||
{ | ||
o = new C(100); | ||
return 0; | ||
} | ||
|
||
public class C | ||
{ | ||
public C(int result) => Result = result; | ||
public int Result; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public void Baz(int arg) | ||
{ | ||
Runtime_73615.Result = Result; | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/tests/JIT/Regression/JitBlue/Runtime_73615/Runtime_73615.il
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
.assembly extern System.Runtime { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) } | ||
.assembly extern xunit.core { } | ||
.assembly extern System.Console { } | ||
|
||
.assembly Runtime_73615 { } | ||
|
||
.class public auto ansi beforefieldinit Runtime_73615 | ||
extends [System.Runtime]System.Object | ||
{ | ||
.class auto ansi nested public beforefieldinit C | ||
extends [System.Runtime]System.Object | ||
{ | ||
.field public int32 Result | ||
.method public hidebysig specialname rtspecialname | ||
instance void .ctor(int32 result) cil managed | ||
{ | ||
// Code size 14 (0xe) | ||
.maxstack 8 | ||
IL_0000: ldarg.0 | ||
IL_0001: call instance void [System.Runtime]System.Object::.ctor() | ||
IL_0006: ldarg.0 | ||
IL_0007: ldarg.1 | ||
IL_0008: stfld int32 Runtime_73615/C::Result | ||
IL_000d: ret | ||
} // end of method C::.ctor | ||
|
||
.method public hidebysig instance void | ||
Baz(int32 arg) cil managed noinlining | ||
{ | ||
// Code size 12 (0xc) | ||
.maxstack 8 | ||
IL_0000: ldarg.0 | ||
IL_0001: ldfld int32 Runtime_73615/C::Result | ||
IL_0006: stsfld int32 Runtime_73615::Result | ||
IL_000b: ret | ||
} // end of method C::Baz | ||
|
||
} // end of class C | ||
|
||
.field public static int32 Result | ||
.method public hidebysig static int32 Main() cil managed | ||
{ | ||
.custom instance void [xunit.core]Xunit.FactAttribute::.ctor() = ( 01 00 00 00 ) | ||
.entrypoint | ||
// Code size 59 (0x3b) | ||
.maxstack 8 | ||
IL_0000: ldc.i4.s 101 | ||
IL_0002: newobj instance void Runtime_73615/C::.ctor(int32) | ||
IL_0007: call void Runtime_73615::Foo(class Runtime_73615/C) | ||
IL_000c: ldsfld int32 Runtime_73615::Result | ||
IL_0011: ldc.i4.s 100 | ||
IL_0013: bne.un.s IL_0021 | ||
|
||
IL_0015: ldstr "PASS" | ||
IL_001a: call void [System.Console]System.Console::WriteLine(string) | ||
IL_001f: br.s IL_0035 | ||
|
||
IL_0021: ldstr "FAIL: Got result {0}" | ||
IL_0026: ldsfld int32 Runtime_73615::Result | ||
IL_002b: box [System.Runtime]System.Int32 | ||
IL_0030: call void [System.Console]System.Console::WriteLine(string, | ||
object) | ||
IL_0035: ldsfld int32 Runtime_73615::Result | ||
IL_003a: ret | ||
} // end of method Runtime_73615::TestEntryPoint | ||
|
||
.method private hidebysig static void Foo(class Runtime_73615/C arg) cil managed noinlining | ||
{ | ||
// Code size 21 (0x15) | ||
.maxstack 2 | ||
IL_0000: ldarga.s arg | ||
IL_0002: ldarga.s arg | ||
IL_0004: call int32 Runtime_73615::Bar(class Runtime_73615/C&) | ||
IL_0009: constrained. Runtime_73615/C | ||
IL_000f: callvirt instance void Runtime_73615/C::Baz(int32) | ||
IL_0014: ret | ||
} // end of method Runtime_73615::Foo | ||
|
||
.method private hidebysig static int32 | ||
Bar(class Runtime_73615/C& o) cil managed noinlining | ||
{ | ||
// Code size 11 (0xb) | ||
.maxstack 8 | ||
IL_0000: ldarg.0 | ||
IL_0001: ldc.i4.s 100 | ||
IL_0003: newobj instance void Runtime_73615/C::.ctor(int32) | ||
IL_0008: stind.ref | ||
IL_0009: ldc.i4.0 | ||
IL_000a: ret | ||
} // end of method Runtime_73615::Bar | ||
|
||
.method public hidebysig specialname rtspecialname | ||
instance void .ctor() cil managed | ||
{ | ||
// Code size 7 (0x7) | ||
.maxstack 8 | ||
IL_0000: ldarg.0 | ||
IL_0001: call instance void [System.Runtime]System.Object::.ctor() | ||
IL_0006: ret | ||
} // end of method Runtime_73615::.ctor | ||
|
||
} // end of class Runtime_73615 |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_73615/Runtime_73615.ilproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.IL"> | ||
<PropertyGroup> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).il" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall exactly what a "global effect" is in this context. Could the same issue happen if the this pointer was from a loaded field rather than a local?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spillGlobEffects
here means to also spill nodes that read heap memory, in addition to all other side effects. We don't need to spill those because inserting an indirection doesn't modify global state.The same issue can happen if the pointer is from a loaded field, but the spill here is still sufficient (anything that can modify global memory will be spilled even without
spillGlobEffects
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍