[llvm] [RemoveDIs][DebugInfo] Add DPValue checks to the verifier, prepare DPValue for parsing support (PR #79810)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 22 08:05:56 PST 2024
================
@@ -6152,6 +6175,80 @@ static DISubprogram *getSubprogram(Metadata *LocalScope) {
return nullptr;
}
+void Verifier::visit(DPValue &DPV) {
+ CheckDI(DPV.getType() == DPValue::LocationType::Value ||
+ DPV.getType() == DPValue::LocationType::Declare ||
+ DPV.getType() == DPValue::LocationType::Assign,
+ "invalid #dbg record type", &DPV, DPV.getType());
+ StringRef Kind;
+ switch (DPV.getType()) {
+ case DPValue::LocationType::Value:
+ Kind = "value";
+ break;
+ case DPValue::LocationType::Declare:
+ Kind = "declare";
+ break;
+ case DPValue::LocationType::Assign:
+ Kind = "assign";
+ break;
+ default:
+ llvm_unreachable("Tried to print a DPValue with an invalid LocationType!");
+ };
+ auto *MD = DPV.getRawLocation();
+ CheckDI(isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
+ (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
+ "invalid #dbg_" + Kind + " address/value", &DPV, MD);
+ CheckDI(isa<DILocalVariable>(DPV.getRawVariable()),
+ "invalid #dbg_" + Kind + " variable", &DPV, DPV.getRawVariable());
+ CheckDI(DPV.getExpression(), "missing #dbg_" + Kind + " expression", &DPV,
+ DPV.getExpression());
+
+ if (DPV.isDbgAssign()) {
+ CheckDI(isa<DIAssignID>(DPV.getRawAssignID()),
+ "invalid #dbg_assign DIAssignID", &DPV, DPV.getRawAssignID());
+ const auto *RawAddr = DPV.getRawAddress();
+ CheckDI(
+ isa<ValueAsMetadata>(RawAddr) ||
+ (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
+ "invalid #dbg_assign address", &DPV, DPV.getRawAddress());
+ CheckDI(DPV.getAddressExpression(),
+ "missing #dbg_assign address expression", &DPV,
+ DPV.getAddressExpression());
+ // All of the linked instructions should be in the same function as DPV.
+ for (Instruction *I : at::getAssignmentInsts(&DPV))
+ CheckDI(DPV.getFunction() == I->getFunction(),
+ "inst not in same function as #dbg_assign", I, &DPV);
+ }
+
+ if (MDNode *N = DPV.getDebugLoc().getAsMDNode()) {
+ CheckDI(isa<DILocation>(N), "invalid #dbg_" + Kind + " location", &DPV, N);
+ visitDILocation(*cast<DILocation>(N));
+ }
+
+ BasicBlock *BB = DPV.getParent();
+ Function *F = BB ? BB->getParent() : nullptr;
----------------
SLTozer wrote:
This is a duplicate of an existing check on debug intrinsics - if we were visiting any uninserted blocks that contained debug values, this would already be firing.
https://github.com/llvm/llvm-project/pull/79810
More information about the llvm-commits
mailing list