]> granicus.if.org Git - clang/commitdiff
Fix crash initializing a bit-field with a non-constant in a place where we
authorEli Friedman <eli.friedman@gmail.com>
Sat, 17 Jul 2010 23:55:01 +0000 (23:55 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 17 Jul 2010 23:55:01 +0000 (23:55 +0000)
try to evaluate the initializer as a constant.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108632 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprConstant.cpp
test/CodeGenCXX/nonconst-init.cpp [new file with mode: 0644]

index bbd256c4f1fa97d95f123593eb681c2ea6e835eb..4831b5dabe0aaa340aaeb6ee67a4939332763bf9 100644 (file)
@@ -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/test/CodeGenCXX/nonconst-init.cpp b/test/CodeGenCXX/nonconst-init.cpp
new file mode 100644 (file)
index 0000000..21129b9
--- /dev/null
@@ -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()};