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

Duncan Sands baldrick at free.fr
Mon Jan 25 07:46:20 PST 2010


Author: baldrick
Date: Mon Jan 25 09:46:20 2010
New Revision: 94422

URL: http://llvm.org/viewvc/llvm-project?rev=94422&view=rev
Log:
Base the decision on when to add padding on the LLVM type, not the
GCC type, since the GCC type may not have a size or may have variable
size.  This happens when compiling 2006-01-23-UnionInit.c for example.

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=94422&r1=94421&r2=94422&view=diff

==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Mon Jan 25 09:46:20 2010
@@ -7732,15 +7732,15 @@
   // type indirectly.
 
   // If we have a lower bound for the range of the type, get it.
-  tree InitType = TREE_TYPE(exp);
+  tree init_type = TREE_TYPE(exp);
   tree min_element = size_zero_node;
   std::vector<Constant*> ResultElts;
 
-  if (TREE_CODE(InitType) == VECTOR_TYPE) {
-    ResultElts.resize(TYPE_VECTOR_SUBPARTS(InitType));
+  if (TREE_CODE(init_type) == VECTOR_TYPE) {
+    ResultElts.resize(TYPE_VECTOR_SUBPARTS(init_type));
   } else {
-    assert(TREE_CODE(InitType) == ARRAY_TYPE && "Unknown type for init");
-    tree Domain = TYPE_DOMAIN(InitType);
+    assert(TREE_CODE(init_type) == ARRAY_TYPE && "Unknown type for init");
+    tree Domain = TYPE_DOMAIN(init_type);
     if (Domain && TYPE_MIN_VALUE(Domain))
       min_element = fold_convert(sizetype, TYPE_MIN_VALUE(Domain));
 
@@ -7828,7 +7828,7 @@
       AllEltsSameType = false;
   }
 
-  if (TREE_CODE(InitType) == VECTOR_TYPE) {
+  if (TREE_CODE(init_type) == VECTOR_TYPE) {
     assert(AllEltsSameType && "Vector of heterogeneous element types?");
     return ConstantVector::get(ResultElts);
   }
@@ -7838,17 +7838,19 @@
     ConstantStruct::get(Context, ResultElts, false);
 
   // If the array does not require extra padding, return it.
-  int64_t PadBits = getInt64(TYPE_SIZE(InitType), true) -
-    getTargetData().getTypeAllocSizeInBits(Res->getType());
-  assert(PadBits >= 0 && "Supersized array initializer!");
-  if (PadBits <= 0)
+  const Type *InitType = ConvertType(init_type);
+  uint64_t ExpectedBits = getTargetData().getTypeAllocSizeInBits(InitType);
+  uint64_t FoundBits = getTargetData().getTypeAllocSizeInBits(Res->getType());
+  // The initializer may be bigger than the type if init_type is variable sized
+  // or has no size (in which case the size is determined by the initial value).
+  if (ExpectedBits <= FoundBits)
     return Res;
 
   // Wrap the array in a struct with padding at the end.
   Constant *PadElts[2];
   PadElts[0] = Res;
   PadElts[1] = UndefValue::get(ArrayType::get(Type::getInt8Ty(Context),
-                                              PadBits / 8));
+                                              (ExpectedBits - FoundBits) / 8));
   return ConstantStruct::get(Context, PadElts, 2, false);
 }
 





More information about the llvm-commits mailing list