Update overlapped field test to conflict on 32-bit arches (#62308)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Fri, 3 Dec 2021 19:43:21 +0000 (14:43 -0500)
committerGitHub <noreply@github.com>
Fri, 3 Dec 2021 19:43:21 +0000 (14:43 -0500)
* Update overlapped field test to conflict on 32-bit arches

   Fixes https://github.com/dotnet/runtime/issues/62303

* [class-init] Setup fields of nested structs in layout check

   On AOT the field's class may not have been fully inited yet.

   Related to https://github.com/dotnet/runtime/issues/62311

src/mono/mono/metadata/class-init.c
src/tests/Loader/classloader/explicitlayout/NestedStructs/case04.cs

index c53f4e5..a7c333a 100644 (file)
@@ -1903,7 +1903,7 @@ validate_struct_fields_overlaps (guint8 *layout_check, int layout_size, MonoClas
                if (mono_type_is_struct (ftype)) {
                        // recursively check the layout of the embedded struct
                        MonoClass *embedded_class = mono_class_from_mono_type_internal (ftype);
-                       g_assert (m_class_is_fields_inited (embedded_class));
+                        mono_class_setup_fields (embedded_class);
 
                        const int embedded_fields_count = mono_class_get_field_count (embedded_class);
                        int *embedded_offsets = g_new0 (int, embedded_fields_count);
index 7e2cfc4..c89bea2 100644 (file)
@@ -27,7 +27,7 @@ public struct SecondLevel
 [StructLayout(LayoutKind.Explicit)]
 public struct ThirdLevel
 {
-    [FieldOffset(6)]
+    [FieldOffset(2)]
     public short ConflictingValueTypeField;
 }