[llvm] [SandboxIR] Add debug checker to compare IR before/after a revert (PR #115968)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 12 18:08:45 PST 2024
================
@@ -1844,3 +1844,41 @@ define void @foo(i32 %arg, float %farg) {
Ctx.revert();
EXPECT_FALSE(FAdd->getFastMathFlags() != OrigFMF);
}
+
+TEST_F(TrackerTest, IRSnapshotCheckerNoChanges) {
+ parseIR(C, R"IR(
+define i32 @foo(i32 %arg) {
+ %add0 = add i32 %arg, %arg
+ ret i32 %add0
+}
+)IR");
+ Function &LLVMF = *M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+
+ [[maybe_unused]] auto *F = Ctx.createFunction(&LLVMF);
+ sandboxir::IRSnapshotChecker Checker(Ctx);
+ Checker.save();
+ Checker.expectNoDiff();
+}
+
+TEST_F(TrackerTest, IRSnapshotCheckerDiesWithUnexpectedChanges) {
+ parseIR(C, R"IR(
+define i32 @foo(i32 %arg) {
+ %add0 = add i32 %arg, %arg
+ %add1 = add i32 %add0, %arg
+ ret i32 %add1
+}
+)IR");
+ Function &LLVMF = *M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+
+ auto *F = Ctx.createFunction(&LLVMF);
+ auto *BB = &*F->begin();
+ auto It = BB->begin();
+ sandboxir::Instruction *Add0 = &*It++;
+ sandboxir::Instruction *Add1 = &*It++;
+ sandboxir::IRSnapshotChecker Checker(Ctx);
+ Checker.save();
+ Add1->setOperand(1, Add0);
+ EXPECT_DEATH(Checker.expectNoDiff(), "Found IR difference");
+}
----------------
vporpo wrote:
perhaps we should also exercise running `save()` again (or reset() + save()) after some changes are made?
https://github.com/llvm/llvm-project/pull/115968
More information about the llvm-commits
mailing list