[cfe-commits] r54610 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c
Daniel Dunbar
daniel at zuster.org
Sun Aug 10 00:00:24 PDT 2008
Author: ddunbar
Date: Sun Aug 10 02:00:24 2008
New Revision: 54610
URL: http://llvm.org/viewvc/llvm-project?rev=54610&view=rev
Log:
Fix crash during initialization of a bitfield which followed a zero
length element.
Fix some 80-col violations.
Added:
cfe/trunk/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c
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=54610&r1=54609&r2=54610&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sun Aug 10 02:00:24 2008
@@ -132,7 +132,8 @@
// Calculate information about the relevant field
const llvm::Type* Ty = CI->getType();
- unsigned size = CGM.getTypes().getTargetData().getTypeStoreSizeInBits(Ty);
+ const llvm::TargetData &TD = CGM.getTypes().getTargetData();
+ unsigned size = TD.getTypeStoreSizeInBits(Ty);
unsigned fieldOffset = CGM.getTypes().getLLVMFieldNo(Field) * size;
CodeGenTypes::BitFieldInfo bitFieldInfo =
CGM.getTypes().getBitFieldInfo(Field);
@@ -143,7 +144,12 @@
// FIXME: This won't work if the struct isn't completely packed!
unsigned offset = 0, i = 0;
while (offset < (fieldOffset & -8))
- offset += CGM.getTypes().getTargetData().getTypeStoreSizeInBits(Elts[i++]->getType());
+ offset += TD.getTypeStoreSizeInBits(Elts[i++]->getType());
+
+ // Advance over 0 sized elements (must terminate in bounds since
+ // the bitfield must have a size).
+ while (TD.getTypeStoreSizeInBits(Elts[i]->getType()) == 0)
+ ++i;
// Promote the size of V if necessary
// FIXME: This should never occur, but currently it can because
Added: cfe/trunk/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c?rev=54610&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c (added)
+++ cfe/trunk/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c Sun Aug 10 02:00:24 2008
@@ -0,0 +1,11 @@
+// RUN: clang --emit-llvm -o %t %s &&
+// RUN: grep "i8 52" %s | count 1
+
+struct et7 {
+ float lv7[0];
+ char mv7:6;
+} yv7 = {
+ {},
+ 52,
+};
+
More information about the cfe-commits
mailing list