[PATCH] D86799: [WIP] Experimental Debug Location Verifier.

Adrian Prantl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 12:50:05 PDT 2020


aprantl updated this revision to Diff 288679.
aprantl added a comment.

Ignore line 0.

Now:

  ttyStackTrace.cpp.o -c /Volumes/Data/llvm-project/llvm/lib/Support/PrettyStackTrace.cpp
  Occurence of source location from an operand does not dominate instruction.
    br label %cond.end, !dbg !2018
  !2018 = !DILocation(line: 107, column: 29, scope: !2010)
    %cond = phi i64 [ %call, %cond.true ], [ 0, %cond.false ], !dbg !2018
  fatal error: error in backend: Broken module found, compilation aborted!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86799/new/

https://reviews.llvm.org/D86799

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -269,6 +269,11 @@
   /// Keep track which DISubprogram is attached to which function.
   DenseMap<const DISubprogram *, const Function *> DISubprogramAttachments;
 
+  /// For each DILocation, store a list of the first Instruction with that !dbg
+  /// attachment in each basic block.
+  DenseMap<const DILocation *, SmallVector<const Instruction *, 1>>
+      FirstDILocationPerBlock;
+
   /// Track all DICompileUnits visited.
   SmallPtrSet<const Metadata *, 2> CUVisited;
 
@@ -468,6 +473,7 @@
   void visitLoadInst(LoadInst &LI);
   void visitStoreInst(StoreInst &SI);
   void verifyDominatesUse(Instruction &I, unsigned i);
+  void verifyDominateUseSourceLoc(Instruction &I, unsigned i);
   void visitInstruction(Instruction &I);
   void visitTerminator(Instruction &I);
   void visitBranchInst(BranchInst &BI);
@@ -2506,6 +2512,22 @@
       if (BrokenDebugInfo)
         return;
     }
+
+  // For each DILocation, store a list of the first Instruction with that !dbg
+  // attachment in each basic block.
+  FirstDILocationPerBlock.clear();
+  for (auto &BB : F) {
+    Seen.clear();
+    for (auto &I : BB) {
+      const DILocation *Loc = I.getDebugLoc().get();
+      if (!Loc)
+        continue;
+      auto it_inserted = Seen.insert(Loc);
+      if (!it_inserted.second)
+        continue;
+      FirstDILocationPerBlock[Loc].push_back(&I);
+    }
+  }
 }
 
 // verifyBasicBlock - Verify that a basic block is well formed...
@@ -4179,6 +4201,35 @@
   const Use &U = I.getOperandUse(i);
   Assert(DT.dominates(Op, U),
          "Instruction does not dominate all uses!", Op, &I);
+
+  verifyDominateUseSourceLoc(I, i);
+}
+
+void Verifier::verifyDominateUseSourceLoc(Instruction &I, unsigned i) {
+  MDNode *N = I.getDebugLoc().getAsMDNode();
+  if (!N)
+    return;
+  AssertDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N);
+  // If an instruction has a source location, then all occurrences of
+  // each operand's source location must dominate this instruction or
+  // be in the same BB as the instruction.
+  Instruction *Op = cast<Instruction>(I.getOperand(i));
+
+  MDNode *OpN = Op->getDebugLoc().getAsMDNode();
+  if (!OpN)
+    return;
+  AssertDI(isa<DILocation>(OpN), "invalid !dbg metadata attachment", &I, N);
+  DILocation *OpLoc = cast<DILocation>(N);
+  if (OpLoc->getLine() == 0)
+    return;
+  // Verify that the first occurrance of the operand's !dbg location
+  // in each basic block dominates I.
+  for (auto *FirstOccurence : FirstDILocationPerBlock[OpLoc])
+    AssertDI(FirstOccurence->getParent() == I.getParent() ||
+                 DT.dominates(FirstOccurence, &I),
+             "Occurence of source location from an operand does not dominate "
+             "instruction.",
+             FirstOccurence, OpLoc, &I);
 }
 
 void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86799.288679.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200828/78e15dd0/attachment.bin>


More information about the llvm-commits mailing list