r316686 - Revert "Simplify codegen and debug info generation for block context parameters."
Adrian Prantl via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 11:32:16 PDT 2017
Author: adrian
Date: Thu Oct 26 11:32:16 2017
New Revision: 316686
URL: http://llvm.org/viewvc/llvm-project?rev=316686&view=rev
Log:
Revert "Simplify codegen and debug info generation for block context parameters."
This reverts commit r316684 while investigating buildbot breakage.
Added:
cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m
Removed:
cfe/trunk/test/CodeGen/debug-info-block-vars.c
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=316686&r1=316685&r2=316686&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Oct 26 11:32:16 2017
@@ -1294,19 +1294,19 @@ void CodeGenFunction::setBlockContextPar
assert(BlockInfo && "not emitting prologue of block invocation function?!");
llvm::Value *localAddr = nullptr;
- // Allocate a stack slot like for any local variable to guarantee optimal
- // debug info at -O0. The mem2reg pass will eliminate it when optimizing.
- Address alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
- Builder.CreateStore(arg, alloc);
- localAddr = Builder.CreateLoad(alloc);
+ if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+ // Allocate a stack slot to let the debug info survive the RA.
+ Address alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
+ Builder.CreateStore(arg, alloc);
+ localAddr = Builder.CreateLoad(alloc);
+ }
if (CGDebugInfo *DI = getDebugInfo()) {
if (CGM.getCodeGenOpts().getDebugInfo() >=
codegenoptions::LimitedDebugInfo) {
DI->setLocation(D->getLocation());
- DI->EmitDeclareOfBlockLiteralArgVariable(
- *BlockInfo, D->getName(), argNum,
- cast<llvm::AllocaInst>(alloc.getPointer()), Builder);
+ DI->EmitDeclareOfBlockLiteralArgVariable(*BlockInfo, arg, argNum,
+ localAddr, Builder);
}
}
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=316686&r1=316685&r2=316686&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Oct 26 11:32:16 2017
@@ -3694,9 +3694,9 @@ bool operator<(const BlockLayoutChunk &l
}
void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
- StringRef Name,
+ llvm::Value *Arg,
unsigned ArgNo,
- llvm::AllocaInst *Alloca,
+ llvm::Value *LocalAddr,
CGBuilderTy &Builder) {
assert(DebugKind >= codegenoptions::LimitedDebugInfo);
ASTContext &C = CGM.getContext();
@@ -3828,11 +3828,19 @@ void CGDebugInfo::EmitDeclareOfBlockLite
// Create the descriptor for the parameter.
auto *debugVar = DBuilder.createParameterVariable(
- scope, Name, ArgNo, tunit, line, type,
+ scope, Arg->getName(), ArgNo, tunit, line, type,
CGM.getLangOpts().Optimize, flags);
+ if (LocalAddr) {
+ // Insert an llvm.dbg.value into the current block.
+ DBuilder.insertDbgValueIntrinsic(
+ LocalAddr, debugVar, DBuilder.createExpression(),
+ llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
+ Builder.GetInsertBlock());
+ }
+
// Insert an llvm.dbg.declare into the current block.
- DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
+ DBuilder.insertDeclare(Arg, debugVar, DBuilder.createExpression(),
llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
Builder.GetInsertBlock());
}
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=316686&r1=316685&r2=316686&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Oct 26 11:32:16 2017
@@ -398,8 +398,8 @@ public:
/// Emit call to \c llvm.dbg.declare for the block-literal argument
/// to a block invocation function.
void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
- StringRef Name, unsigned ArgNo,
- llvm::AllocaInst *LocalAddr,
+ llvm::Value *Arg, unsigned ArgNo,
+ llvm::Value *LocalAddr,
CGBuilderTy &Builder);
/// Emit information about a global variable.
Removed: cfe/trunk/test/CodeGen/debug-info-block-vars.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-block-vars.c?rev=316685&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-block-vars.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-block-vars.c (removed)
@@ -1,20 +0,0 @@
-// RUN: %clang_cc1 -x c -fblocks -debug-info-kind=standalone -emit-llvm -O0 \
-// RUN: -triple x86_64-apple-darwin -o - %s | FileCheck %s
-// RUN: %clang_cc1 -x c -fblocks -debug-info-kind=standalone -emit-llvm -O1 \
-// RUN: -triple x86_64-apple-darwin -o - %s \
-// RUN: | FileCheck --check-prefix=CHECK-OPT %s
-
-// CHECK: define internal void @__f_block_invoke(i8* %.block_descriptor)
-// CHECK: %.block_descriptor.addr = alloca i8*, align 8
-// CHECK: %block.addr = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor* }>*, align 8
-// CHECK: store i8* %.block_descriptor, i8** %.block_descriptor.addr, align 8
-// CHECK: call void @llvm.dbg.declare(metadata i8** %.block_descriptor.addr,
-// CHECK-SAME: metadata !DIExpression())
-// CHECK-OPT-NOT: alloca
-// CHECK-OPT: call void @llvm.dbg.value(metadata i8* %.block_descriptor,
-// CHECK-OPT-SAME: metadata !DIExpression())
-void f() {
- a(^{
- b();
- });
-}
Added: cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m?rev=316686&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m (added)
+++ cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m Thu Oct 26 11:32:16 2017
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s
+//
+// Test that debug location is generated for a captured "self" inside
+// a block.
+//
+// This test is split into two parts, this one for the frontend, and
+// then llvm/test/DebugInfo/debug-info-block-captured-self.ll to
+// ensure that DW_AT_location is generated for the captured self.
+ at class T;
+ at interface S
+ at end
+ at interface Mode
+-(int) count;
+ at end
+ at interface Context
+ at end
+ at interface ViewController
+ at property (nonatomic, readwrite, strong) Context *context;
+ at end
+typedef enum {
+ Unknown = 0,
+} State;
+ at interface Main : ViewController
+{
+ T * t1;
+ T * t2;
+}
+ at property(readwrite, nonatomic) State state;
+ at end
+ at implementation Main
+- (id) initWithContext:(Context *) context
+{
+ t1 = [self.context withBlock:^(id obj){
+ id *mode1;
+ t2 = [mode1 withBlock:^(id object){
+ Mode *mode2 = object;
+ if ([mode2 count] != 0) {
+ self.state = 0;
+ }
+ }];
+ }];
+}
+ at end
+// The important part of this test is that there is a dbg.value
+// intrinsic associated with the implicit .block_descriptor argument
+// of the block. We also test that this value gets alloca'd, so the
+// register llocator won't accidentally kill it.
+
+// outer block:
+// CHECK: define internal void {{.*}}_block_invoke{{.*}}
+
+// inner block:
+// CHECK: define internal void {{.*}}_block_invoke{{.*}}
+// CHECK: %[[MEM1:.*]] = alloca i8*, align 8
+// CHECK-NEXT: %[[MEM2:.*]] = alloca i8*, align 8
+// CHECK-NEXT: [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
+// CHECK: store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
+// CHECK: %[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
+// CHECK: call void @llvm.dbg.value(metadata i8* %[[TMP0]], metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
+// CHECK: call void @llvm.dbg.declare(metadata i8* [[BLOCK_DESC]], metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
+// CHECK: store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
+// CHECK: call void @llvm.dbg.declare(metadata [[BLOCK_T]]** [[DBGADDR]], metadata ![[SELF:.*]], metadata !{{.*}})
+// make sure we are still in the same function
+// CHECK: define {{.*}}__copy_helper_block_
+// Metadata
+// CHECK: ![[MAIN:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Main"
+// CHECK-SAME: line: 23,
+// CHECK: ![[PMAIN:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[MAIN]],
+// CHECK: ![[BDMD]] = !DILocalVariable(name: ".block_descriptor", arg:
+// CHECK: ![[SELF]] = !DILocalVariable(name: "self"
+// CHECK-NOT: arg:
+// CHECK-SAME: line: 40,
More information about the cfe-commits
mailing list