diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2025-06-11 13:56:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-11 13:56:30 +0100 |
commit | 3d7aa961ac96f83d2e28f107c6dfa5a6a279b364 (patch) | |
tree | e22ff48d2d4a7bbf2d09d0a0d6c6e33751ef6b3c /llvm/lib/IR/Verifier.cpp | |
parent | 2692c3aa6760f1e4ea015f906926f63ec7dce044 (diff) | |
download | llvm-3d7aa961ac96f83d2e28f107c6dfa5a6a279b364.zip llvm-3d7aa961ac96f83d2e28f107c6dfa5a6a279b364.tar.gz llvm-3d7aa961ac96f83d2e28f107c6dfa5a6a279b364.tar.bz2 |
[DebugInfo][RemoveDIs] Use autoupgrader to convert old debug-info (#143452)
By chance, two things have prevented the autoupgrade path being
exercised much so far:
* LLParser setting the debug-info mode to "old" on seeing intrinsics,
* The test in AutoUpgrade.cpp wanting to upgrade into a "new" debug-info
block.
In practice, this appears to mean this code path hasn't seen the various
invalid inputs that can come its way. This commit does a number of
things:
* Tolerates the various illegal inputs that can be written with
debug-intrinsics, and that must be tolerated until the Verifier runs,
* Printing illegal/null DbgRecord fields must succeed,
* Verifier errors need to localise the function/block where the error
is,
* Tests that now see debug records will print debug-record errors,
Plus a few new tests for other intrinsic-to-debug-record failures modes
I found. There are also two edge cases:
* Some of the unit tests switch back and forth between intrinsic and
record modes at will; I've deleted coverage and some assertions to
tolerate this as intrinsic support is now Gone (TM),
* In sroa-extract-bits.ll, the order of debug records flips. This is
because the autoupgrader upgrades in the opposite order to the basic
block conversion routines... which doesn't change the record order, but
_does_ change the use list order in Metadata! This should (TM) have no
consequence to the correctness of LLVM, but will change the order of
various records and the order of DWARF record output too.
I tried to reduce this patch to a smaller collection of changes, but
they're all intertwined, sorry.
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 592bb6a..9ec94a8 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -6714,7 +6714,7 @@ void Verifier::visit(DbgVariableRecord &DVR) { CheckDI(DVR.getType() == DbgVariableRecord::LocationType::Value || DVR.getType() == DbgVariableRecord::LocationType::Declare || DVR.getType() == DbgVariableRecord::LocationType::Assign, - "invalid #dbg record type", &DVR, DVR.getType()); + "invalid #dbg record type", &DVR, DVR.getType(), BB, F); // The location for a DbgVariableRecord must be either a ValueAsMetadata, // DIArgList, or an empty MDNode (which is a legacy representation for an @@ -6722,30 +6722,33 @@ void Verifier::visit(DbgVariableRecord &DVR) { auto *MD = DVR.getRawLocation(); CheckDI(MD && (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) || (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands())), - "invalid #dbg record address/value", &DVR, MD); + "invalid #dbg record address/value", &DVR, MD, BB, F); if (auto *VAM = dyn_cast<ValueAsMetadata>(MD)) { visitValueAsMetadata(*VAM, F); if (DVR.isDbgDeclare()) { // Allow integers here to support inttoptr salvage. Type *Ty = VAM->getValue()->getType(); CheckDI(Ty->isPointerTy() || Ty->isIntegerTy(), - "location of #dbg_declare must be a pointer or int", &DVR, MD); + "location of #dbg_declare must be a pointer or int", &DVR, MD, BB, + F); } } else if (auto *AL = dyn_cast<DIArgList>(MD)) { visitDIArgList(*AL, F); } CheckDI(isa_and_nonnull<DILocalVariable>(DVR.getRawVariable()), - "invalid #dbg record variable", &DVR, DVR.getRawVariable()); + "invalid #dbg record variable", &DVR, DVR.getRawVariable(), BB, F); visitMDNode(*DVR.getRawVariable(), AreDebugLocsAllowed::No); CheckDI(isa_and_nonnull<DIExpression>(DVR.getRawExpression()), - "invalid #dbg record expression", &DVR, DVR.getRawExpression()); + "invalid #dbg record expression", &DVR, DVR.getRawExpression(), BB, + F); visitMDNode(*DVR.getExpression(), AreDebugLocsAllowed::No); if (DVR.isDbgAssign()) { CheckDI(isa_and_nonnull<DIAssignID>(DVR.getRawAssignID()), - "invalid #dbg_assign DIAssignID", &DVR, DVR.getRawAssignID()); + "invalid #dbg_assign DIAssignID", &DVR, DVR.getRawAssignID(), BB, + F); visitMDNode(*cast<DIAssignID>(DVR.getRawAssignID()), AreDebugLocsAllowed::No); @@ -6756,29 +6759,29 @@ void Verifier::visit(DbgVariableRecord &DVR) { CheckDI( isa<ValueAsMetadata>(RawAddr) || (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()), - "invalid #dbg_assign address", &DVR, DVR.getRawAddress()); + "invalid #dbg_assign address", &DVR, DVR.getRawAddress(), BB, F); if (auto *VAM = dyn_cast<ValueAsMetadata>(RawAddr)) visitValueAsMetadata(*VAM, F); CheckDI(isa_and_nonnull<DIExpression>(DVR.getRawAddressExpression()), "invalid #dbg_assign address expression", &DVR, - DVR.getRawAddressExpression()); + DVR.getRawAddressExpression(), BB, F); visitMDNode(*DVR.getAddressExpression(), AreDebugLocsAllowed::No); // All of the linked instructions should be in the same function as DVR. for (Instruction *I : at::getAssignmentInsts(&DVR)) CheckDI(DVR.getFunction() == I->getFunction(), - "inst not in same function as #dbg_assign", I, &DVR); + "inst not in same function as #dbg_assign", I, &DVR, BB, F); } // This check is redundant with one in visitLocalVariable(). DILocalVariable *Var = DVR.getVariable(); - CheckDI(isType(Var->getRawType()), "invalid type ref", Var, - Var->getRawType()); + CheckDI(isType(Var->getRawType()), "invalid type ref", Var, Var->getRawType(), + BB, F); auto *DLNode = DVR.getDebugLoc().getAsMDNode(); CheckDI(isa_and_nonnull<DILocation>(DLNode), "invalid #dbg record DILocation", - &DVR, DLNode); + &DVR, DLNode, BB, F); DILocation *Loc = DVR.getDebugLoc(); // The scopes for variables and !dbg attachments must agree. @@ -6790,7 +6793,7 @@ void Verifier::visit(DbgVariableRecord &DVR) { CheckDI(VarSP == LocSP, "mismatched subprogram between #dbg record variable and DILocation", &DVR, BB, F, Var, Var->getScope()->getSubprogram(), Loc, - Loc->getScope()->getSubprogram()); + Loc->getScope()->getSubprogram(), BB, F); verifyFnArgs(DVR); } |