[llvm-commits] [llvm-gcc-4.2] r54427 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Bill Wendling isanbard at gmail.com
Wed Aug 6 15:17:24 PDT 2008


Author: void
Date: Wed Aug  6 17:17:23 2008
New Revision: 54427

URL: http://llvm.org/viewvc/llvm-project?rev=54427&view=rev
Log:
r50318 looks like it never made it into mainline:

Initialize padding bytes.

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=54427&r1=54426&r2=54427&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Aug  6 17:17:23 2008
@@ -6687,6 +6687,8 @@
 
 Constant *TreeConstantToLLVM::ConvertRecordCONSTRUCTOR(tree exp) {
   const StructType *STy = cast<StructType>(ConvertType(TREE_TYPE(exp)));
+
+  bool OneEltIsUnion = false;
   std::vector<Constant*> ResultElts;
   ResultElts.resize(STy->getNumElements());
 
@@ -6706,6 +6708,9 @@
       }
     }
 
+    if (TREE_CODE(TREE_TYPE(elt_value)) == UNION_TYPE)
+      OneEltIsUnion = true;
+
     // Decode the field's value.
     Constant *Val = Convert(elt_value);
    
@@ -6746,9 +6751,30 @@
   }
   
   // Fill in null elements with zeros.
+  unsigned InitSize = 0;
   for (unsigned i = 0, e = ResultElts.size(); i != e; ++i) {
     if (ResultElts[i] == 0)
       ResultElts[i] = Constant::getNullValue(STy->getElementType(i));
+
+    InitSize += getTargetData().getABITypeSize(ResultElts[i]->getType());
+  }
+
+  // If the struct has a fixed size, and if one the union value we converted
+  // isn't large enough to fill all the bits, add a zero initialized array at
+  // the end to pad it out.
+  tree StructType = TREE_TYPE(exp);
+  if (OneEltIsUnion && 
+      TYPE_SIZE(StructType) && TREE_CODE(TYPE_SIZE(StructType)) == INTEGER_CST) {
+    unsigned StructSize = ((unsigned)TREE_INT_CST_LOW(TYPE_SIZE(TREE_TYPE(exp)))+7)/8;
+    if (StructSize != InitSize) {
+      const Type *FillTy;
+      assert(StructSize > InitSize && "Init shouldn't be larger than struct!");
+      if (StructSize - InitSize == 1)
+        FillTy = Type::Int8Ty;
+      else
+        FillTy = ArrayType::get(Type::Int8Ty, StructSize - InitSize);
+      ResultElts.push_back(Constant::getNullValue(FillTy));
+    }
   }
 
   return ConstantStruct::get(ResultElts, STy->isPacked());





More information about the llvm-commits mailing list