[llvm] Add -verify-with-context option to enable better reporting of verifier errors (PR #84867)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 07:19:57 PDT 2024
================
@@ -132,9 +132,64 @@ static cl::opt<bool> VerifyNoAliasScopeDomination(
cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical "
"scopes are not dominating"));
+static cl::opt<bool> VerifyWithContext(
+ "verify-with-context", cl::Hidden, cl::init(false),
+ cl::desc("Enable a detailed context reporting for verification errors"));
+
namespace llvm {
-struct VerifierSupport {
+/// Helper type to manage the current context of a Verifier.
+struct VerifierCtxManager {
+ /// Current context.
+ SmallVector<const Value *> ContextPath;
+ /// The number of the current instruction in the current basic block.
+ size_t CurInstNumInThisBlock;
+
+ VerifierCtxManager() : CurInstNumInThisBlock(0) {}
+
+ void pushCtx(const Value *V) {
+ if (isa<Instruction>(V))
+ CurInstNumInThisBlock++;
+ else if (isa<BasicBlock>(V) || isa<Function>(V))
+ CurInstNumInThisBlock = 0;
+ ContextPath.emplace_back(V);
+ }
+ void popCtx() { ContextPath.pop_back(); }
+ void printCtx(raw_ostream &OS, bool NL = false) {
+ if (ContextPath.empty())
+ return;
+ OS << "Context [";
+ for (size_t i = 0; i < ContextPath.size(); ++i) {
+ if (i > 0) {
+ OS << " -> ";
+ }
+ auto C = ContextPath[i];
+ if (isa<Function>(C)) {
+ OS << "Function '";
----------------
arsenm wrote:
Printing "Context", "Instruction" and so on is pretty verbose
https://github.com/llvm/llvm-project/pull/84867
More information about the llvm-commits
mailing list