From dae858aca398936b0ce9252ff3b0a6736c2e4a73 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. llvm-svn: 146009 --- clang/lib/CodeGen/CGExprConstant.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'clang/lib/CodeGen/CGExprConstant.cpp') diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 5d436619d75..48eda17b7a8 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/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