[cfe-commits] r77021 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp utils/ABITest/layout/Makefile

Anders Carlsson andersca at mac.com
Fri Jul 24 17:24:56 PDT 2009


Author: andersca
Date: Fri Jul 24 19:24:56 2009
New Revision: 77021

URL: http://llvm.org/viewvc/llvm-project?rev=77021&view=rev
Log:
More work on the constant struct builder. We now try to layout all constant structs but throw away the result.

Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/utils/ABITest/layout/Makefile

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=77021&r1=77020&r2=77021&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Jul 24 19:24:56 2009
@@ -34,6 +34,7 @@
   CodeGenFunction *CGF;
 
   bool Packed;  
+
   unsigned NextFieldOffsetInBytes;
   
   std::vector<llvm::Constant *> Elements;
@@ -131,12 +132,24 @@
       ElementNo++;
     }
     
+    uint64_t LayoutSizeInBytes = Layout.getSize() / 8;
+    
+    if (NextFieldOffsetInBytes > LayoutSizeInBytes) {
+      // If the struct is bigger than the size of the record type,
+      // we must have a flexible array member at the end.
+      assert(RD->hasFlexibleArrayMember() &&
+             "Must have flexible array member if struct is bigger than type!");
+      
+      // No tail padding is necessary.
+      return true;
+    }
+    
     // Append tail padding if necessary.
     AppendTailPadding(Layout.getSize());
-    
+      
     assert(Layout.getSize() / 8 == NextFieldOffsetInBytes && 
            "Tail padding mismatch!");
-
+    
     return true;
   }
   
@@ -156,16 +169,15 @@
                                      const InitListExpr *ILE) {
     ConstStructBuilder Builder(CGM, CGF);
     
-    // FIXME: Use this when it works well enough.
-    return 0;
-    
     if (!Builder.Build(ILE))
       return 0;
     
     llvm::Constant *Result = 
       CGM.getLLVMContext().getConstantStruct(Builder.Elements, Builder.Packed);
 
-    assert(Builder.NextFieldOffsetInBytes == Builder.getSizeInBytes(Result));
+    assert(llvm::RoundUpToAlignment(Builder.NextFieldOffsetInBytes,
+                                    Builder.getAlignment(Result)) == 
+           Builder.getSizeInBytes(Result) && "Size mismatch!");
 
     return Result;
   }
@@ -330,6 +342,7 @@
   }
 
   llvm::Constant *EmitStructInitialization(InitListExpr *ILE) {
+    // FIXME: Use the returned struct when the builder works well enough.
     ConstStructBuilder::BuildStruct(CGM, CGF, ILE);
     
     const llvm::StructType *SType =

Modified: cfe/trunk/utils/ABITest/layout/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/ABITest/layout/Makefile?rev=77021&r1=77020&r2=77021&view=diff

==============================================================================
--- cfe/trunk/utils/ABITest/layout/Makefile (original)
+++ cfe/trunk/utils/ABITest/layout/Makefile Fri Jul 24 19:24:56 2009
@@ -11,11 +11,11 @@
 
 CFLAGS := -std=gnu99
 
-X_COMPILER := llvm-gcc
+X_COMPILER := /Developer/usr/bin/llvm-gcc-4.2
 Y_COMPILER := clang
 CC := gcc
 
-ifeq (0, 0)
+ifeq (1, 0)
 X_CFLAGS := -m32
 Y_CFLAGS := -m32
 CC_CFLAGS := -m32





More information about the cfe-commits mailing list