aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/PassManagerTest.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2023-03-14 10:44:14 -0700
committerArthur Eubanks <aeubanks@google.com>2023-03-15 13:13:08 -0700
commit20a7ea49f40e2d47eb6b87acf835782dece92f08 (patch)
treeb61931fcbc6b479974c1c497d5b95510aa0c1cbb /llvm/unittests/IR/PassManagerTest.cpp
parent361cba22b2013f66e5b18896ffcf2564b332ab7b (diff)
downloadllvm-20a7ea49f40e2d47eb6b87acf835782dece92f08.zip
llvm-20a7ea49f40e2d47eb6b87acf835782dece92f08.tar.gz
llvm-20a7ea49f40e2d47eb6b87acf835782dece92f08.tar.bz2
[StandardInstrumentations] Verify function doesn't change if analyses are preserved
Reuse StructuralHash and allow it to be used in non-expensive checks builds. Move PreservedAnalysisChecker further down StandardInstrumentations so other Instrumentations (e.g. printing) have a chance to run before PreservedAnalysisChecker crashes. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D146003
Diffstat (limited to 'llvm/unittests/IR/PassManagerTest.cpp')
-rw-r--r--llvm/unittests/IR/PassManagerTest.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp
index bae5d46..4c8be37 100644
--- a/llvm/unittests/IR/PassManagerTest.cpp
+++ b/llvm/unittests/IR/PassManagerTest.cpp
@@ -950,4 +950,37 @@ TEST_F(PassManagerTest, FunctionPassCFGCheckerWrapped) {
FPM.addPass(TestSimplifyCFGWrapperPass(InnerFPM));
FPM.run(*F, FAM);
}
+
+#ifdef EXPENSIVE_CHECKS
+
+struct WrongFunctionPass : PassInfoMixin<WrongFunctionPass> {
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM) {
+ F.getEntryBlock().begin()->eraseFromParent();
+ return PreservedAnalyses::all();
+ }
+ static StringRef name() { return "WrongFunctionPass"; }
+};
+
+TEST_F(PassManagerTest, FunctionAnalysisMissedInvalidation) {
+ LLVMContext Context;
+ auto M = parseIR(Context, "define void @foo() {\n"
+ " %a = add i32 0, 0\n"
+ " ret void\n"
+ "}\n");
+
+ FunctionAnalysisManager FAM;
+ PassInstrumentationCallbacks PIC;
+ StandardInstrumentations SI(M->getContext(), /*DebugLogging*/ false);
+ SI.registerCallbacks(PIC, &FAM);
+ FAM.registerPass([&] { return PassInstrumentationAnalysis(&PIC); });
+
+ FunctionPassManager FPM;
+ FPM.addPass(WrongFunctionPass());
+
+ auto *F = M->getFunction("foo");
+ EXPECT_DEATH(FPM.run(*F, FAM), "Function @foo changed by WrongFunctionPass without invalidating analyses");
+}
+
+#endif
+
}