-
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
Invalid codegen with Unsafe.As on FullOpts when accessing a struct field through ulong->struct cast. #88950
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsDescriptionGiven: struct Example
{
object? Value;
ulong Inner;
struct ExampleInner { int Offset; int Length }
public int Offset
{
get
{
var inner = Inner;
return Unsafe.As<ulong, ExampleInner>(ref inner).Offset;
}
}
public int Length
{
get
{
var inner = Inner;
return Unsafe.As<ulong, ExampleInner>(ref inner).Length;
}
}
} It appears that accessing Reproduction Steps
Expected behaviorOutput:
Actual behaviorOutput:
Regression?Yes, does not reproduce on .NET 7 and .NET 6. Known WorkaroundsNone, bitcast produces worse codegen. ConfigurationReproduced on:
Other informationNo response
|
hm.. interesting, sounds like FieldSeq is messed up in FIELDADDR |
The bug seems to be in |
That should be solved with #85562. |
Description
Given:
It appears that accessing
ExampleInner
fields stored asulong
produces invalid codegen on FullOpts but not on MinOpts or withUnsafe.BitCast
: the produced assembly reads theLength
field at the offset of 8 bytes instead of 12.Reproduction Steps
Program.cs
dotnet run -c release
Expected behavior
Output:
Actual behavior
Output:
Regression?
Yes, does not reproduce on .NET 7 and .NET 6.
Known Workarounds
None, bitcast produces worse codegen.
Configuration
Reproduced on:
Other information
No response
The text was updated successfully, but these errors were encountered: