-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Bad codegen for unused ref int
local in Release builds
#53113
Comments
The problem is that the release codegen has a superfluous
|
Dereferencing null pointer is a bad idea no matter what compiler generates :)
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/unsafe-code |
I have used null pointer in the repro just to make it minimal. The situation where I have run into this issue was more complex interop code and the pointer was actually non-null. Regardless, the IL produced by the compiler in Release builds is wrong. |
@jkotas while I agree that release and debug should certainly have the same behavior, I come to the opposite conclusion as to what that behavior should be: both should be null referencing, and the debug code is missing a |
I think that Debug works correctly. When you are assigning one
This one is not assigning one |
Fixes dotnet#53113. Previously, when we did stack local optimization, we'd erase the assignment (including the context of the assignment being by-ref), leaving just the pointer indirection. This is incorrect, and resulted in us generating a ldind where we shouldn't. This fixes the bug by tracking whether we're currently optimizing a stack-scheduled assignment, and seeing through the pointer indirection in that case.
) * See through ref pointer indirection when optimizing stack locals Fixes #53113. Previously, when we did stack local optimization, we'd erase the assignment (including the context of the assignment being by-ref), leaving just the pointer indirection. This is incorrect, and resulted in us generating a ldind where we shouldn't. This fixes the bug by tracking whether a pointer indirection operator is referring to a location in initial binding, and only emitting the address when that is true.
Version Used: .NET Core 6.0.100-preview.2.21155.3
Steps to Reproduce:
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
to .csproj and replace the Program.cs in the default console app with:dotnet run
dotnet run -c Release
Expected Behavior:
Debug and Release builds have the same behavior
Actual Behavior:
Debug prints "Hello world"
Release fails with System.NullReferenceException
The text was updated successfully, but these errors were encountered: