summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp16
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp16
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.h4
3 files changed, 22 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index e7743fa0c65..2915dabe541 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1294,19 +1294,19 @@ void CodeGenFunction::setBlockContextParameter(const ImplicitParamDecl *D,
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);
}
}
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3e4acd208f6..a73e4a98b3c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3694,9 +3694,9 @@ bool operator<(const BlockLayoutChunk &l, const BlockLayoutChunk &r) {
}
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::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
// 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());
}
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 4f7b7f2a0d9..36de231f05f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -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.
OpenPOWER on IntegriCloud