[llvm-commits] [dragonegg] r88665 - /dragonegg/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Fri Nov 13 10:02:40 PST 2009


Author: baldrick
Date: Fri Nov 13 12:02:39 2009
New Revision: 88665

URL: http://llvm.org/viewvc/llvm-project?rev=88665&view=rev
Log:
Port commit 85284 (johannes) from llvm-gcc:
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:
    dragonegg/trunk/llvm-convert.cpp

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=88665&r1=88664&r2=88665&view=diff

==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Fri Nov 13 12:02:39 2009
@@ -7866,6 +7866,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
@@ -7875,20 +7892,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