Re-land r313825: "[IR] Add llvm.dbg.addr, a control-dependent version of llvm.dbg...
authorReid Kleckner <rnk@google.com>
Thu, 21 Sep 2017 19:52:03 +0000 (19:52 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 21 Sep 2017 19:52:03 +0000 (19:52 +0000)
commit0fe506bc5eff0b3b77632ff8db00165ae07830ee
tree540b10e2fd6b6ca76708216c9cdf21255da665db
parent977996d25b1f7ca0d4f4d2c863537a95287f096e
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
20 files changed:
llvm/docs/SourceLevelDebugging.rst
llvm/include/llvm/IR/IntrinsicInst.h
llvm/include/llvm/IR/Intrinsics.td
llvm/include/llvm/Transforms/Utils/Local.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
llvm/test/DebugInfo/X86/dbg-addr-dse.ll [new file with mode: 0644]
llvm/test/DebugInfo/X86/dbg-addr.ll [new file with mode: 0644]
llvm/test/DebugInfo/X86/sroasplit-5.ll
llvm/test/DebugInfo/X86/sroasplit-dbg-declare.ll [new file with mode: 0644]
llvm/test/Transforms/Mem2Reg/dbg-addr-inline-dse.ll [new file with mode: 0644]
llvm/test/Transforms/Mem2Reg/dbg-addr.ll [new file with mode: 0644]
llvm/test/Transforms/SROA/dbg-addr-diamond.ll [new file with mode: 0644]
llvm/unittests/Transforms/Utils/CMakeLists.txt
llvm/unittests/Transforms/Utils/Local.cpp