diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2010-07-17 23:55:01 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2010-07-17 23:55:01 +0000 |
commit | 3ee1022f377ff98db758dcc9393057e9098989af (patch) | |
tree | a0899afef582c83fcccfd8569e2134bc637de1aa /clang | |
parent | 2960987ddb8183fcf2935ffeec25b60976de38dc (diff) | |
download | bcm5719-llvm-3ee1022f377ff98db758dcc9393057e9098989af.tar.gz bcm5719-llvm-3ee1022f377ff98db758dcc9393057e9098989af.zip |
Fix crash initializing a bit-field with a non-constant in a place where we
try to evaluate the initializer as a constant.
llvm-svn: 108632
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 7 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/nonconst-init.cpp | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index bbd256c4f1f..4831b5dabe0 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -81,10 +81,6 @@ AppendField(const FieldDecl *Field, uint64_t FieldOffset, assert(NextFieldOffsetInBytes <= FieldOffsetInBytes && "Field offset mismatch!"); - // Emit the field. - if (!InitCst) - return false; - unsigned FieldAlignment = getAlignment(InitCst); // Round up the field offset to the alignment of the field type. @@ -360,6 +356,9 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) { Field->getType(), CGF); else EltInit = CGM.EmitNullConstant(Field->getType()); + + if (!EltInit) + return false; if (!Field->isBitField()) { // Handle non-bitfield members. diff --git a/clang/test/CodeGenCXX/nonconst-init.cpp b/clang/test/CodeGenCXX/nonconst-init.cpp new file mode 100644 index 00000000000..21129b9b2a6 --- /dev/null +++ b/clang/test/CodeGenCXX/nonconst-init.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s + +int a(); +// CHECK: call i32 @_Z1av() +struct x {int x, y : 10;} x = {1, a()}; |