Re-land r313825: "[IR] Add llvm.dbg.addr, a control-dependent version of llvm.dbg.declare"
The fix is to avoid invalidating our insertion point in
replaceDbgDeclare:
Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
+ if (DII == InsertBefore)
+ InsertBefore = &*std::next(InsertBefore->getIterator());
DII->eraseFromParent();
I had to write a unit tests for this instead of a lit test because the
use list order matters in order to trigger the bug.
The reduced C test case for this was:
void useit(int*);
static inline void inlineme() {
int x[2];
useit(x);
}
void f() {
inlineme();
inlineme();
}
llvm-svn: 313905
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1a40d5c..88f5b36 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -24,6 +24,11 @@
using namespace llvm;
using namespace llvm::dwarf;
+cl::opt<bool>
+ UseDbgAddr("use-dbg-addr",
+ llvm::cl::desc("Use llvm.dbg.addr for all local variables"),
+ cl::init(false));
+
DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes)
: M(m), VMContext(M.getContext()), CUNode(nullptr),
DeclareFn(nullptr), ValueFn(nullptr),
@@ -776,6 +781,11 @@
return I;
}
+static Function *getDeclareIntrin(Module &M) {
+ return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
+ : Intrinsic::dbg_declare);
+}
+
Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
Instruction *InsertBefore) {
@@ -785,7 +795,7 @@
VarInfo->getScope()->getSubprogram() &&
"Expected matching subprograms");
if (!DeclareFn)
- DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
+ DeclareFn = getDeclareIntrin(M);
trackIfUnresolved(VarInfo);
trackIfUnresolved(Expr);
@@ -804,7 +814,7 @@
VarInfo->getScope()->getSubprogram() &&
"Expected matching subprograms");
if (!DeclareFn)
- DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
+ DeclareFn = getDeclareIntrin(M);
trackIfUnresolved(VarInfo);
trackIfUnresolved(Expr);