[llvm-commits] [llvm-gcc-4.2] r78288 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Chris Lattner
sabre at nondot.org
Wed Aug 5 23:14:27 PDT 2009
Author: lattner
Date: Thu Aug 6 01:14:24 2009
New Revision: 78288
URL: http://llvm.org/viewvc/llvm-project?rev=78288&view=rev
Log:
add a deplorable hack to the gcc tree to ir converter.
The G++ frontend is creating a field decl of an invalid
width to represent zero initialized stuff. Tolerate zeros
with nonsense width to get around this.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=78288&r1=78287&r2=78288&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Thu Aug 6 01:14:24 2009
@@ -7710,19 +7710,31 @@
if (!isBitfield(Field))
LayoutInfo.AddFieldToRecordConstant(Val, GCCFieldOffsetInBits);
else {
- assert(isa<ConstantInt>(Val) && "Can only init bitfield with constant");
+ // Bitfields can only be initialized with constants (integer constant
+ // expressions).
+ ConstantInt *ValC = cast<ConstantInt>(Val);
uint64_t FieldSizeInBits = getInt64(DECL_SIZE(Field), true);
uint64_t ValueSizeInBits = Val->getType()->getPrimitiveSizeInBits();
+
+ // G++ has various bugs handling {} initializers where it doesn't
+ // synthesize a zero node of the right type. Instead of figuring out G++,
+ // just hack around it by special casing zero and allowing it to be the
+ // wrong size.
+ if (ValueSizeInBits < FieldSizeInBits && ValC->isZero()) {
+ APInt ValAsInt = ValC->getValue();
+ ValC = ConstantInt::get(Context, ValAsInt.zext(FieldSizeInBits));
+ ValueSizeInBits = FieldSizeInBits;
+ }
+
assert(ValueSizeInBits >= FieldSizeInBits &&
"disagreement between LLVM and GCC on bitfield size");
if (ValueSizeInBits != FieldSizeInBits) {
// Fields are allowed to be smaller than their type. Simply discard
// the unwanted upper bits in the field value.
- APInt ValAsInt = cast<ConstantInt>(Val)->getValue();
- Val = ConstantInt::get(Context, ValAsInt.trunc(FieldSizeInBits));
+ APInt ValAsInt = ValC->getValue();
+ ValC = ConstantInt::get(Context, ValAsInt.trunc(FieldSizeInBits));
}
- LayoutInfo.AddBitFieldToRecordConstant(cast<ConstantInt>(Val),
- GCCFieldOffsetInBits);
+ LayoutInfo.AddBitFieldToRecordConstant(ValC, GCCFieldOffsetInBits);
}
}
More information about the llvm-commits
mailing list