From 247b657d314bf612d74e1c9eda3d3b8911f3769f Mon Sep 17 00:00:00 2001 From: Fadi Hanna Date: Mon, 6 Apr 2020 22:19:15 -0700 Subject: [PATCH] Fix IsBlittable flag bug on types. (#34613) The issue is that we are automatically assuming that types are blittable until proven otherwise while traversing the list of fields declared on the type. In the case of a type with no fields, we have to also check if the parent type is blittable, before blindly setting the flag to true (Ex: what if the base type has non-blittable fields?) --- src/coreclr/src/vm/classlayoutinfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/vm/classlayoutinfo.cpp b/src/coreclr/src/vm/classlayoutinfo.cpp index 7830295..aa7923f 100644 --- a/src/coreclr/src/vm/classlayoutinfo.cpp +++ b/src/coreclr/src/vm/classlayoutinfo.cpp @@ -611,7 +611,6 @@ VOID EEClassLayoutInfo::CollectLayoutFieldMetadataThrowing( // Set some defaults based on the parent type of this type (if one exists). _ASSERTE(!(fHasNonTrivialParent && !(pParentMT->HasLayout()))); - pEEClassLayoutInfoOut->SetIsBlittable(fHasNonTrivialParent ? pParentMT->IsBlittable() : TRUE); pEEClassLayoutInfoOut->SetIsZeroSized(FALSE); pEEClassLayoutInfoOut->SetHasExplicitSize(FALSE); pEEClassLayoutInfoOut->m_cbPackingSize = packingSize; @@ -663,6 +662,8 @@ VOID EEClassLayoutInfo::CollectLayoutFieldMetadataThrowing( DEBUGARG(szName) ); + // Type is blittable only if parent is also blittable + isBlittable = isBlittable && (fHasNonTrivialParent ? pParentMT->IsBlittable() : TRUE); pEEClassLayoutInfoOut->SetIsBlittable(isBlittable); S_UINT32 cbSortArraySize = S_UINT32(cTotalFields) * S_UINT32(sizeof(LayoutRawFieldInfo*)); -- 2.7.4