-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Corrupted function parameter value in Release configuration (overwritten by the first argument value). #96306
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsDescriptionAfter several calls function argument gets corrupted: it's value gets overwritten by the first field of the first argument. Reproduction StepsCompile and run next code in release (the 'scale' parameter of the CreateInclineOrIdentity will swap to 0 at some point):
The project configuration:
I've attached the whole project. Expected behaviorThe console full of 42 value. Actual behaviorA span of zeroes in the console. Regression?No response Known WorkaroundsMark corrupted parameter with the 'in' keyword. ConfigurationWindows 10 (10.0.19045.3803/22H2/2022Update) Other informationThe problem could be seen in the assembly. This is the function call site: mov rcx,[rsp+30] ; 1-st argument (Point2D struct) And here is the function code being JITtered serveral times: ; JitBugReproduce.AlongAxisScaling.CreateInclineOrIdentity(JitBugReproduce.Point2D, JitBugReproduce.Point2D, JitBugReproduce.Vector2D, Single)
|
Doesn't reproduce in 7.0.14. Should be regression in 8.0. |
It looks like a bug in public static void CreateInclineOrIdentity(Point2D fixedStart, Point2D fixedEnd, Point2D scalingDirection, float scale)
{
Foo();
PrintSuspiciousArgument(scale); // just print the scale's value
+ GC.KeepAlive(new Vector2().X);
} causes the issue to reproduce in .NET 7 as well. I can take a look (when I'm back from holiday). |
Parameters that are going into float registers can come from integer registers in the presence of struct promotion. We need to home those before integer parameters or the source register could have been overridden by the integer parameter homing logic. Ideally it seems like the homing logic should be unified to handle all parameters simultaneously, but this seems like a simple enough fix. I do not think we have ABIs where we have the opposite kind constraint (integer parameters coming from float registers). Fix dotnet#96306
Parameters that are going into float registers can come from integer registers in the presence of struct promotion. We need to home those before integer parameters or the source register could have been overridden by the integer parameter homing logic. Ideally it seems like the homing logic should be unified to handle all parameters simultaneously, but this seems like a simple enough fix. I do not think we have ABIs where we have the opposite kind constraint (integer parameters coming from float registers). Fix #96306
@GeneralGDA #96439 has a fix for the problem in .NET 9. If this is blocking scenarios for you in .NET 8 and the workaround is not sufficient then I can also backport the fix to .NET 8. Please let me know if you'd like to request a backport. |
Parameters that are going into float registers can come from integer registers in the presence of struct promotion. We need to home those before integer parameters or the source register could have been overridden by the integer parameter homing logic. Ideally it seems like the homing logic should be unified to handle all parameters simultaneously, but this seems like a simple enough fix. I do not think we have ABIs where we have the opposite kind constraint (integer parameters coming from float registers). Fix #96306
…eters (#98749) * JIT: Home float parameters before integer parameters Parameters that are going into float registers can come from integer registers in the presence of struct promotion. We need to home those before integer parameters or the source register could have been overridden by the integer parameter homing logic. Ideally it seems like the homing logic should be unified to handle all parameters simultaneously, but this seems like a simple enough fix. I do not think we have ABIs where we have the opposite kind constraint (integer parameters coming from float registers). Fix #96306 * Add test * Disable float -> int reg enregistration for some rare cases --------- Co-authored-by: Jakob Botsch Nielsen <[email protected]>
Description
After several calls function argument gets corrupted: it's value gets overwritten by the first field of the first argument.
Reproduction Steps
Compile and run next code in release (the 'scale' parameter of the CreateInclineOrIdentity will swap to 0 at some point):
The project configuration:
I've attached the whole project.
Expected behavior
The console full of 42 value.
Actual behavior
A span of zeroes in the console.
Regression?
No response
Known Workarounds
Mark corrupted parameter with the 'in' keyword.
Configuration
Windows 10 (10.0.19045.3803/22H2/2022Update)
AMD Ryzen 7 5800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
Other information
The problem could be seen in the assembly. This is the function call site:
mov rcx,[rsp+30] ; 1-st argument (Point2D struct)
mov rdx,[rsp+28]; 2-nd argument (Point2D struct)
mov r8,[rsp+20]; 3-nd argument (Point2D struct)
vmovss xmm3,dword ptr [rax+4]; 4-th argument, a float
add rsp,38
jmp qword ptr [7FF8390FE910]; JitBugReproduce.AlongAxisScaling.CreateInclineOrIdentity(JitBugReproduce.Point2D, JitBugReproduce.Point2D, JitBugReproduce.Vector2D, Single)
And here is the function code being JITtered serveral times:
; JitBugReproduce.AlongAxisScaling.CreateInclineOrIdentity(JitBugReproduce.Point2D, JitBugReproduce.Point2D, JitBugReproduce.Vector2D, Single)
; var fixedLine = new Line2D(fixedStart, fixedEnd - fixedStart, FloatExtensions.DefaultEpsilon);
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
; PrintSuspiciousArgument(scale); // just print the scale's value
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
; return Identity;
; ^^^^^^^^^^^^^^^^
sub rsp,48
vzeroupper
vmovq xmm3,rcx; here the float value is overwritten by the first argument data
vmovq xmm1,rdx
vmovq xmm2,r8
vmovss dword ptr [rsp+68],xmm3
The text was updated successfully, but these errors were encountered: