r222487 - Debug info for blocks: Fix a bug caught by the Verifier.
Adrian Prantl
aprantl at apple.com
Thu Nov 20 16:35:26 PST 2014
Author: adrian
Date: Thu Nov 20 18:35:25 2014
New Revision: 222487
URL: http://llvm.org/viewvc/llvm-project?rev=222487&view=rev
Log:
Debug info for blocks: Fix a bug caught by the Verifier.
When emitting nested block definitions, the insert-at-point variant of
DIBuilder::insertDeclare() could be called with the insertion point set
to the end-of-BasicBlock sentinel, causing the parent pointer of the
CallInst to be set to the intentionally bogus value of the sentinel.
Fixed by conditionally invoking the correct version of insertDeclare().
rdar://problem/19034882
Added:
cfe/trunk/test/CodeGenObjC/debug-info-nested-blocks.m
Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=222487&r1=222486&r2=222487&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Nov 20 18:35:25 2014
@@ -1243,7 +1243,9 @@ CodeGenFunction::GenerateBlockFunction(G
}
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.
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=222487&r1=222486&r2=222487&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Nov 20 18:35:25 2014
@@ -2940,7 +2940,7 @@ llvm::DIType CGDebugInfo::CreateSelfType
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!");
@@ -2998,8 +2998,11 @@ void CGDebugInfo::EmitDeclareOfBlockDecl
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()));
}
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=222487&r1=222486&r2=222487&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Nov 20 18:35:25 2014
@@ -263,7 +263,8 @@ public:
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.
Added: cfe/trunk/test/CodeGenObjC/debug-info-nested-blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/debug-info-nested-blocks.m?rev=222487&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/debug-info-nested-blocks.m (added)
+++ cfe/trunk/test/CodeGenObjC/debug-info-nested-blocks.m Thu Nov 20 18:35:25 2014
@@ -0,0 +1,26 @@
+// 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]]
More information about the cfe-commits
mailing list