[llvm-branch-commits] [llvm-gcc-branch] r78294 - /llvm-gcc-4.2/branches/Apple/Bender-SWB/gcc/llvm-convert.cpp

Bill Wendling isanbard at gmail.com
Thu Aug 6 02:13:52 PDT 2009


Author: void
Date: Thu Aug  6 04:13:52 2009
New Revision: 78294

URL: http://llvm.org/viewvc/llvm-project?rev=78294&view=rev
Log:
--- Merging r78288 into '.':
U    gcc/llvm-convert.cpp

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/branches/Apple/Bender-SWB/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/branches/Apple/Bender-SWB/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Bender-SWB/gcc/llvm-convert.cpp?rev=78294&r1=78293&r2=78294&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Bender-SWB/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Bender-SWB/gcc/llvm-convert.cpp Thu Aug  6 04:13:52 2009
@@ -7425,19 +7425,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(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(ValAsInt.trunc(FieldSizeInBits));
+        APInt ValAsInt = ValC->getValue();
+        ValC = ConstantInt::get(ValAsInt.trunc(FieldSizeInBits));
       }
-      LayoutInfo.AddBitFieldToRecordConstant(cast<ConstantInt>(Val),
-                                             GCCFieldOffsetInBits);
+      LayoutInfo.AddBitFieldToRecordConstant(ValC, GCCFieldOffsetInBits);
     }
   }
 





More information about the llvm-branch-commits mailing list