[PATCH] D84891: WIP: [Verifier] Flag dbg.declares which specify different addresses for the same fragment

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 29 14:49:36 PDT 2020


vsk created this revision.
vsk added reviewers: aprantl, compnerd.
Herald added subscribers: modocache, hiraditya.
Herald added a project: LLVM.
vsk requested review of this revision.

When verifying a basic block, keep track of the mapping between
!DILocalVariable fragments and addresses (typically stack slots). This
can help identify variables that are accidentally described as being in
two different stack slots.

Known check-llvm failures:

Failed Tests (3):

  LLVM :: DebugInfo/COFF/local-variables.ll
  LLVM :: Transforms/Coroutines/coro-debug-frame-variable.ll
  LLVM :: Transforms/LoopVectorize/discriminator.ll


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84891

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -263,6 +263,13 @@
   /// instruction has an operand that is an instruction in the same block.
   SmallPtrSet<Instruction *, 16> InstsInThisBlock;
 
+  /// When verifying a basic block, keep track of the mapping between
+  /// !DILocalVariable fragments and addresses (typically stack slots). This
+  /// can help identify variables that are accidentally described as being in
+  /// two different stack slots.
+  DenseMap<std::pair<DILocalVariable *, DIExpression *>, DbgDeclareInst *>
+      LocalFragment2Address;
+
   /// Keep track of the metadata nodes that have been checked already.
   SmallPtrSet<const Metadata *, 32> MDNodes;
 
@@ -2524,6 +2531,7 @@
 //
 void Verifier::visitBasicBlock(BasicBlock &BB) {
   InstsInThisBlock.clear();
+  LocalFragment2Address.clear();
 
   // Ensure that basic blocks have terminators!
   Assert(BB.getTerminator(), "Basic Block does not have terminator!", &BB);
@@ -5322,6 +5330,19 @@
   AssertDI(isType(Var->getRawType()), "invalid type ref", Var,
            Var->getRawType());
   verifyFnArgs(DII);
+
+  // A block should not have two dbg.declares which map the same variable
+  // to two different addresses.
+  if (auto *DDI = dyn_cast<DbgDeclareInst>(&DII)) {
+    DbgDeclareInst *&Address =
+        LocalFragment2Address[{Var, DII.getExpression()}];
+    if (!Address)
+      Address = DDI;
+    else
+      AssertDI(Address->getVariableLocation() == DII.getVariableLocation(),
+               "dbg.declares specify different addresses for the same fragment",
+               Address, &DII, BB, F, Var);
+  }
 }
 
 void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84891.281744.patch
Type: text/x-patch
Size: 1803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/abdcd728/attachment.bin>


More information about the llvm-commits mailing list