}
DI->EmitDeclareOfBlockDeclRefVariable(variable, BlockPointerDbgLoc,
- Builder, blockInfo);
+ Builder, blockInfo,
+ entry_ptr == entry->end()
+ ? nullptr : entry_ptr);
}
}
// Recover location if it was changed in the above loop.
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
const VarDecl *VD, llvm::Value *Storage, CGBuilderTy &Builder,
- const CGBlockInfo &blockInfo) {
+ const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
VD->getName(), Unit, Line, Ty);
// Insert an llvm.dbg.declare into the current block.
- llvm::Instruction *Call = DBuilder.insertDeclare(
- Storage, D, DBuilder.createExpression(addr), Builder.GetInsertPoint());
+ llvm::Instruction *Call = InsertPoint ?
+ DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr),
+ InsertPoint)
+ : DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr),
+ Builder.GetInsertBlock());
Call->setDebugLoc(
llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back()));
}
void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
llvm::Value *storage,
CGBuilderTy &Builder,
- const CGBlockInfo &blockInfo);
+ const CGBlockInfo &blockInfo,
+ llvm::Instruction *InsertPoint = 0);
/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
/// variable declaration.
--- /dev/null
+// RUN: %clang_cc1 -emit-llvm -gdwarf-2 -fblocks -o - -x objective-c %s| FileCheck %s
+// This code triggered a bug where a dbg.declare intrinsic ended up with the
+// wrong parent and subsequently failed the Verifier.
+void baz(id b);
+void fub(id block);
+int foo(void);
+void bar(void) {
+ fub(^() {
+ id a;
+ id b = [a bar:^(int e){}];
+ if (b) {
+ ^() {
+ if ((0 && foo()) ? 1 : 0) {
+ baz([a aMessage]);
+ }
+ };
+ }
+ });
+}
+
+// Verify that debug info for BlockPointerDbgLoc is emitted for the
+// innermost block.
+//
+// CHECK: define {{.*}}void @__bar_block_invoke_3(i8* %.block_descriptor)
+// CHECK: %[[BLOCKADDR:.*]] = alloca <{{.*}}>*, align 8
+// CHECK: call void @llvm.dbg.declare(metadata !{{.*}}%[[BLOCKADDR]]