You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crossgen2 incorrectly takes Size into account for Auto layout #1770
We should update the documentation of StructLayoutAttribute to explicitly call out the cases where Size is ignored (if it is less than the actual size of the struct and apparently for LayoutKind.Auto as well).
In your example above you should name your arbitrary struct something other than GUID.
As the size of the well known Windows type "GUID" is actually 16 bytes.
I just copy pasted the name from a struct in the loader test mentioned in #1763 when I was playing with it. That struct is not a guid either but at least it's 16 bytes.
We can rename it for the regression test to Foo, in line with good naming practices.
We should update the documentation of StructLayoutAttribute to explicitly call out the cases where Size is ignored
It is never ignored (as long it is valid). It is always respected for the unmanaged layout of the type. The documentation says that StructLayoutAttribute controls the unmanaged layout of the type, and that it controls the managed layout only when the type is blittable.
Wouldn't that mean that Size is effectively ignored/invalid on StructLayout=Auto then?
Auto can't be marshalled and therefore can't have an unmanaged size, it also isn't blittable and therefore won't be impactful on the managed side either.
Activity
tannergooding commentedon Jan 15, 2020
We should update the documentation of
StructLayoutAttributeto explicitly call out the cases whereSizeis ignored (if it is less than the actual size of the struct and apparently forLayoutKind.Autoas well).briansull commentedon Jan 15, 2020
In your example above you should name your arbitrary struct something other than GUID.
As the size of the well known Windows type "GUID" is actually 16 bytes.
MichalStrehovsky commentedon Jan 15, 2020
I just copy pasted the name from a struct in the loader test mentioned in #1763 when I was playing with it. That struct is not a guid either but at least it's 16 bytes.
We can rename it for the regression test to Foo, in line with good naming practices.
jkotas commentedon Jan 16, 2020
It is never ignored (as long it is valid). It is always respected for the unmanaged layout of the type. The documentation says that
StructLayoutAttributecontrols the unmanaged layout of the type, and that it controls the managed layout only when the type is blittable.tannergooding commentedon Jan 16, 2020
Would the above case not qualify as blittable?
MichalStrehovsky commentedon Jan 16, 2020
It doesn't qualify because it doesn't have layout (only Sequential/Explicit types "have layout").
runtime/src/coreclr/src/vm/class.h
Lines 2301 to 2308 in 4f9ae42
tannergooding commentedon Jan 16, 2020
Wouldn't that mean that
Sizeis effectively ignored/invalid onStructLayout=Autothen?Auto can't be marshalled and therefore can't have an unmanaged size, it also isn't blittable and therefore won't be impactful on the managed side either.
jkotas commentedon Jan 16, 2020
Right, it is useless on StructLayout=Auto, just like all other managed/unmanaged marshaling directives.
Do not look at Size when doing Auto layout
Do not look at Size when doing Auto layout (#1805)