diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-12-07 01:30:11 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-12-07 01:30:11 +0000 |
commit | dae858aca398936b0ce9252ff3b0a6736c2e4a73 (patch) | |
tree | c8ea1dfda2ed5c6ca1ee79b126cd9541e4a52d49 /clang/lib/CodeGen/CGExprConstant.cpp | |
parent | af748e11800c50300668464c59e8d9a9b121b83a (diff) | |
download | bcm5719-llvm-dae858aca398936b0ce9252ff3b0a6736c2e4a73.tar.gz bcm5719-llvm-dae858aca398936b0ce9252ff3b0a6736c2e4a73.zip |
Make sure we correctly zero-initialize unions containing a pointer to data member as the first field. PR11487.
llvm-svn: 146009
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
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. |