]> granicus.if.org Git - clang/commitdiff
Cleanp code with some recent suggestions.
authorMike Stump <mrs@apple.com>
Sun, 22 Feb 2009 13:27:11 +0000 (13:27 +0000)
committerMike Stump <mrs@apple.com>
Sun, 22 Feb 2009 13:27:11 +0000 (13:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65285 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGen/const-init.c

index 60bf73f0b413be818bb9f46b0d543dbbc5bc3166..d368d20bcecb22dda66660be40917a6853b9522f 100644 (file)
@@ -193,13 +193,8 @@ const llvm::Type *CodeGenModule::getBlockDescriptorType() {
                                               UnsignedLongTy,
                                               NULL);
 
-  // FIXME: This breaks an unrelated testcase in the testsuite, we
-  // _want_ llvm to not use structural equality, sometimes.  What
-  // should we do, modify the testcase and do this anyway, or...
-#if 0
   getModule().addTypeName("struct.__block_descriptor",
                           BlockDescriptorType);
-#endif
 
   return BlockDescriptorType;
 }
@@ -232,7 +227,6 @@ CodeGenModule::getGenericBlockLiteralType() {
                                                   BlockDescPtrTy,
                                                   NULL);
 
-  // FIXME: See struct.__block_descriptor
   getModule().addTypeName("struct.__block_literal_generic",
                           GenericBlockLiteralType);
 
@@ -271,7 +265,6 @@ CodeGenModule::getGenericExtendedBlockLiteralType() {
                                                           Int8PtrTy,
                                                           NULL);
 
-  // FIXME: See struct.__block_descriptor
   getModule().addTypeName("struct.__block_literal_extended_generic",
                           GenericExtendedBlockLiteralType);
 
@@ -312,8 +305,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
 
   // Get the function pointer from the literal.
   llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp");
-  // FIXME: second argument should be false?
-  llvm::Value *Func = Builder.CreateLoad(FuncPtr, FuncPtr, "tmp");
+  llvm::Value *Func = Builder.CreateLoad(FuncPtr, false, "tmp");
 
   // Cast the function pointer to the right type.
   const llvm::Type *BlockFTy =
index 63aa4e0a20a520c74e9e16ade820771116964097..a271e76bf1a592e05804cd7d15a4485d784d0267 100644 (file)
@@ -616,14 +616,8 @@ Value *ScalarExprEmitter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
 
   // See if we have already allocated an offset for this variable.
   if (offset == 0) {
-    int Size = CGF.CGM.getTargetData().getTypeStoreSizeInBits(Ty) / 8;
-
-    unsigned Align = CGF.CGM.getContext().getTypeAlign(E->getDecl()->getType());
-    if (const AlignedAttr* AA = E->getDecl()->getAttr<AlignedAttr>())
-        Align = std::max(Align, AA->getAlignment());
-
     // if not, allocate one now.
-    offset = CGF.getBlockOffset(Size, Align);
+    offset = CGF.getBlockOffset(E->getDecl());
   }
 
   llvm::Value *BlockLiteral = CGF.LoadBlockStruct();
index 2de696d66470bd59dddbc2e48e94dc64164dc435..cffa7fa5ec12bdd36c4d069b0745f16938d01366 100644 (file)
@@ -286,15 +286,20 @@ public:
     assert (((Align & 7) == 0)
             && "alignment must be on at least byte boundaries");
     // Ensure proper alignment, even if it means we have to have a gap
-    if (BlockOffset % (Align >> 3)) {
-      BlockOffset += (Align >> 3) - (BlockOffset % (Align >> 3));
-      assert ((BlockOffset % (Align >> 3)) == 0
-              && "alignment calculation is wrong");
-    }
+    BlockOffset = llvm::RoundUpToAlignment(BlockOffset, Align/8);
       
     BlockOffset += Size;
     return BlockOffset-Size;
   }
+  uint64_t getBlockOffset(ValueDecl *D) {
+    uint64_t Size = getContext().getTypeSize(D->getType()) / 8;
+
+    unsigned Align = getContext().getTypeAlign(D->getType());
+    if (const AlignedAttr* AA = D->getAttr<AlignedAttr>())
+        Align = std::max(Align, AA->getAlignment());
+
+    return getBlockOffset(Size, Align);
+  }
   std::map<Decl*, uint64_t> BlockDecls;
 
   void GenerateCode(const FunctionDecl *FD,
index a709cef218af702476a749be6788736e863fea0c..0ca7c24f0bff9484e9ec2c140cba7e05420b61e7 100644 (file)
@@ -28,13 +28,13 @@ _Complex double g1x = 1.0f;
 _Complex double g1y = 1.0fi;
 // RUN: grep '@g1 = global { i8, i8 } { i8 1, i8 10 }' %t &&
 _Complex char g1 = (char) 1 + (char) 10 * 1i;
-// RUN: grep '@g2 = global { i32, i32 } { i32 1, i32 10 }' %t &&
+// RUN: grep '@g2 = global .struct.__block_descriptor { i32 1, i32 10 }' %t &&
 _Complex int g2 = 1 + 10i;
 // RUN: grep '@g3 = global { float, float } { float 1.000000e+00, float 1.000000e+01 }' %t &&
 _Complex float g3 = 1.0 + 10.0i;
 // RUN: grep '@g4 = global { double, double } { double 1.000000e+00, double 1.000000e+01 }' %t &&
 _Complex double g4 = 1.0 + 10.0i;
-// RUN: grep '@g5 = global { i32, i32 } zeroinitializer' %t &&
+// RUN: grep '@g5 = global .struct.__block_descriptor zeroinitializer' %t &&
 _Complex int g5 = (2 + 3i) == (5 + 7i);
 // RUN: grep '@g6 = global { double, double } { double -1.100000e+01, double 2.900000e+01 }' %t &&
 _Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i);