-
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
Forbid - byref cnst
-> + (byref -cnst)
transformation.
#44266
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
546cc65
Add a repro test.
660dad6
Forbid the transformation for byrefs.
db8b3ff
Update src/coreclr/src/jit/morph.cpp
6318887
Update src/coreclr/src/jit/morph.cpp
AndyAyersMS 8d1d5d4
Fix the test return value.
f81f6c9
improve the test.
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
63 changes: 63 additions & 0 deletions
63
src/tests/JIT/Regression/JitBlue/Runtime_44266/Runtime_44266.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,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// This test shows an inlining of `byref LCL_VAR_ADDR - byref CNST_INT` method that returns a native int. | ||
// However, Jit could try to optimize `-` as `+ -CNST_INT` that could lead to an incorrect `long + (-byref)`. | ||
|
||
.assembly extern System.Console {} | ||
.assembly extern legacy library mscorlib {} | ||
.assembly byrefsubbyref1 { } | ||
.class a extends [mscorlib]System.Object | ||
{ | ||
.field static class ctest S_1 | ||
.method public static native int byrefsubbyref(class ctest& V_1, class ctest& V_2) aggressiveinlining | ||
{ | ||
ldarg 0 | ||
ldarg 1 | ||
sub | ||
ret | ||
} | ||
|
||
.method public static int32 main() cil managed | ||
{ | ||
.entrypoint | ||
.maxstack 2 | ||
.locals init (class ctest V_1, | ||
class ctest V_2, | ||
native int V_3) | ||
newobj instance void ctest::.ctor() | ||
stloc.0 | ||
newobj instance void ctest::.ctor() | ||
dup | ||
stsfld class ctest a::S_1 | ||
stloc.1 | ||
|
||
ldloca V_1 | ||
ldsflda class ctest a::S_1 | ||
call native int a::byrefsubbyref(class ctest&, class ctest&) | ||
stloc V_3 | ||
ldloc V_3 | ||
call void a::KeepA(native int) | ||
ldc.i4.s 100 | ||
ret | ||
} | ||
|
||
.method public hidebysig static void KeepA(native int a) cil managed noinlining | ||
{ | ||
.maxstack 8 | ||
ret | ||
} | ||
} | ||
|
||
.class private auto ansi ctest | ||
extends [mscorlib]System.Object | ||
{ | ||
.method public specialname rtspecialname | ||
instance void .ctor() cil managed | ||
{ | ||
.maxstack 1 | ||
ldarg.0 | ||
call instance void [mscorlib]System.Object::.ctor() | ||
ret | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/tests/JIT/Regression/JitBlue/Runtime_44266/Runtime_44266.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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.IL"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).il" /> | ||
</ItemGroup> | ||
</Project> |
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.
Do you need conv.i4 before returning the value? Stack has
native int
, but method returnsint32
.If you need the method to return 100, you could allocate a 101 element array and subtract the managed reference between the first element and last element.
The difference between a stack location and a static field that this is returning right now is a very random number.
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.
You are right, I will fix the test to always return 100 instead of a random number.
I am not an expert in ECMA so I am very glad that you are looking at the test, thank you.
My understanding is that ECMA allows implicit coercion of
native int
toint
so I do not need a cast there.However, I could read it wrong and can add a cast just for safety.
from ECMA, page 38:

I.8.7.3 General assignment compatibility:
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 believe that @sandreenko is correct that this implicit conversion is allowed.