[llvm-commits] [llvm-gcc-4.2] r85284 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Dale Johannesen
dalej at apple.com
Tue Oct 27 13:01:54 PDT 2009
Author: johannes
Date: Tue Oct 27 15:01:53 2009
New Revision: 85284
URL: http://llvm.org/viewvc/llvm-project?rev=85284&view=rev
Log:
We already had a hack to do this:
// 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.
but the handling was limited to bitfields. It turns out this can happen
with non-bitfields as well; extend it to cover that case.
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=85284&r1=85283&r2=85284&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Oct 27 15:01:53 2009
@@ -7774,6 +7774,23 @@
uint64_t GCCFieldOffsetInBits = getFieldOffsetInBits(Field);
NextField = TREE_CHAIN(Field);
+ uint64_t FieldSizeInBits = getInt64(DECL_SIZE(Field), true);
+ uint64_t ValueSizeInBits = Val->getType()->getPrimitiveSizeInBits();
+ ConstantInt *ValC = dyn_cast<ConstantInt>(Val);
+ if (ValC && ValC->isZero()) {
+ // 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) {
+ APInt ValAsInt = ValC->getValue();
+ ValC = ConstantInt::get(Context, ValueSizeInBits < FieldSizeInBits ?
+ ValAsInt.zext(FieldSizeInBits) :
+ ValAsInt.trunc(FieldSizeInBits));
+ ValueSizeInBits = FieldSizeInBits;
+ Val = ValC;
+ }
+ }
// If this is a non-bitfield value, just slap it onto the end of the struct
// with the appropriate padding etc. If it is a bitfield, we have more
@@ -7783,20 +7800,7 @@
else {
// 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(ValC);
assert(ValueSizeInBits >= FieldSizeInBits &&
"disagreement between LLVM and GCC on bitfield size");
if (ValueSizeInBits != FieldSizeInBits) {
More information about the llvm-commits
mailing list