* Don't consider types with empty base classes blittable. They have a different managed and native size.
* Add test.
* Update src/coreclr/vm/classlayoutinfo.cpp
DEBUGARG(szName)
);
- // Type is blittable only if parent is also blittable
- isBlittable = isBlittable && (fHasNonTrivialParent ? pParentMT->IsBlittable() : TRUE);
+ // Type is blittable only if parent is also blittable and is not empty.
+ if (isBlittable && fHasNonTrivialParent)
+ {
+ isBlittable = pParentMT->IsBlittable() // Check parent
+ && (!pParentLayoutInfo || !pParentLayoutInfo->IsZeroSized()); // Ensure non-zero size
+ }
pEEClassLayoutInfoOut->SetIsBlittable(isBlittable);
S_UINT32 cbSortArraySize = S_UINT32(cTotalFields) * S_UINT32(sizeof(LayoutRawFieldInfo*));
Assert.Equal(8, Marshal.SizeOf<TestStructWithVector64>());
}
+ [Fact]
+ public void SizeOf_TypeWithEmptyBase_ReturnsExpected()
+ {
+ Assert.Equal(4, Marshal.SizeOf<DerivedClass>());
+ }
+
public static IEnumerable<object[]> SizeOf_InvalidType_TestData()
{
yield return new object[] { typeof(int).MakeByRefType(), null };
{
public System.Runtime.Intrinsics.Vector64<double> v;
}
+
+ [StructLayout(LayoutKind.Sequential)]
+ public class EmptyClass
+ {
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public class DerivedClass : EmptyClass
+ {
+ public int i;
+ }
}
}