[cfe-commits] r155662 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGen/blocks.c

John McCall rjmccall at apple.com
Thu Apr 26 14:14:42 PDT 2012


Author: rjmccall
Date: Thu Apr 26 16:14:42 2012
New Revision: 155662

URL: http://llvm.org/viewvc/llvm-project?rev=155662&view=rev
Log:
Fix a bug with block layout when the block contains something
more aligned than the block header but also contains something
smaller than the block-header alignment but not exactly half
the difference between the large alignment and the header
alignment.  Got that?

I'm really not sure what I was thinking with the buggy computation
here, but the fix is pretty obvious.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/test/CodeGen/blocks.c

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=155662&r1=155661&r2=155662&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Apr 26 16:14:42 2012
@@ -458,19 +458,22 @@
     }
   }
 
+  assert(endAlign == getLowBit(blockSize));
+
   // At this point, we just have to add padding if the end align still
   // isn't aligned right.
   if (endAlign < maxFieldAlign) {
-    CharUnits padding = maxFieldAlign - endAlign;
+    CharUnits newBlockSize = blockSize.RoundUpToAlignment(maxFieldAlign);
+    CharUnits padding = newBlockSize - blockSize;
 
     elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty,
                                                 padding.getQuantity()));
-    blockSize += padding;
-
-    endAlign = getLowBit(blockSize);
-    assert(endAlign >= maxFieldAlign);
+    blockSize = newBlockSize;
+    endAlign = maxFieldAlign;
   }
 
+  assert(endAlign == getLowBit(blockSize));
+
   // Slam everything else on now.  This works because they have
   // strictly decreasing alignment and we expect that size is always a
   // multiple of alignment.

Modified: cfe/trunk/test/CodeGen/blocks.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks.c?rev=155662&r1=155661&r2=155662&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/blocks.c (original)
+++ cfe/trunk/test/CodeGen/blocks.c Thu Apr 26 16:14:42 2012
@@ -40,3 +40,11 @@
   _Bool b = 0;
   f3_helper(^{ if (b) {} });
 }
+
+// rdar://problem/11322251
+void f4_helper(long long (^)(void));
+void f4(void) {
+  _Bool b = 0;
+  long long ll = 0;
+  f4_helper(^{ if (b) return ll; return 0LL; });
+}





More information about the cfe-commits mailing list