-
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
TypeLoadException when a ref struct
using explicit layout has fields of type ref struct
#111260
Comments
The offending imprecise check was introduced in dotnet/coreclr#25200 . |
@jkotas or @davidwrighton My interpretation of this scenario is that a ByRefLike value type should just be treated as any other value type. The ByRefLike nature of it doesn't impact the overlap or alignment rules. My plan here would be to remove the alignment check for the ByRefLike type and let the "value type layout" check work for the ByRefLike type "as is". Is there a flaw with that approach? CoreCLR: runtime/src/coreclr/vm/methodtablebuilder.cpp Lines 8680 to 8688 in 29013d8
native AOT: runtime/src/coreclr/tools/Common/TypeSystem/Common/MetadataFieldLayoutAlgorithm.cs Lines 333 to 340 in 29013d8
|
We need an alignment check on the actual byref fields... If we remove the check on byref like types as a whole, we need to preserve that detail for them. |
Agreed. Does |
Oh, perhaps you meant that since |
@davidwrighton It looks like we are missing some check here.
I think I see what you meant by this now. Thanks. |
Description
Context: Found in .NET 9 when experimenting with
ref struct
in P/Invoke scenarios. I want to make it clear that I'm not using "ref fields" but rather only "ref structs"; the fields of the struct are notref
(pointer) but the type is ofref struct
(stack-only).Reproduction Steps
Expected behavior
A
ref struct
of explicit layout can have fields that are positioned usingFieldOffset
attribute where the type of the field is aref struct
without creating a runtime exception.Actual behavior
When a
ref struct
is using explicit struct layout, aSystem.TypeLoadException
can occur regarding the field offset of the struct's field which the type is anotherref struct
.Regression?
No response
Known Workarounds
ref
from the nested struct.Configuration
osx-arm64
)Other information
Hypothesis: The word
ref
in the context of a struct (stack-only) is confused to be in the context of a field (pointer); the field is mistaken for an object type with rules about field alignment when it's actually a struct.The text was updated successfully, but these errors were encountered: