Author: adrian Date: Mon Apr 18 18:48:16 2016 New Revision: 266698 URL: http://llvm.org/viewvc/llvm-project?rev=266698&view=rev Log: [ObjC++] Fix crash when emitting debug info for a block member capturing this.
rdar://problem/23871824 Added: cfe/trunk/test/CodeGenObjCXX/debug-info-block-capture-this.mm Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=266698&r1=266697&r2=266698&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 18 18:48:16 2016 @@ -3262,9 +3262,14 @@ void CGDebugInfo::EmitDeclareOfBlockLite // If we have a null capture, this must be the C++ 'this' capture. if (!capture) { - const CXXMethodDecl *method = - cast<CXXMethodDecl>(blockDecl->getNonClosureContext()); - QualType type = method->getThisType(C); + QualType type; + if (auto *Method = + cast_or_null<CXXMethodDecl>(blockDecl->getNonClosureContext())) + type = Method->getThisType(C); + else if (auto *RDecl = dyn_cast<CXXRecordDecl>(blockDecl->getParent())) + type = QualType(RDecl->getTypeForDecl(), 0); + else + llvm_unreachable("unexpected block declcontext"); fields.push_back(createFieldType("this", type, 0, loc, AS_public, offsetInBits, tunit, tunit)); Added: cfe/trunk/test/CodeGenObjCXX/debug-info-block-capture-this.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/debug-info-block-capture-this.mm?rev=266698&view=auto ============================================================================== --- cfe/trunk/test/CodeGenObjCXX/debug-info-block-capture-this.mm (added) +++ cfe/trunk/test/CodeGenObjCXX/debug-info-block-capture-this.mm Mon Apr 18 18:48:16 2016 @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++14 -fblocks -debug-info-kind=standalone -emit-llvm %s -o - | FileCheck %s +struct test +{ + int func() { return 1; } + int (^block)() = ^{ return func(); }; +}; + +int main(int argc, const char * argv[]) { + test t; + return t.block(); +} + +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "__block_literal_1", +// CHECK-SAME: elements: ![[ELEMS:.*]]) +// CHECK: ![[ELEMS]] = !{{{.*}}, ![[THIS:[0-9]+]]} +// CHECK: ![[THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this", +// CHECK-SAME: baseType: !"_ZTS4test", + + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits