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

Chris Lattner sabre at nondot.org
Wed May 6 11:58:17 PDT 2009


Author: lattner
Date: Wed May  6 13:58:16 2009
New Revision: 71105

URL: http://llvm.org/viewvc/llvm-project?rev=71105&view=rev
Log:
consider a packed C struct of {int, void*} on a 64-bit target.  If we have
a designated init for the pointer, then the code will insert explicit padding
to pad up to byte 4 (where the pointer starts).  After doing that, we then
have to convert the llvm struct to a packed struct in order to get the pointer
to start at byte 4 instead of byte 8.  This changes the code to handle this 
case by recursing after inserting explicit padding.

This fixes rdar://6861719 and UnitTests/2009-04-16-BitfieldInitialization.c:t10

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=71105&r1=71104&r2=71105&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed May  6 13:58:16 2009
@@ -6834,6 +6834,7 @@
 /// struct constant, change it to make all the implicit padding between elements
 /// be fully explicit.
 void ConstantLayoutInfo::ConvertToPacked() {
+  assert(!StructIsPacked && "Struct is already packed");
   uint64_t EltOffs = 0;
   for (unsigned i = 0, e = ResultElts.size(); i != e; ++i) {
     Constant *Val = ResultElts[i];
@@ -6921,10 +6922,11 @@
   if (LLVMNaturalByteOffset*8 > GCCFieldOffsetInBits) {
     // Switch to packed.
     ConvertToPacked();
-    LLVMNaturalByteOffset = NextFieldByteStart;
-    ValLLVMAlign = 1;
-    assert(LLVMNaturalByteOffset*8 <= GCCFieldOffsetInBits &&
+    assert(NextFieldByteStart*8 <= GCCFieldOffsetInBits &&
            "Packing didn't fix the problem!");
+    
+    // Recurse to add the field after converting to packed.
+    return AddFieldToRecordConstant(Val, GCCFieldOffsetInBits);
   }
 
   // If the LLVM offset is not large enough, we need to insert explicit
@@ -6940,8 +6942,10 @@
     ResultElts.push_back(Constant::getNullValue(FillTy));
 
     NextFieldByteStart = GCCFieldOffsetInBits/8;
-    LLVMNaturalByteOffset
-      = TargetData::RoundUpAlignment(NextFieldByteStart, ValLLVMAlign);
+    
+    // Recurse to add the field.  This handles the case when the LLVM struct
+    // needs to be converted to packed after inserting tail padding.
+    return AddFieldToRecordConstant(Val, GCCFieldOffsetInBits);
   }
 
   // Slap 'Val' onto the end of our ConstantStruct, it must be known to land





More information about the llvm-commits mailing list