[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 15:56:20 PDT 2020
vsk updated this revision to Diff 281757.
vsk added a comment.
Ignore inlined entities. It's not unexpected for a function that's inlined multiple times to introduce dbg.declares for the same inlined entity.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84891/new/
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,22 @@
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. However, if a function is inlined more than
+ // once, it's not unexpected for there to be multiple dbg.declares for an
+ // inlined entity.
+ bool InlinedDef = Loc->getInlinedAt();
+ if (!InlinedDef && isa<DbgDeclareInst>(&DII)) {
+ DbgDeclareInst *&Address =
+ LocalFragment2Address[{Var, DII.getExpression()}];
+ if (!Address)
+ Address = cast<DbgDeclareInst>(&DII);
+ 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.281757.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/e4b61d5f/attachment.bin>
More information about the llvm-commits
mailing list