[clang] [dataflow] Parse formulas from text (PR #66424)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 15 05:55:22 PDT 2023
================
@@ -258,114 +276,71 @@ TEST(SolverTest, IffWithUnits) {
}
TEST(SolverTest, IffWithUnitsConflict) {
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto XEqY = Ctx.iff(X, Y);
- auto NotY = Ctx.neg(Y);
-
- // (X <=> Y) ^ X !Y
- EXPECT_THAT(solve({XEqY, X, NotY}), unsat());
+ Arena A;
+ auto Constraints = parseAll(A, R"(
+ (V0 = V1)
+ V0
+ !V1
+ )");
+ EXPECT_THAT(solve(Constraints), unsat());
}
TEST(SolverTest, IffTransitiveConflict) {
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto Z = Ctx.atom();
- auto XEqY = Ctx.iff(X, Y);
- auto YEqZ = Ctx.iff(Y, Z);
- auto NotX = Ctx.neg(X);
-
- // (X <=> Y) ^ (Y <=> Z) ^ Z ^ !X
- EXPECT_THAT(solve({XEqY, YEqZ, Z, NotX}), unsat());
+ Arena A;
+ auto Constraints = parseAll(A, R"(
+ (V0 = V1)
+ (V1 = V2)
+ V2
+ !V0
+ )");
+ EXPECT_THAT(solve(Constraints), unsat());
}
TEST(SolverTest, DeMorgan) {
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto Z = Ctx.atom();
- auto W = Ctx.atom();
-
- // !(X v Y) <=> !X ^ !Y
- auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
-
- // !(Z ^ W) <=> !Z v !W
- auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
-
- // A ^ B
- EXPECT_THAT(solve({A, B}), sat(_));
+ Arena A;
+ auto Constraints = parseAll(A, R"(
+ (!(V0 | V1) = (!V0 & !V1))
+ (!(V2 & V3) = (!V2 | !V3))
+ )");
+ EXPECT_THAT(solve(Constraints), sat(_));
}
TEST(SolverTest, RespectsAdditionalConstraints) {
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto XEqY = Ctx.iff(X, Y);
- auto NotY = Ctx.neg(Y);
-
- // (X <=> Y) ^ X ^ !Y
- EXPECT_THAT(solve({XEqY, X, NotY}), unsat());
+ Arena A;
+ auto Constraints = parseAll(A, R"(
+ (V0 = V1)
+ V0
+ !V1
+ )");
+ EXPECT_THAT(solve(Constraints), unsat());
}
TEST(SolverTest, ImplicationIsEquivalentToDNF) {
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto XImpliesY = Ctx.impl(X, Y);
- auto XImpliesYDNF = Ctx.disj(Ctx.neg(X), Y);
- auto NotEquivalent = Ctx.neg(Ctx.iff(XImpliesY, XImpliesYDNF));
-
- // !((X => Y) <=> (!X v Y))
- EXPECT_THAT(solve({NotEquivalent}), unsat());
+ Arena A;
+ auto Constraints = parseAll(A, R"(
+ !((V0 => V1) = (!V0 | V1))
+ )");
+ EXPECT_THAT(solve(Constraints), unsat());
}
TEST(SolverTest, ImplicationConflict) {
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto *XImplY = Ctx.impl(X, Y);
- auto *XAndNotY = Ctx.conj(X, Ctx.neg(Y));
-
- // X => Y ^ X ^ !Y
- EXPECT_THAT(solve({XImplY, XAndNotY}), unsat());
-}
-
-TEST(SolverTest, LowTimeoutResultsInTimedOut) {
- WatchedLiteralsSolver solver(10);
- ConstraintContext Ctx;
- auto X = Ctx.atom();
- auto Y = Ctx.atom();
- auto Z = Ctx.atom();
- auto W = Ctx.atom();
-
- // !(X v Y) <=> !X ^ !Y
- auto A = Ctx.iff(Ctx.neg(Ctx.disj(X, Y)), Ctx.conj(Ctx.neg(X), Ctx.neg(Y)));
-
- // !(Z ^ W) <=> !Z v !W
- auto B = Ctx.iff(Ctx.neg(Ctx.conj(Z, W)), Ctx.disj(Ctx.neg(Z), Ctx.neg(W)));
-
- // A ^ B
- EXPECT_EQ(solver.solve({A, B}).getStatus(), Solver::Result::Status::TimedOut);
+ Arena A;
+ auto Constraints = parseAll(A, R"(
+ (V0 => V1)
+ (V0 & !V1)
----------------
martinboehme wrote:
```suggestion
(V0 => V1)
V0
!V1
```
Nit: This is the way you notated this kind of thing above.
https://github.com/llvm/llvm-project/pull/66424
More information about the cfe-commits
mailing list