[PATCH] D86799: [WIP] Experimental Debug Location Verifier.
Adrian Prantl via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 11:43:07 PDT 2020
aprantl created this revision.
aprantl added a reviewer: vsk.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
aprantl requested review of this revision.
This is an experimental debug location verifier that ensures the following condition: 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.
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,33 @@
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);
+ // 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.288656.patch
Type: text/x-patch
Size: 2977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200828/9a3810b2/attachment.bin>
More information about the llvm-commits
mailing list