[clang-tools-extra] [clang] [llvm] Report pass name when -llvm-verify-each reports breakage (PR #71447)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 1 08:42:11 PST 2023
https://github.com/chrulski-intel updated https://github.com/llvm/llvm-project/pull/71447
>From c7a15dcfed077f95470eaa57833331a24d54fd3c Mon Sep 17 00:00:00 2001
From: chrulski-intel <christopher.m.chrulski at intel.com>
Date: Mon, 6 Nov 2023 09:39:33 -0800
Subject: [PATCH 1/3] Report pass name when -llvm-verify-each reports breakage
Update the string reported to include the pass name of last pass
when running verifier after each pass.
---
llvm/lib/Passes/StandardInstrumentations.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 06cc58c0219632d..556fdbb44620d90 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -1401,7 +1401,9 @@ void VerifyInstrumentation::registerCallbacks(
dbgs() << "Verifying function " << F->getName() << "\n";
if (verifyFunction(*F, &errs()))
- report_fatal_error("Broken function found, compilation aborted!");
+ report_fatal_error(formatv("Broken function found after pass "
+ "\"{0}\", compilation aborted!",
+ P));
} else {
const Module **MPtr = llvm::any_cast<const Module *>(&IR);
const Module *M = MPtr ? *MPtr : nullptr;
@@ -1416,7 +1418,9 @@ void VerifyInstrumentation::registerCallbacks(
dbgs() << "Verifying module " << M->getName() << "\n";
if (verifyModule(*M, &errs()))
- report_fatal_error("Broken module found, compilation aborted!");
+ report_fatal_error(formatv("Broken module found after pass "
+ "\"{0}\", compilation aborted!",
+ P));
}
}
});
>From 85536510f3fea0fde04d13b2cca82e682b63d884 Mon Sep 17 00:00:00 2001
From: chrulski-intel <christopher.m.chrulski at intel.com>
Date: Tue, 28 Nov 2023 12:34:33 -0800
Subject: [PATCH 2/3] Add test for message reporting of -verify-each failure
message
Adds a testing pass that intentionally creates IR that will
trigger a verification failure to test that -verify-each
generates an appropriate error message.
---
llvm/lib/Passes/PassBuilder.cpp | 26 ++++++++++++++++++++++++++
llvm/lib/Passes/PassRegistry.def | 2 ++
llvm/test/Other/verify-each-failure.ll | 18 ++++++++++++++++++
3 files changed, 46 insertions(+)
create mode 100644 llvm/test/Other/verify-each-failure.ll
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 0d7cac19d44c3a8..c1a7d2b068004e8 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -405,6 +405,32 @@ class TriggerCrashPass : public PassInfoMixin<TriggerCrashPass> {
static StringRef name() { return "TriggerCrashPass"; }
};
+// A pass for testing message reporting of -verify-each failures.
+// DO NOT USE THIS EXCEPT FOR TESTING!
+class TriggerVerifyEachFailurePass
+ : public PassInfoMixin<TriggerVerifyEachFailurePass> {
+public:
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
+ // Intentionally break the Module by creating an alias without setting the
+ // aliasee.
+ auto *PtrTy = llvm::PointerType::getUnqual(M.getContext());
+ GlobalAlias::create(PtrTy, PtrTy->getAddressSpace(),
+ GlobalValue::LinkageTypes::InternalLinkage,
+ "__bad_alias", nullptr, &M);
+ return PreservedAnalyses::none();
+ }
+
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
+ // Intentionally break the Function by inserting a terminator
+ // instruction in the middle of a basic block.
+ BasicBlock &BB = F.getEntryBlock();
+ new UnreachableInst(F.getContext(), BB.getTerminator());
+ return PreservedAnalyses::none();
+ }
+
+ static StringRef name() { return "TriggerVerifierFailurePass"; }
+};
+
} // namespace
PassBuilder::PassBuilder(TargetMachine *TM, PipelineTuningOptions PTO,
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index eb51ccef68c827d..e6c66c3aab2c9cd 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -122,6 +122,7 @@ MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation())
MODULE_PASS("trigger-crash", TriggerCrashPass())
MODULE_PASS("verify", VerifierPass())
+MODULE_PASS("verify-each-failure", TriggerVerifyEachFailurePass())
MODULE_PASS("view-callgraph", CallGraphViewerPass())
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass())
MODULE_PASS("dfsan", DataFlowSanitizerPass())
@@ -438,6 +439,7 @@ FUNCTION_PASS("verify<memoryssa>", MemorySSAVerifierPass())
FUNCTION_PASS("verify<regions>", RegionInfoVerifierPass())
FUNCTION_PASS("verify<safepoint-ir>", SafepointIRVerifierPass())
FUNCTION_PASS("verify<scalar-evolution>", ScalarEvolutionVerifierPass())
+FUNCTION_PASS("verify-each-failure", TriggerVerifyEachFailurePass())
FUNCTION_PASS("view-cfg", CFGViewerPass())
FUNCTION_PASS("view-cfg-only", CFGOnlyViewerPass())
FUNCTION_PASS("tlshoist", TLSVariableHoistPass())
diff --git a/llvm/test/Other/verify-each-failure.ll b/llvm/test/Other/verify-each-failure.ll
new file mode 100644
index 000000000000000..ce9a21ceb9beeee
--- /dev/null
+++ b/llvm/test/Other/verify-each-failure.ll
@@ -0,0 +1,18 @@
+; A test that the option -verify-each reports the last pass run
+; when a failure occurs.
+
+; RUN: not --crash opt -disable-output -debug-pass-manager -verify-each -passes="module(verify-each-failure)" %s 2>&1 | FileCheck %s --check-prefix=CHECK_MODULE
+; RUN: not --crash opt -disable-output -debug-pass-manager -verify-each -passes="function(verify-each-failure)" %s 2>&1 | FileCheck %s --check-prefix=CHECK_FUNCTION
+
+; CHECK_MODULE: Running pass: TriggerVerifierFailurePass on [module]
+; CHECK_MODULE: Broken module found after pass "TriggerVerifierFailurePass", compilation aborted!
+
+; CHECK_FUNCTION: Running pass: TriggerVerifierFailurePass on main
+; CHECK_FUNCTION: Broken function found after pass "TriggerVerifierFailurePass", compilation aborted!
+
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4
+ store i32 0, ptr %retval, align 4
+ ret i32 0
+}
>From b6fbd48483ee2c98470f7299490ec0f196927140 Mon Sep 17 00:00:00 2001
From: chrulski-intel <christopher.m.chrulski at intel.com>
Date: Thu, 30 Nov 2023 14:19:57 -0800
Subject: [PATCH 3/3] Rename testing pass to better reflect intent of pass.
---
llvm/lib/Passes/PassBuilder.cpp | 6 +++---
llvm/lib/Passes/PassRegistry.def | 4 ++--
llvm/test/Other/trigger-verifier-error.ll | 18 ++++++++++++++++++
llvm/test/Other/verify-each-failure.ll | 18 ------------------
4 files changed, 23 insertions(+), 23 deletions(-)
create mode 100644 llvm/test/Other/trigger-verifier-error.ll
delete mode 100644 llvm/test/Other/verify-each-failure.ll
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c1a7d2b068004e8..b2fc44b438fea94 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -407,8 +407,8 @@ class TriggerCrashPass : public PassInfoMixin<TriggerCrashPass> {
// A pass for testing message reporting of -verify-each failures.
// DO NOT USE THIS EXCEPT FOR TESTING!
-class TriggerVerifyEachFailurePass
- : public PassInfoMixin<TriggerVerifyEachFailurePass> {
+class TriggerVerifierErrorPass
+ : public PassInfoMixin<TriggerVerifierErrorPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
// Intentionally break the Module by creating an alias without setting the
@@ -428,7 +428,7 @@ class TriggerVerifyEachFailurePass
return PreservedAnalyses::none();
}
- static StringRef name() { return "TriggerVerifierFailurePass"; }
+ static StringRef name() { return "TriggerVerifierErrorPass"; }
};
} // namespace
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index e6c66c3aab2c9cd..881091bfb3e7b6b 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -121,8 +121,8 @@ MODULE_PASS("strip-nondebug", StripNonDebugSymbolsPass())
MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation())
MODULE_PASS("trigger-crash", TriggerCrashPass())
+MODULE_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
MODULE_PASS("verify", VerifierPass())
-MODULE_PASS("verify-each-failure", TriggerVerifyEachFailurePass())
MODULE_PASS("view-callgraph", CallGraphViewerPass())
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass())
MODULE_PASS("dfsan", DataFlowSanitizerPass())
@@ -429,6 +429,7 @@ FUNCTION_PASS("speculative-execution", SpeculativeExecutionPass())
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
FUNCTION_PASS("structurizecfg", StructurizeCFGPass())
FUNCTION_PASS("tailcallelim", TailCallElimPass())
+FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
FUNCTION_PASS("typepromotion", TypePromotionPass(TM))
FUNCTION_PASS("unify-loop-exits", UnifyLoopExitsPass())
FUNCTION_PASS("vector-combine", VectorCombinePass())
@@ -439,7 +440,6 @@ FUNCTION_PASS("verify<memoryssa>", MemorySSAVerifierPass())
FUNCTION_PASS("verify<regions>", RegionInfoVerifierPass())
FUNCTION_PASS("verify<safepoint-ir>", SafepointIRVerifierPass())
FUNCTION_PASS("verify<scalar-evolution>", ScalarEvolutionVerifierPass())
-FUNCTION_PASS("verify-each-failure", TriggerVerifyEachFailurePass())
FUNCTION_PASS("view-cfg", CFGViewerPass())
FUNCTION_PASS("view-cfg-only", CFGOnlyViewerPass())
FUNCTION_PASS("tlshoist", TLSVariableHoistPass())
diff --git a/llvm/test/Other/trigger-verifier-error.ll b/llvm/test/Other/trigger-verifier-error.ll
new file mode 100644
index 000000000000000..692758cd0eb5048
--- /dev/null
+++ b/llvm/test/Other/trigger-verifier-error.ll
@@ -0,0 +1,18 @@
+; A test that the option -verify-each reports the last pass run
+; when a failure occurs.
+
+; RUN: not --crash opt -disable-output -debug-pass-manager -verify-each -passes="module(trigger-verifier-error)" %s 2>&1 | FileCheck %s --check-prefix=CHECK_MODULE
+; RUN: not --crash opt -disable-output -debug-pass-manager -verify-each -passes="function(trigger-verifier-error)" %s 2>&1 | FileCheck %s --check-prefix=CHECK_FUNCTION
+
+; CHECK_MODULE: Running pass: TriggerVerifierErrorPass on [module]
+; CHECK_MODULE: Broken module found after pass "TriggerVerifierErrorPass", compilation aborted!
+
+; CHECK_FUNCTION: Running pass: TriggerVerifierErrorPass on main
+; CHECK_FUNCTION: Broken function found after pass "TriggerVerifierErrorPass", compilation aborted!
+
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4
+ store i32 0, ptr %retval, align 4
+ ret i32 0
+}
diff --git a/llvm/test/Other/verify-each-failure.ll b/llvm/test/Other/verify-each-failure.ll
deleted file mode 100644
index ce9a21ceb9beeee..000000000000000
--- a/llvm/test/Other/verify-each-failure.ll
+++ /dev/null
@@ -1,18 +0,0 @@
-; A test that the option -verify-each reports the last pass run
-; when a failure occurs.
-
-; RUN: not --crash opt -disable-output -debug-pass-manager -verify-each -passes="module(verify-each-failure)" %s 2>&1 | FileCheck %s --check-prefix=CHECK_MODULE
-; RUN: not --crash opt -disable-output -debug-pass-manager -verify-each -passes="function(verify-each-failure)" %s 2>&1 | FileCheck %s --check-prefix=CHECK_FUNCTION
-
-; CHECK_MODULE: Running pass: TriggerVerifierFailurePass on [module]
-; CHECK_MODULE: Broken module found after pass "TriggerVerifierFailurePass", compilation aborted!
-
-; CHECK_FUNCTION: Running pass: TriggerVerifierFailurePass on main
-; CHECK_FUNCTION: Broken function found after pass "TriggerVerifierFailurePass", compilation aborted!
-
-define i32 @main() {
-entry:
- %retval = alloca i32, align 4
- store i32 0, ptr %retval, align 4
- ret i32 0
-}
More information about the cfe-commits
mailing list