[cfe-commits] r108632 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGenCXX/nonconst-init.cpp
Eli Friedman
eli.friedman at gmail.com
Sat Jul 17 16:55:01 PDT 2010
Author: efriedma
Date: Sat Jul 17 18:55:01 2010
New Revision: 108632
URL: http://llvm.org/viewvc/llvm-project?rev=108632&view=rev
Log:
Fix crash initializing a bit-field with a non-constant in a place where we
try to evaluate the initializer as a constant.
Added:
cfe/trunk/test/CodeGenCXX/nonconst-init.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=108632&r1=108631&r2=108632&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Jul 17 18:55:01 2010
@@ -81,10 +81,6 @@
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 @@
Field->getType(), CGF);
else
EltInit = CGM.EmitNullConstant(Field->getType());
+
+ if (!EltInit)
+ return false;
if (!Field->isBitField()) {
// Handle non-bitfield members.
Added: cfe/trunk/test/CodeGenCXX/nonconst-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/nonconst-init.cpp?rev=108632&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/nonconst-init.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/nonconst-init.cpp Sat Jul 17 18:55:01 2010
@@ -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()};
More information about the cfe-commits
mailing list