https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/70437
I'm working on a patch that will use this function from a different test. >From 34daee21bca7dbfe906e270a88e829e6beb79c97 Mon Sep 17 00:00:00 2001 From: Martin Braenne <mboe...@google.com> Date: Fri, 27 Oct 2023 09:27:12 +0000 Subject: [PATCH] [clang][dataflow][NFC] Move `parseAll()` to TestingSupport and rename `parseFormulas()` I'm working on a patch that will use this function from a different test. --- .../Analysis/FlowSensitive/SolverTest.cpp | 30 +++++-------------- .../Analysis/FlowSensitive/TestingSupport.cpp | 16 ++++++++++ .../Analysis/FlowSensitive/TestingSupport.h | 4 +++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp b/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp index a61e692088a8717..71f6da93594e30e 100644 --- a/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp @@ -25,6 +25,7 @@ using namespace clang; using namespace dataflow; using test::ConstraintContext; +using test::parseFormulas; using testing::_; using testing::AnyOf; using testing::Pair; @@ -33,21 +34,6 @@ using testing::UnorderedElementsAre; constexpr auto AssignedTrue = Solver::Result::Assignment::AssignedTrue; constexpr auto AssignedFalse = Solver::Result::Assignment::AssignedFalse; -std::vector<const Formula *> parseAll(Arena &A, StringRef Lines) { - std::vector<const Formula *> Result; - while (!Lines.empty()) { - auto [First, Rest] = Lines.split('\n'); - Lines = Rest; - if (First.trim().empty()) - continue; - if (auto F = A.parseFormula(First)) - Result.push_back(&*F); - else - ADD_FAILURE() << llvm::toString(F.takeError()); - } - return Result; -} - // Checks if the conjunction of `Vals` is satisfiable and returns the // corresponding result. Solver::Result solve(llvm::ArrayRef<const Formula *> Vals) { @@ -277,7 +263,7 @@ TEST(SolverTest, IffWithUnits) { TEST(SolverTest, IffWithUnitsConflict) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 = V1) V0 !V1 @@ -287,7 +273,7 @@ TEST(SolverTest, IffWithUnitsConflict) { TEST(SolverTest, IffTransitiveConflict) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 = V1) (V1 = V2) V2 @@ -298,7 +284,7 @@ TEST(SolverTest, IffTransitiveConflict) { TEST(SolverTest, DeMorgan) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (!(V0 | V1) = (!V0 & !V1)) (!(V2 & V3) = (!V2 | !V3)) )"); @@ -307,7 +293,7 @@ TEST(SolverTest, DeMorgan) { TEST(SolverTest, RespectsAdditionalConstraints) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 = V1) V0 !V1 @@ -317,7 +303,7 @@ TEST(SolverTest, RespectsAdditionalConstraints) { TEST(SolverTest, ImplicationIsEquivalentToDNF) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( !((V0 => V1) = (!V0 | V1)) )"); EXPECT_THAT(solve(Constraints), unsat()); @@ -325,7 +311,7 @@ TEST(SolverTest, ImplicationIsEquivalentToDNF) { TEST(SolverTest, ImplicationConflict) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 => V1) (V0 & !V1) )"); @@ -334,7 +320,7 @@ TEST(SolverTest, ImplicationConflict) { TEST(SolverTest, ReachedLimitsReflectsTimeouts) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (!(V0 | V1) = (!V0 & !V1)) (!(V2 & V3) = (!V2 & !V3)) )"); diff --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp index 65c527ae63d2d71..e24ff25cb8292fb 100644 --- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" #include "llvm/Testing/Annotations/Annotations.h" +#include "gtest/gtest.h" #include <cassert> #include <functional> #include <memory> @@ -218,3 +219,18 @@ const IndirectFieldDecl *test::findIndirectFieldDecl(ASTContext &ASTCtx, assert(Result != nullptr); return Result; } + +std::vector<const Formula *> test::parseFormulas(Arena &A, StringRef Lines) { + std::vector<const Formula *> Result; + while (!Lines.empty()) { + auto [First, Rest] = Lines.split('\n'); + Lines = Rest; + if (First.trim().empty()) + continue; + if (auto F = A.parseFormula(First)) + Result.push_back(&*F); + else + ADD_FAILURE() << llvm::toString(F.takeError()); + } + return Result; +} diff --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h index a8089d9b8c7a13f..100d78378695d3c 100644 --- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h +++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h @@ -525,6 +525,10 @@ class ConstraintContext { } }; +/// Parses a list of formulas, separated by newlines, and returns them. +/// On parse errors, calls `ADD_FAILURE()` to fail the current test. +std::vector<const Formula *> parseFormulas(Arena &A, StringRef Lines); + } // namespace test } // namespace dataflow } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits