]> granicus.if.org Git - clang/commitdiff
When comparing two block captures for layout, don't crash
authorJohn McCall <rjmccall@apple.com>
Fri, 11 Sep 2015 22:00:51 +0000 (22:00 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 11 Sep 2015 22:00:51 +0000 (22:00 +0000)
if they have the same alignment and one was 'this'.

Fixes PR24780.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247482 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
test/CodeGenObjCXX/blocks.mm

index 472835feabd525025fbf395097a5bbd8d409d5a5..70006b022ebcb045de8191b57a4cf736c989bdac 100644 (file)
@@ -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;
index 62ae428e5ec169e8f970f39784f310e30beda57d..fd93437ff65262f76d5b09b5e0e2e4a97ff381e1 100644 (file)
@@ -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); });
+  }
+};