diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-03-14 22:24:38 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-03-14 22:24:38 +0000 |
commit | 8062eb6bede3bb92e8c2e119cc0985ab336247a1 (patch) | |
tree | 4b40a67175db996484046991d25e367c5032b501 /clang/lib/CodeGen/CGExprConstant.cpp | |
parent | b344ac9afe6a2a270cceeea14926873ed58ee507 (diff) | |
download | bcm5719-llvm-8062eb6bede3bb92e8c2e119cc0985ab336247a1.tar.gz bcm5719-llvm-8062eb6bede3bb92e8c2e119cc0985ab336247a1.zip |
CodeGen: Correctly initialize bitfields with non-constant initializers
It is possible to construct an initializer for a bitfield which is not
constant. Instead of emitting code to initialize the field before the
execution of main, clang would crash.
llvm-svn: 232285
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 54f7eee6791..7406354bdc8 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -383,14 +383,19 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) { if (!EltInit) return false; - + if (!Field->isBitField()) { // Handle non-bitfield members. AppendField(*Field, Layout.getFieldOffset(FieldNo), EltInit); } else { // Otherwise we have a bitfield. - AppendBitField(*Field, Layout.getFieldOffset(FieldNo), - cast<llvm::ConstantInt>(EltInit)); + if (auto *CI = dyn_cast<llvm::ConstantInt>(EltInit)) { + AppendBitField(*Field, Layout.getFieldOffset(FieldNo), CI); + } else { + // We are trying to initialize a bitfield with a non-trivial constant, + // this must require run-time code. + return false; + } } } |