From: David Majnemer Date: Wed, 15 Oct 2014 16:36:11 +0000 (+0000) Subject: CodeGen: Cleanup CGRecordLowering::lowerUnion a little X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27c0ff3ab384b2a442e024f458123859c9333206;p=clang CodeGen: Cleanup CGRecordLowering::lowerUnion a little Remove some duplicated state, no functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219805 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 8084532e4c..7ad394b5ee 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -280,10 +280,6 @@ void CGRecordLowering::lowerUnion() { CharUnits LayoutSize = Layout.getSize(); llvm::Type *StorageType = nullptr; bool SeenNamedMember = false; - bool InitializingMemberIsNonZero = false; - // Compute zero-initializable status. - if (!D->field_empty() && !isZeroInitializable(*D->field_begin())) - IsZeroInitializable = IsZeroInitializableAsBase = false; // Iterate through the fields setting bitFieldInfo and the Fields array. Also // locate the "most appropriate" storage type. The heuristic for finding the // storage type isn't necessary, the first (non-0-length-bitfield) field's @@ -301,6 +297,7 @@ void CGRecordLowering::lowerUnion() { } Fields[Field->getCanonicalDecl()] = 0; llvm::Type *FieldType = getStorageType(Field); + // Compute zero-initializable status. // This union might not be zero initialized: it may contain a pointer to // data member which might have some exotic initialization sequence. // If this is the case, then we aught not to try and come up with a "better" @@ -309,17 +306,20 @@ void CGRecordLowering::lowerUnion() { if (!SeenNamedMember && Field->getDeclName()) { SeenNamedMember = true; if (!isZeroInitializable(Field)) { - InitializingMemberIsNonZero = true; + IsZeroInitializable = IsZeroInitializableAsBase = false; StorageType = FieldType; } } + // Because our union isn't zero initializable, we won't be getting a better + // storage type. + if (!IsZeroInitializable) + continue; // Conditionally update our storage type if we've got a new "better" one. if (!StorageType || getAlignment(FieldType) > getAlignment(StorageType) || (getAlignment(FieldType) == getAlignment(StorageType) && getSize(FieldType) > getSize(StorageType))) - if (!InitializingMemberIsNonZero) - StorageType = FieldType; + StorageType = FieldType; } // If we have no storage type just pad to the appropriate size and return. if (!StorageType)