r247482 - When comparing two block captures for layout, don't crash

John McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 11 15:00:51 PDT 2015


Author: rjmccall
Date: Fri Sep 11 17:00:51 2015
New Revision: 247482

URL: http://llvm.org/viewvc/llvm-project?rev=247482&view=rev
Log:
When comparing two block captures for layout, don't crash
if they have the same alignment and one was 'this'.

Fixes PR24780.

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

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=247482&r1=247481&r2=247482&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Sep 11 17:00:51 2015
@@ -221,7 +221,7 @@ namespace {
       return left.Alignment > right.Alignment;
 
     auto getPrefOrder = [](const BlockLayoutChunk &chunk) {
-      if (chunk.Capture->isByRef())
+      if (chunk.Capture && chunk.Capture->isByRef())
         return 1;
       if (chunk.Lifetime == Qualifiers::OCL_Strong)
         return 0;

Modified: cfe/trunk/test/CodeGenObjCXX/blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/blocks.mm?rev=247482&r1=247481&r2=247482&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/blocks.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/blocks.mm Fri Sep 11 17:00:51 2015
@@ -8,6 +8,8 @@
 @end
 
 void f(int (^bl)(B* b));
+void takeBlock(void (^block)());
+void useValues(...);
 
 // Test1
 void g() {
@@ -59,3 +61,10 @@ void gun() {
     return foovar;
   };
 }
+
+// PR24780
+class CaptureThisAndAnotherPointer {
+  void test(void *ptr) {
+    takeBlock(^{ useValues(ptr, this); });
+  }
+};




More information about the cfe-commits mailing list