From 26e80cdfe8933a7f804e1d05b379d5ad50119db5 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 7 Dec 2011 01:30:11 +0000 Subject: Make sure we correctly zero-initialize unions containing a pointer to data member as the first field. PR11487. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146009 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 5d436619d7..48eda17b7a 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -1243,13 +1243,17 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM, for (RecordDecl::field_iterator I = record->field_begin(), E = record->field_end(); I != E; ++I) { const FieldDecl *field = *I; - - // Ignore bit fields. - if (field->isBitField()) - continue; - - unsigned fieldIndex = layout.getLLVMFieldNo(field); - elements[fieldIndex] = CGM.EmitNullConstant(field->getType()); + + // Fill in non-bitfields. (Bitfields always use a zero pattern, which we + // will fill in later.) + if (!field->isBitField()) { + unsigned fieldIndex = layout.getLLVMFieldNo(field); + elements[fieldIndex] = CGM.EmitNullConstant(field->getType()); + } + + // For unions, stop after the first named field. + if (record->isUnion() && field->getDeclName()) + break; } // Fill in the virtual bases, if we're working with the complete object. -- cgit v1.2.3