From 4c682cf50f928f82e286df97d10a3d1fcf68e1a1 Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 11 Sep 2015 22:00:51 +0000 Subject: [PATCH] When comparing two block captures for layout, don't crash 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 | 2 +- test/CodeGenObjCXX/blocks.mm | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 472835feab..70006b022e 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -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; diff --git a/test/CodeGenObjCXX/blocks.mm b/test/CodeGenObjCXX/blocks.mm index 62ae428e5e..fd93437ff6 100644 --- a/test/CodeGenObjCXX/blocks.mm +++ b/test/CodeGenObjCXX/blocks.mm @@ -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); }); + } +}; -- 2.50.1