Repository: dotnet/runtime
File: src/coreclr/vm/classlayoutinfo.cpp (C++)

Code before:
            }
#else // TARGET_X86 && UNIX_X86_ABI
            placementInfo.m_alignment = placementInfo.m_size;
#endif
        }
        else if (corElemType == ELEMENT_TYPE_PTR || corElemType == ELEMENT_TYPE_FNPTR)
        {
            placementInfo.m_size = TARGET_POINTER_SIZE;
            placementInfo.m_alignment = TARGET_POINTER_SIZE;
        }
        else if (corElemType == ELEMENT_TYPE_VALUETYPE)
        {
            _ASSERTE(!pNestedType.IsNull());

            placementInfo.m_size = (pNestedType.GetMethodTable()->GetNumInstanceFieldBytes());

#if !defined(TARGET_64BIT) && (DATA_ALIGNMENT > 4)
            if (placementInfo.m_size >= DATA_ALIGNMENT)
            {
                placementInfo.m_alignment = DATA_ALIGNMENT;
            }
            else
#elif defined(FEATURE_64BIT_ALIGNMENT)
            if (pNestedType.RequiresAlign8())
            {
#ifdef TARGET_WASM
                placementInfo.m_alignment = max(8, pNestedType.GetMethodTable()->GetFieldAlignmentRequirement());
#else // !TARGET_WASM
                placementInfo.m_alignment = 8;
#endif // !TARGET_WASM
            }
            else
#endif // FEATURE_64BIT_ALIGNMENT
            if (pNestedType.GetMethodTable()->ContainsGCPointers())
            {
                // this field type has GC pointers in it, which need to be pointer-size aligned
                placementInfo.m_alignment = TARGET_POINTER_SIZE;
            }
            else
            {
                placementInfo.m_alignment = pNestedType.GetMethodTable()->GetFieldAlignmentRequirement();
            }
        }

        // No other type permitted for ManagedSequential.
        return placementInfo;
    }

    void InitializeLayoutFieldInfoArray(FieldDesc* pFields, ULONG cFields, MethodTable** pByValueClassCache, BYTE packingSize, LayoutRawFieldInfo* pInfoArray, UINT32* pNumInstanceFields, BYTE* pAlignmentRequirement)
    {
        ULONG cInstanceFields = 0;

Review comment (bug):
It looks like we have Arm32 bug here. It does not make sense for this ifdef to exist. Also, we may want to match !RequiresAlign8 logic that ignores `GetFieldAlignmentRequirement` for types with GC references. So maybe something like this?
```
            if (pNestedType.GetMethodTable()->ContainsGCPointers())
            {
                // this field type has GC pointers in it, which need to be pointer-size aligned
                placementInfo.m_alignment = TARGET_POINTER_SIZE;
            }
            else
            {
                placementInfo.m_alignment = pNestedType.GetMethodTable()->GetFieldAlignmentRequirement();
            }
#if defined(FEATURE_64BIT_ALIGNMENT)
            if (pNestedType.RequiresAlign8())
            {
                placementInfo.m_alignment = max(placementInfo.m_alignment, 8);
            }
#endif
```

Code after:
            }
#else // TARGET_X86 && UNIX_X86_ABI
            placementInfo.m_alignment = placementInfo.m_size;
#endif
        }
        else if (corElemType == ELEMENT_TYPE_PTR || corElemType == ELEMENT_TYPE_FNPTR)
        {
            placementInfo.m_size = TARGET_POINTER_SIZE;
            placementInfo.m_alignment = TARGET_POINTER_SIZE;
        }
        else if (corElemType == ELEMENT_TYPE_VALUETYPE)
        {
            _ASSERTE(!pNestedType.IsNull());

            placementInfo.m_size = (pNestedType.GetMethodTable()->GetNumInstanceFieldBytes());

#if !defined(TARGET_64BIT) && (DATA_ALIGNMENT > 4)
            if (placementInfo.m_size >= DATA_ALIGNMENT)
            {
                placementInfo.m_alignment = DATA_ALIGNMENT;
            }
            else
#endif // !TARGET_64BIT && (DATA_ALIGNMENT > 4)
            if (pNestedType.GetMethodTable()->ContainsGCPointers())
            {
                // this field type has GC pointers in it, which need to be pointer-size aligned
                placementInfo.m_alignment = TARGET_POINTER_SIZE;
            }
            else
            {
                placementInfo.m_alignment = pNestedType.GetMethodTable()->GetFieldAlignmentRequirement();
            }
#ifdef FEATURE_64BIT_ALIGNMENT
            if (pNestedType.RequiresAlign8())
            {
                placementInfo.m_alignment = max(8u, placementInfo.m_alignment);
            }
#endif // FEATURE_64BIT_ALIGNMENT
        }

        // No other type permitted for ManagedSequential.
        return placementInfo;
    }

    void InitializeLayoutFieldInfoArray(FieldDesc* pFields, ULONG cFields, MethodTable** pByValueClassCache, BYTE packingSize, LayoutRawFieldInfo* pInfoArray, UINT32* pNumInstanceFields, BYTE* pAlignmentRequirement)
    {
        ULONG cInstanceFields = 0;
        BYTE alignmentRequirement = 0;
        for (ULONG i = 0; i < cFields; i++)
        {
            FieldDesc* pField = &pFields[i];