[clang] 9cbdef6 - [clang][dataflow] Replace usage of the deprecated overload of `checkDataflow`.
Wei Yi Tee via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 16 09:20:05 PDT 2022
Author: Wei Yi Tee
Date: 2022-09-16T16:19:07Z
New Revision: 9cbdef610339e2b762ba5fa98a4db044bba19d0d
URL: https://github.com/llvm/llvm-project/commit/9cbdef610339e2b762ba5fa98a4db044bba19d0d
DIFF: https://github.com/llvm/llvm-project/commit/9cbdef610339e2b762ba5fa98a4db044bba19d0d.diff
LOG: [clang][dataflow] Replace usage of the deprecated overload of `checkDataflow`.
Updated files:
- `ChromiumCheckModelTest.cpp`.
- `MatchSwitchTest.cpp`.
- `MultiVarConstantPropagationTest.cpp`.
- `SingleVarConstantPropagationTest.cpp`.
- `TestingSupportTest.cpp`.
- `TransferTest.cpp`.
Reviewed By: gribozavr2, sgatev
Differential Revision: https://reviews.llvm.org/D133865
Added:
Modified:
clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
index 103e424755e3c..ea171f7c1fbd9 100644
--- a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -11,10 +11,9 @@
#include "TestingSupport.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Error.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
@@ -26,10 +25,8 @@ using namespace dataflow;
using namespace test;
namespace {
-using ::testing::_;
-using ::testing::ElementsAre;
using ::testing::NotNull;
-using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
static constexpr char ChromiumCheckHeader[] = R"(
namespace std {
@@ -134,29 +131,28 @@ void runDataflow(llvm::StringRef Code, Matcher Match) {
{"check.h", ChromiumCheckHeader}, {"othercheck.h", OtherCheckHeader}};
ASSERT_THAT_ERROR(
- test::checkDataflow<ModelAdaptorAnalysis<ChromiumCheckModel>>(
- Code, "target",
- [](ASTContext &C, Environment &) {
- return ModelAdaptorAnalysis<ChromiumCheckModel>(C);
- },
- [&Match](
- llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) { Match(Results, ASTCtx); },
- {"-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"},
- FileContents),
+ checkDataflow<ModelAdaptorAnalysis<ChromiumCheckModel>>(
+ AnalysisInputs<ModelAdaptorAnalysis<ChromiumCheckModel>>(
+ Code, ast_matchers::hasName("target"),
+ [](ASTContext &C, Environment &) {
+ return ModelAdaptorAnalysis<ChromiumCheckModel>(C);
+ })
+ .withASTBuildArgs({"-fsyntax-only",
+ "-fno-delayed-template-parsing", "-std=c++17"})
+ .withASTBuildVirtualMappedFiles(std::move(FileContents)),
+ /*VerifyResults=*/
+ [&Match](const llvm::StringMap<DataflowAnalysisState<NoopLattice>>
+ &Results,
+ const AnalysisOutputs &AO) { Match(Results, AO.ASTCtx); }),
llvm::Succeeded());
}
TEST(ChromiumCheckModelTest, CheckSuccessImpliesConditionHolds) {
auto Expectations =
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -184,12 +180,10 @@ TEST(ChromiumCheckModelTest, CheckSuccessImpliesConditionHolds) {
TEST(ChromiumCheckModelTest, UnrelatedCheckIgnored) {
auto Expectations =
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
diff --git a/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp b/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
index 90cc4a19ac7fc..42bf5ddec508a 100644
--- a/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
@@ -19,12 +19,10 @@
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
#include "clang/Analysis/FlowSensitive/MapLattice.h"
#include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
-#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/ADT/StringMapEntry.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -38,7 +36,7 @@ using namespace clang;
using namespace dataflow;
namespace {
-using ::testing::Pair;
+using ::llvm::IsStringMapEntry;
using ::testing::UnorderedElementsAre;
class BooleanLattice {
@@ -119,16 +117,19 @@ class TestAnalysis : public DataflowAnalysis<TestAnalysis, BooleanLattice> {
template <typename Matcher>
void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
+ using namespace ast_matchers;
+ using namespace test;
ASSERT_THAT_ERROR(
- test::checkDataflow<TestAnalysis>(
- Code, "fun",
- [](ASTContext &C, Environment &) { return TestAnalysis(C); },
+ checkDataflow<TestAnalysis>(
+ AnalysisInputs<TestAnalysis>(
+ Code, hasName("fun"),
+ [](ASTContext &C, Environment &) { return TestAnalysis(C); })
+ .withASTBuildArgs({"-fsyntax-only", "-std=c++17"}),
+ /*VerifyResults=*/
[&Expectations](
- llvm::ArrayRef<std::pair<
- std::string, DataflowAnalysisState<TestAnalysis::Lattice>>>
- Results,
- ASTContext &) { EXPECT_THAT(Results, Expectations); },
- {"-fsyntax-only", "-std=c++17"}),
+ const llvm::StringMap<
+ DataflowAnalysisState<TestAnalysis::Lattice>> &Results,
+ const AnalysisOutputs &) { EXPECT_THAT(Results, Expectations); }),
llvm::Succeeded());
}
@@ -140,8 +141,8 @@ TEST(MatchSwitchTest, JustX) {
// [[p]]
}
)";
- RunDataflow(Code,
- UnorderedElementsAre(Pair("p", Holds(BooleanLattice(true)))));
+ RunDataflow(Code, UnorderedElementsAre(
+ IsStringMapEntry("p", Holds(BooleanLattice(true)))));
}
TEST(MatchSwitchTest, JustFoo) {
@@ -152,8 +153,8 @@ TEST(MatchSwitchTest, JustFoo) {
// [[p]]
}
)";
- RunDataflow(Code,
- UnorderedElementsAre(Pair("p", Holds(BooleanLattice(false)))));
+ RunDataflow(Code, UnorderedElementsAre(
+ IsStringMapEntry("p", Holds(BooleanLattice(false)))));
}
TEST(MatchSwitchTest, XThenFoo) {
@@ -166,8 +167,8 @@ TEST(MatchSwitchTest, XThenFoo) {
// [[p]]
}
)";
- RunDataflow(Code,
- UnorderedElementsAre(Pair("p", Holds(BooleanLattice(false)))));
+ RunDataflow(Code, UnorderedElementsAre(
+ IsStringMapEntry("p", Holds(BooleanLattice(false)))));
}
TEST(MatchSwitchTest, FooThenX) {
@@ -180,8 +181,8 @@ TEST(MatchSwitchTest, FooThenX) {
// [[p]]
}
)";
- RunDataflow(Code,
- UnorderedElementsAre(Pair("p", Holds(BooleanLattice(true)))));
+ RunDataflow(Code, UnorderedElementsAre(
+ IsStringMapEntry("p", Holds(BooleanLattice(true)))));
}
TEST(MatchSwitchTest, Neither) {
@@ -192,8 +193,8 @@ TEST(MatchSwitchTest, Neither) {
// [[p]]
}
)";
- RunDataflow(Code,
- UnorderedElementsAre(Pair("p", Holds(BooleanLattice(false)))));
+ RunDataflow(Code, UnorderedElementsAre(
+ IsStringMapEntry("p", Holds(BooleanLattice(false)))));
}
TEST(MatchSwitchTest, ReturnNonVoid) {
diff --git a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index 2615fe4ebb60b..d2e774db5a3f4 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -23,13 +23,12 @@
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
#include "clang/Analysis/FlowSensitive/MapLattice.h"
-#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
-#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/ADT/StringMapEntry.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -183,7 +182,10 @@ class ConstantPropagationAnalysis
}
};
-using ::testing::IsEmpty;
+using ::clang::dataflow::test::AnalysisInputs;
+using ::clang::dataflow::test::AnalysisOutputs;
+using ::clang::dataflow::test::checkDataflow;
+using ::llvm::IsStringMapEntry;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
@@ -209,18 +211,19 @@ MATCHER_P(HoldsCPLattice, m,
template <typename Matcher>
void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
ASSERT_THAT_ERROR(
- test::checkDataflow<ConstantPropagationAnalysis>(
- Code, "fun",
- [](ASTContext &C, Environment &) {
- return ConstantPropagationAnalysis(C);
- },
- [&Expectations](
- llvm::ArrayRef<std::pair<
- std::string,
- DataflowAnalysisState<ConstantPropagationAnalysis::Lattice>>>
- Results,
- ASTContext &) { EXPECT_THAT(Results, Expectations); },
- {"-fsyntax-only", "-std=c++17"}),
+ checkDataflow<ConstantPropagationAnalysis>(
+ AnalysisInputs<ConstantPropagationAnalysis>(
+ Code, hasName("fun"),
+ [](ASTContext &C, Environment &) {
+ return ConstantPropagationAnalysis(C);
+ })
+ .withASTBuildArgs({"-fsyntax-only", "-std=c++17"}),
+ /*VerifyResults=*/
+ [&Expectations](const llvm::StringMap<DataflowAnalysisState<
+ ConstantPropagationAnalysis::Lattice>> &Results,
+ const AnalysisOutputs &) {
+ EXPECT_THAT(Results, Expectations);
+ }),
llvm::Succeeded());
}
@@ -231,9 +234,9 @@ TEST(MultiVarConstantPropagationTest, JustInit) {
// [[p]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1)))))));
+ RunDataflow(Code, UnorderedElementsAre(IsStringMapEntry(
+ "p", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(1)))))));
}
TEST(MultiVarConstantPropagationTest, Assignment) {
@@ -245,11 +248,13 @@ TEST(MultiVarConstantPropagationTest, Assignment) {
// [[p2]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(2)))))));
+ RunDataflow(
+ Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(2)))))));
}
TEST(MultiVarConstantPropagationTest, AssignmentCall) {
@@ -261,9 +266,9 @@ TEST(MultiVarConstantPropagationTest, AssignmentCall) {
// [[p]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies()))))));
+ RunDataflow(Code, UnorderedElementsAre(IsStringMapEntry(
+ "p", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies()))))));
}
TEST(MultiVarConstantPropagationTest, AssignmentBinOp) {
@@ -274,9 +279,9 @@ TEST(MultiVarConstantPropagationTest, AssignmentBinOp) {
// [[p]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(5)))))));
+ RunDataflow(Code, UnorderedElementsAre(IsStringMapEntry(
+ "p", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(5)))))));
}
TEST(MultiVarConstantPropagationTest, PlusAssignment) {
@@ -288,11 +293,12 @@ TEST(MultiVarConstantPropagationTest, PlusAssignment) {
// [[p2]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies()))))));
+ RunDataflow(
+ Code, UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies()))))));
}
TEST(MultiVarConstantPropagationTest, SameAssignmentInBranches) {
@@ -311,16 +317,17 @@ TEST(MultiVarConstantPropagationTest, SameAssignmentInBranches) {
// [[p2]]
}
)cc";
- RunDataflow(Code,
- UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies())))),
- Pair("pT", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(2))))),
- Pair("pF", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(2))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(2)))))));
+ RunDataflow(
+ Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies())))),
+ IsStringMapEntry("pT", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(2))))),
+ IsStringMapEntry("pF", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(2))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(2)))))));
}
// Verifies that the analysis tracks multiple variables simultaneously.
@@ -335,16 +342,17 @@ TEST(MultiVarConstantPropagationTest, TwoVariables) {
// [[p3]]
}
)";
- RunDataflow(Code,
- UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(1))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(1)),
- Pair(Var("other"), HasConstantVal(2))))),
- Pair("p3", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(3)),
- Pair(Var("other"), HasConstantVal(2)))))));
+ RunDataflow(
+ Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(1)),
+ Pair(Var("other"), HasConstantVal(2))))),
+ IsStringMapEntry("p3", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(3)),
+ Pair(Var("other"), HasConstantVal(2)))))));
}
TEST(MultiVarConstantPropagationTest, TwoVariablesInBranches) {
@@ -364,19 +372,21 @@ TEST(MultiVarConstantPropagationTest, TwoVariablesInBranches) {
// [[p2]]
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies()),
- Pair(Var("other"), Varies())))),
- Pair("pT", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), HasConstantVal(2)),
- Pair(Var("other"), Varies())))),
- Pair("pF", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("other"), HasConstantVal(3)),
- Pair(Var("target"), Varies())))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies()),
- Pair(Var("other"), Varies()))))));
+ RunDataflow(
+ Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies()),
+ Pair(Var("other"), Varies())))),
+ IsStringMapEntry("pT", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(2)),
+ Pair(Var("other"), Varies())))),
+ IsStringMapEntry("pF", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("other"), HasConstantVal(3)),
+ Pair(Var("target"), Varies())))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies()),
+ Pair(Var("other"), Varies()))))));
}
TEST(MultiVarConstantPropagationTest, SameAssignmentInBranch) {
@@ -391,11 +401,13 @@ TEST(MultiVarConstantPropagationTest, SameAssignmentInBranch) {
// [[p2]]
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1)))))));
+ RunDataflow(
+ Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(1)))))));
}
TEST(MultiVarConstantPropagationTest, NewVarInBranch) {
@@ -414,15 +426,17 @@ TEST(MultiVarConstantPropagationTest, NewVarInBranch) {
}
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies())))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1))))),
- Pair("p3", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies())))),
- Pair("p4", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1)))))));
+ RunDataflow(
+ Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies())))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("p3", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies())))),
+ IsStringMapEntry("p4", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(1)))))));
}
TEST(MultiVarConstantPropagationTest, DifferentAssignmentInBranches) {
@@ -441,15 +455,16 @@ TEST(MultiVarConstantPropagationTest, DifferentAssignmentInBranches) {
// [[p2]]
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies())))),
- Pair("pT", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1))))),
- Pair("pF", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(2))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies()))))));
+ RunDataflow(
+ Code, UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies())))),
+ IsStringMapEntry("pT", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("pF", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(2))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies()))))));
}
TEST(MultiVarConstantPropagationTest, DifferentAssignmentInBranch) {
@@ -464,11 +479,12 @@ TEST(MultiVarConstantPropagationTest, DifferentAssignmentInBranch) {
// [[p2]]
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(UnorderedElementsAre(Pair(
- Var("target"), HasConstantVal(1))))),
- Pair("p2", HoldsCPLattice(UnorderedElementsAre(
- Pair(Var("target"), Varies()))))));
+ RunDataflow(
+ Code, UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(UnorderedElementsAre(Pair(
+ Var("target"), HasConstantVal(1))))),
+ IsStringMapEntry("p2", HoldsCPLattice(UnorderedElementsAre(
+ Pair(Var("target"), Varies()))))));
}
} // namespace
diff --git a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
index 664950065844d..67c86f130c977 100644
--- a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -28,6 +28,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
+#include "llvm/Testing/ADT/StringMapEntry.h"
#include "llvm/Testing/Support/Annotations.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
@@ -168,7 +169,10 @@ class ConstantPropagationAnalysis
}
};
-using ::testing::Pair;
+using ::clang::dataflow::test::AnalysisInputs;
+using ::clang::dataflow::test::AnalysisOutputs;
+using ::clang::dataflow::test::checkDataflow;
+using ::llvm::IsStringMapEntry;
using ::testing::UnorderedElementsAre;
MATCHER_P(HasConstantVal, v, "") { return arg.Data && arg.Data->Value == v; }
@@ -187,18 +191,19 @@ MATCHER_P(HoldsCPLattice, m,
template <typename Matcher>
void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
ASSERT_THAT_ERROR(
- test::checkDataflow<ConstantPropagationAnalysis>(
- Code, "fun",
- [](ASTContext &C, Environment &) {
- return ConstantPropagationAnalysis(C);
- },
- [&Expectations](
- llvm::ArrayRef<std::pair<
- std::string,
- DataflowAnalysisState<ConstantPropagationAnalysis::Lattice>>>
- Results,
- ASTContext &) { EXPECT_THAT(Results, Expectations); },
- {"-fsyntax-only", "-std=c++17"}),
+ checkDataflow<ConstantPropagationAnalysis>(
+ AnalysisInputs<ConstantPropagationAnalysis>(
+ Code, hasName("fun"),
+ [](ASTContext &C, Environment &) {
+ return ConstantPropagationAnalysis(C);
+ })
+ .withASTBuildArgs({"-fsyntax-only", "-std=c++17"}),
+ /*VerifyResults=*/
+ [&Expectations](const llvm::StringMap<DataflowAnalysisState<
+ ConstantPropagationAnalysis::Lattice>> &Results,
+ const AnalysisOutputs &) {
+ EXPECT_THAT(Results, Expectations);
+ }),
llvm::Succeeded());
}
@@ -209,8 +214,8 @@ TEST(ConstantPropagationTest, JustInit) {
// [[p]]
}
)";
- RunDataflow(
- Code, UnorderedElementsAre(Pair("p", HoldsCPLattice(HasConstantVal(1)))));
+ RunDataflow(Code, UnorderedElementsAre(IsStringMapEntry(
+ "p", HoldsCPLattice(HasConstantVal(1)))));
}
// Verifies that the analysis tracks the last variable seen.
@@ -225,10 +230,11 @@ TEST(ConstantPropagationTest, TwoVariables) {
// [[p3]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(HasConstantVal(1))),
- Pair("p2", HoldsCPLattice(HasConstantVal(2))),
- Pair("p3", HoldsCPLattice(HasConstantVal(3)))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("p2", HoldsCPLattice(HasConstantVal(2))),
+ IsStringMapEntry("p3", HoldsCPLattice(HasConstantVal(3)))));
}
TEST(ConstantPropagationTest, Assignment) {
@@ -240,9 +246,10 @@ TEST(ConstantPropagationTest, Assignment) {
// [[p2]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(HasConstantVal(1))),
- Pair("p2", HoldsCPLattice(HasConstantVal(2)))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("p2", HoldsCPLattice(HasConstantVal(2)))));
}
TEST(ConstantPropagationTest, AssignmentCall) {
@@ -254,7 +261,8 @@ TEST(ConstantPropagationTest, AssignmentCall) {
// [[p]]
}
)";
- RunDataflow(Code, UnorderedElementsAre(Pair("p", HoldsCPLattice(Varies()))));
+ RunDataflow(Code, UnorderedElementsAre(
+ IsStringMapEntry("p", HoldsCPLattice(Varies()))));
}
TEST(ConstantPropagationTest, AssignmentBinOp) {
@@ -265,8 +273,8 @@ TEST(ConstantPropagationTest, AssignmentBinOp) {
// [[p]]
}
)";
- RunDataflow(
- Code, UnorderedElementsAre(Pair("p", HoldsCPLattice(HasConstantVal(5)))));
+ RunDataflow(Code, UnorderedElementsAre(IsStringMapEntry(
+ "p", HoldsCPLattice(HasConstantVal(5)))));
}
TEST(ConstantPropagationTest, PlusAssignment) {
@@ -278,9 +286,10 @@ TEST(ConstantPropagationTest, PlusAssignment) {
// [[p2]]
}
)";
- RunDataflow(
- Code, UnorderedElementsAre(Pair("p1", HoldsCPLattice(HasConstantVal(1))),
- Pair("p2", HoldsCPLattice(Varies()))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("p2", HoldsCPLattice(Varies()))));
}
TEST(ConstantPropagationTest, SameAssignmentInBranches) {
@@ -299,11 +308,12 @@ TEST(ConstantPropagationTest, SameAssignmentInBranches) {
// [[p2]]
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(IsUnknown())),
- Pair("pT", HoldsCPLattice(HasConstantVal(2))),
- Pair("pF", HoldsCPLattice(HasConstantVal(2))),
- Pair("p2", HoldsCPLattice(HasConstantVal(2)))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(IsUnknown())),
+ IsStringMapEntry("pT", HoldsCPLattice(HasConstantVal(2))),
+ IsStringMapEntry("pF", HoldsCPLattice(HasConstantVal(2))),
+ IsStringMapEntry("p2", HoldsCPLattice(HasConstantVal(2)))));
}
TEST(ConstantPropagationTest, SameAssignmentInBranch) {
@@ -318,9 +328,10 @@ TEST(ConstantPropagationTest, SameAssignmentInBranch) {
// [[p2]]
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(HasConstantVal(1))),
- Pair("p2", HoldsCPLattice(HasConstantVal(1)))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("p2", HoldsCPLattice(HasConstantVal(1)))));
}
TEST(ConstantPropagationTest, NewVarInBranch) {
@@ -339,11 +350,12 @@ TEST(ConstantPropagationTest, NewVarInBranch) {
}
}
)cc";
- RunDataflow(Code, UnorderedElementsAre(
- Pair("p1", HoldsCPLattice(IsUnknown())),
- Pair("p2", HoldsCPLattice(HasConstantVal(1))),
- Pair("p3", HoldsCPLattice(IsUnknown())),
- Pair("p4", HoldsCPLattice(HasConstantVal(1)))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(IsUnknown())),
+ IsStringMapEntry("p2", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("p3", HoldsCPLattice(IsUnknown())),
+ IsStringMapEntry("p4", HoldsCPLattice(HasConstantVal(1)))));
}
TEST(ConstantPropagationTest, DifferentAssignmentInBranches) {
@@ -362,11 +374,12 @@ TEST(ConstantPropagationTest, DifferentAssignmentInBranches) {
// [[p2]]
}
)cc";
- RunDataflow(
- Code, UnorderedElementsAre(Pair("p1", HoldsCPLattice(IsUnknown())),
- Pair("pT", HoldsCPLattice(HasConstantVal(1))),
- Pair("pF", HoldsCPLattice(HasConstantVal(2))),
- Pair("p2", HoldsCPLattice(Varies()))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(IsUnknown())),
+ IsStringMapEntry("pT", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("pF", HoldsCPLattice(HasConstantVal(2))),
+ IsStringMapEntry("p2", HoldsCPLattice(Varies()))));
}
TEST(ConstantPropagationTest, DifferentAssignmentInBranch) {
@@ -381,9 +394,10 @@ TEST(ConstantPropagationTest, DifferentAssignmentInBranch) {
// [[p2]]
}
)cc";
- RunDataflow(
- Code, UnorderedElementsAre(Pair("p1", HoldsCPLattice(HasConstantVal(1))),
- Pair("p2", HoldsCPLattice(Varies()))));
+ RunDataflow(Code,
+ UnorderedElementsAre(
+ IsStringMapEntry("p1", HoldsCPLattice(HasConstantVal(1))),
+ IsStringMapEntry("p2", HoldsCPLattice(Varies()))));
}
} // namespace
diff --git a/clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp b/clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
index 4d10a246ab8c0..c00e376d30a7c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
@@ -4,6 +4,7 @@
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/Testing/ADT/StringMapEntry.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -16,9 +17,12 @@ namespace {
using ::clang::ast_matchers::functionDecl;
using ::clang::ast_matchers::hasName;
using ::clang::ast_matchers::isDefinition;
+using ::clang::dataflow::test::AnalysisInputs;
+using ::clang::dataflow::test::AnalysisOutputs;
+using ::clang::dataflow::test::checkDataflow;
+using ::llvm::IsStringMapEntry;
using ::testing::_;
using ::testing::IsEmpty;
-using ::testing::Pair;
using ::testing::UnorderedElementsAre;
template <typename T>
@@ -71,25 +75,27 @@ TEST(BuildStatementToAnnotationMappingTest, ReturnStmt) {
void checkDataflow(
llvm::StringRef Code, llvm::StringRef Target,
- std::function<void(llvm::ArrayRef<std::pair<
- std::string, DataflowAnalysisState<NoopLattice>>>,
- ASTContext &)>
+ std::function<
+ void(const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
+ const AnalysisOutputs &)>
Expectations) {
- ASSERT_THAT_ERROR(
- test::checkDataflow<NoopAnalysis>(
- Code, Target,
- [](ASTContext &Context, Environment &) {
- return NoopAnalysis(Context, /*ApplyBuiltinTransfer=*/false);
- },
- std::move(Expectations), {"-fsyntax-only", "-std=c++17"}),
- llvm::Succeeded());
+ ASSERT_THAT_ERROR(checkDataflow<NoopAnalysis>(
+ AnalysisInputs<NoopAnalysis>(
+ Code, hasName(Target),
+ [](ASTContext &Context, Environment &) {
+ return NoopAnalysis(
+ Context, /*ApplyBuiltinTransfer=*/false);
+ })
+ .withASTBuildArgs({"-fsyntax-only", "-std=c++17"}),
+ /*VerifyResults=*/
+ std::move(Expectations)),
+ llvm::Succeeded());
}
TEST(ProgramPointAnnotations, NoAnnotations) {
::testing::MockFunction<void(
- llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>,
- ASTContext &)>
+ const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
+ const AnalysisOutputs &)>
Expectations;
EXPECT_CALL(Expectations, Call(IsEmpty(), _)).Times(1);
@@ -99,9 +105,8 @@ TEST(ProgramPointAnnotations, NoAnnotations) {
TEST(ProgramPointAnnotations, NoAnnotationsDifferentTarget) {
::testing::MockFunction<void(
- llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>,
- ASTContext &)>
+ const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
+ const AnalysisOutputs &)>
Expectations;
EXPECT_CALL(Expectations, Call(IsEmpty(), _)).Times(1);
@@ -111,13 +116,13 @@ TEST(ProgramPointAnnotations, NoAnnotationsDifferentTarget) {
TEST(ProgramPointAnnotations, WithCodepoint) {
::testing::MockFunction<void(
- llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>,
- ASTContext &)>
+ const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
+ const AnalysisOutputs &)>
Expectations;
- EXPECT_CALL(Expectations,
- Call(UnorderedElementsAre(Pair("program-point", _)), _))
+ EXPECT_CALL(
+ Expectations,
+ Call(UnorderedElementsAre(IsStringMapEntry("program-point", _)), _))
.Times(1);
checkDataflow(R"cc(void target() {
@@ -129,14 +134,13 @@ TEST(ProgramPointAnnotations, WithCodepoint) {
TEST(ProgramPointAnnotations, MultipleCodepoints) {
::testing::MockFunction<void(
- llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>,
- ASTContext &)>
+ const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
+ const AnalysisOutputs &)>
Expectations;
EXPECT_CALL(Expectations,
- Call(UnorderedElementsAre(Pair("program-point-1", _),
- Pair("program-point-2", _)),
+ Call(UnorderedElementsAre(IsStringMapEntry("program-point-1", _),
+ IsStringMapEntry("program-point-2", _)),
_))
.Times(1);
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index d08afd096bc39..4616265ad2598 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -30,32 +30,31 @@ namespace {
using namespace clang;
using namespace dataflow;
using namespace test;
-using ::testing::_;
-using ::testing::ElementsAre;
using ::testing::IsNull;
using ::testing::NotNull;
-using ::testing::Pair;
-using ::testing::SizeIs;
+using ::testing::UnorderedElementsAre;
template <typename Matcher>
void runDataflow(llvm::StringRef Code, Matcher Match,
DataflowAnalysisOptions Options,
LangStandard::Kind Std = LangStandard::lang_cxx17,
llvm::StringRef TargetFun = "target") {
+ using ast_matchers::hasName;
ASSERT_THAT_ERROR(
- test::checkDataflow<NoopAnalysis>(
- Code, TargetFun,
- [Options](ASTContext &C, Environment &) {
- return NoopAnalysis(C, Options);
- },
- [&Match](
- llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) { Match(Results, ASTCtx); },
- {"-fsyntax-only", "-fno-delayed-template-parsing",
- "-std=" + std::string(
- LangStandard::getLangStandardForKind(Std).getName())}),
+ checkDataflow<NoopAnalysis>(
+ AnalysisInputs<NoopAnalysis>(Code, hasName(TargetFun),
+ [Options](ASTContext &C, Environment &) {
+ return NoopAnalysis(C, Options);
+ })
+ .withASTBuildArgs(
+ {"-fsyntax-only", "-fno-delayed-template-parsing",
+ "-std=" +
+ std::string(LangStandard::getLangStandardForKind(Std)
+ .getName())}),
+ /*VerifyResults=*/
+ [&Match](const llvm::StringMap<DataflowAnalysisState<NoopLattice>>
+ &Results,
+ const AnalysisOutputs &AO) { Match(Results, AO.ASTCtx); }),
llvm::Succeeded());
}
@@ -79,12 +78,10 @@ TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
)";
runDataflow(
Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -102,24 +99,23 @@ TEST(TransferTest, BoolVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
-
- const Value *FooVal = Env.getValue(*FooLoc);
- EXPECT_TRUE(isa_and_nonnull<BoolValue>(FooVal));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+
+ const Value *FooVal = Env.getValue(*FooLoc);
+ EXPECT_TRUE(isa_and_nonnull<BoolValue>(FooVal));
+ });
}
TEST(TransferTest, IntVarDecl) {
@@ -129,24 +125,23 @@ TEST(TransferTest, IntVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
-
- const Value *FooVal = Env.getValue(*FooLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+
+ const Value *FooVal = Env.getValue(*FooLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ });
}
TEST(TransferTest, StructVarDecl) {
@@ -161,12 +156,11 @@ TEST(TransferTest, StructVarDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -209,12 +203,11 @@ TEST(TransferTest, StructVarDeclWithInit) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -255,12 +248,11 @@ TEST(TransferTest, ClassVarDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -301,12 +293,11 @@ TEST(TransferTest, ReferenceVarDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -349,12 +340,11 @@ TEST(TransferTest, SelfReferentialReferenceVarDecl) {
// [[p]]
}
)";
- runDataflow(Code, [](llvm::ArrayRef<std::pair<
- std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ runDataflow(Code, [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>>
+ &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -446,12 +436,11 @@ TEST(TransferTest, PointerVarDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -494,12 +483,11 @@ TEST(TransferTest, SelfReferentialPointerVarDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -599,34 +587,33 @@ TEST(TransferTest, MultipleVarsDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
-
- const StorageLocation *BarLoc =
- Env.getStorageLocation(*BarDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(BarLoc));
-
- const Value *FooVal = Env.getValue(*FooLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
-
- const Value *BarVal = Env.getValue(*BarLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(BarVal));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+
+ const StorageLocation *BarLoc =
+ Env.getStorageLocation(*BarDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(BarLoc));
+
+ const Value *FooVal = Env.getValue(*FooLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+
+ const Value *BarVal = Env.getValue(*BarLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(BarVal));
+ });
}
TEST(TransferTest, JoinVarDecl) {
@@ -645,12 +632,11 @@ TEST(TransferTest, JoinVarDecl) {
// [[p4]]
}
)";
- runDataflow(Code, [](llvm::ArrayRef<std::pair<
- std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ runDataflow(Code, [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>>
+ &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p1", _), Pair("p2", _),
- Pair("p3", _), Pair("p4", _)));
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2", "p3", "p4"));
+
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -660,24 +646,25 @@ TEST(TransferTest, JoinVarDecl) {
const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
ASSERT_THAT(BazDecl, NotNull());
- const Environment &Env1 = Results[0].second.Env;
+ const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
+
const StorageLocation *FooLoc =
Env1.getStorageLocation(*FooDecl, SkipPast::None);
EXPECT_THAT(FooLoc, NotNull());
EXPECT_THAT(Env1.getStorageLocation(*BarDecl, SkipPast::None), IsNull());
EXPECT_THAT(Env1.getStorageLocation(*BazDecl, SkipPast::None), IsNull());
- const Environment &Env2 = Results[1].second.Env;
+ const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
EXPECT_EQ(Env2.getStorageLocation(*FooDecl, SkipPast::None), FooLoc);
EXPECT_THAT(Env2.getStorageLocation(*BarDecl, SkipPast::None), NotNull());
EXPECT_THAT(Env2.getStorageLocation(*BazDecl, SkipPast::None), IsNull());
- const Environment &Env3 = Results[2].second.Env;
+ const Environment &Env3 = getEnvironmentAtAnnotation(Results, "p3");
EXPECT_EQ(Env3.getStorageLocation(*FooDecl, SkipPast::None), FooLoc);
EXPECT_THAT(Env3.getStorageLocation(*BarDecl, SkipPast::None), IsNull());
EXPECT_THAT(Env3.getStorageLocation(*BazDecl, SkipPast::None), NotNull());
- const Environment &Env4 = Results[3].second.Env;
+ const Environment &Env4 = getEnvironmentAtAnnotation(Results, "p4");
EXPECT_EQ(Env4.getStorageLocation(*FooDecl, SkipPast::None), FooLoc);
EXPECT_THAT(Env4.getStorageLocation(*BarDecl, SkipPast::None), IsNull());
EXPECT_THAT(Env4.getStorageLocation(*BazDecl, SkipPast::None), IsNull());
@@ -693,25 +680,24 @@ TEST(TransferTest, BinaryOperatorAssign) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
- EXPECT_EQ(Env.getValue(*BarDecl, SkipPast::None), FooVal);
- });
+ EXPECT_EQ(Env.getValue(*BarDecl, SkipPast::None), FooVal);
+ });
}
TEST(TransferTest, VarDeclInitAssign) {
@@ -722,25 +708,24 @@ TEST(TransferTest, VarDeclInitAssign) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
- EXPECT_EQ(Env.getValue(*BarDecl, SkipPast::None), FooVal);
- });
+ EXPECT_EQ(Env.getValue(*BarDecl, SkipPast::None), FooVal);
+ });
}
TEST(TransferTest, VarDeclInitAssignChained) {
@@ -752,29 +737,28 @@ TEST(TransferTest, VarDeclInitAssignChained) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
- EXPECT_EQ(Env.getValue(*BarDecl, SkipPast::None), FooVal);
- EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), FooVal);
- });
+ EXPECT_EQ(Env.getValue(*BarDecl, SkipPast::None), FooVal);
+ EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), FooVal);
+ });
}
TEST(TransferTest, VarDeclInitAssignPtrDeref) {
@@ -787,32 +771,31 @@ TEST(TransferTest, VarDeclInitAssignPtrDeref) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ const Value *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
- const auto *BarVal =
- cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_EQ(Env.getValue(BarVal->getPointeeLoc()), FooVal);
+ const auto *BarVal =
+ cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_EQ(Env.getValue(BarVal->getPointeeLoc()), FooVal);
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
- EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), FooVal);
- });
+ EXPECT_EQ(Env.getValue(*BazDecl, SkipPast::None), FooVal);
+ });
}
TEST(TransferTest, AssignToAndFromReference) {
@@ -829,13 +812,12 @@ TEST(TransferTest, AssignToAndFromReference) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p1", _), Pair("p2", _)));
- const Environment &Env1 = Results[0].second.Env;
- const Environment &Env2 = Results[1].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
+ const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
+ const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -874,34 +856,33 @@ TEST(TransferTest, MultipleParamDecls) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
-
- const Value *FooVal = Env.getValue(*FooLoc);
- ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const StorageLocation *BarLoc =
- Env.getStorageLocation(*BarDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(BarLoc));
-
- const Value *BarVal = Env.getValue(*BarLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(BarVal));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+
+ const Value *FooVal = Env.getValue(*FooLoc);
+ ASSERT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const StorageLocation *BarLoc =
+ Env.getStorageLocation(*BarDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(BarLoc));
+
+ const Value *BarVal = Env.getValue(*BarLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(BarVal));
+ });
}
TEST(TransferTest, StructParamDecl) {
@@ -916,12 +897,11 @@ TEST(TransferTest, StructParamDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -960,12 +940,11 @@ TEST(TransferTest, ReferenceParamDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -996,12 +975,11 @@ TEST(TransferTest, PointerParamDecl) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1031,12 +1009,11 @@ TEST(TransferTest, StructMember) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1092,12 +1069,11 @@ TEST(TransferTest, DerivedBaseMemberClass) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1185,11 +1161,10 @@ TEST(TransferTest, DerivedBaseMemberClass) {
}
static void derivedBaseMemberExpectations(
- llvm::ArrayRef<std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1268,12 +1243,11 @@ TEST(TransferTest, ClassMember) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1324,25 +1298,26 @@ TEST(TransferTest, BaseClassInitializer) {
};
)";
ASSERT_THAT_ERROR(
- test::checkDataflow<NoopAnalysis>(
- Code, cxxConstructorDecl(ofClass(hasName("B"))),
- [](ASTContext &C, Environment &) {
- return NoopAnalysis(C, /*ApplyBuiltinTransfer=*/true);
- },
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
+ checkDataflow<NoopAnalysis>(
+ AnalysisInputs<NoopAnalysis>(
+ Code, cxxConstructorDecl(ofClass(hasName("B"))),
+ [](ASTContext &C, Environment &) {
+ return NoopAnalysis(C, /*ApplyBuiltinTransfer=*/true);
+ })
+ .withASTBuildArgs(
+ {"-fsyntax-only", "-fno-delayed-template-parsing",
+ "-std=" + std::string(LangStandard::getLangStandardForKind(
+ LangStandard::lang_cxx17)
+ .getName())}),
+ /*VerifyResults=*/
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ const AnalysisOutputs &) {
// Regression test to verify that base-class initializers do not
// trigger an assertion. If we add support for such initializers in
// the future, we can expand this test to check more specific
// properties.
- EXPECT_THAT(Results, ElementsAre(Pair("p", _)));
- },
- {"-fsyntax-only", "-fno-delayed-template-parsing",
- "-std=" + std::string(LangStandard::getLangStandardForKind(
- LangStandard::lang_cxx17)
- .getName())}),
+ EXPECT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ }),
llvm::Succeeded());
}
@@ -1358,12 +1333,11 @@ TEST(TransferTest, ReferenceMember) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1414,12 +1388,11 @@ TEST(TransferTest, StructThisMember) {
};
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
Env.getThisPointeeStorageLocation());
@@ -1491,12 +1464,11 @@ TEST(TransferTest, ClassThisMember) {
};
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const auto *ThisLoc =
cast<AggregateStorageLocation>(Env.getThisPointeeStorageLocation());
@@ -1562,12 +1534,10 @@ TEST(TransferTest, StructThisInLambda) {
)";
runDataflow(
ThisCaptureCode,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p1", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p1");
const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
Env.getThisPointeeStorageLocation());
@@ -1603,12 +1573,10 @@ TEST(TransferTest, StructThisInLambda) {
)";
runDataflow(
RefCaptureDefaultCode,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p2", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p2"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p2");
const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
Env.getThisPointeeStorageLocation());
@@ -1641,12 +1609,10 @@ TEST(TransferTest, StructThisInLambda) {
)";
runDataflow(
FreeFunctionLambdaCode,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p3", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p3"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p3");
EXPECT_THAT(Env.getThisPointeeStorageLocation(), IsNull());
},
@@ -1664,28 +1630,27 @@ TEST(TransferTest, ConstructorInitializer) {
}
};
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
- Env.getThisPointeeStorageLocation());
- ASSERT_THAT(ThisLoc, NotNull());
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const auto *FooVal =
- cast<IntegerValue>(Env.getValue(*FooDecl, SkipPast::None));
-
- const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
- ASSERT_THAT(QuxDecl, NotNull());
- EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
+ Env.getThisPointeeStorageLocation());
+ ASSERT_THAT(ThisLoc, NotNull());
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const auto *FooVal =
+ cast<IntegerValue>(Env.getValue(*FooDecl, SkipPast::None));
+
+ const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ ASSERT_THAT(QuxDecl, NotNull());
+ EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+ });
}
TEST(TransferTest, DefaultInitializer) {
@@ -1700,28 +1665,27 @@ TEST(TransferTest, DefaultInitializer) {
}
};
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
- Env.getThisPointeeStorageLocation());
- ASSERT_THAT(ThisLoc, NotNull());
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const auto *FooVal =
- cast<IntegerValue>(Env.getValue(*FooDecl, SkipPast::None));
-
- const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
- ASSERT_THAT(QuxDecl, NotNull());
- EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
+ Env.getThisPointeeStorageLocation());
+ ASSERT_THAT(ThisLoc, NotNull());
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const auto *FooVal =
+ cast<IntegerValue>(Env.getValue(*FooDecl, SkipPast::None));
+
+ const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ ASSERT_THAT(QuxDecl, NotNull());
+ EXPECT_EQ(Env.getValue(*QuxDecl, SkipPast::None), FooVal);
+ });
}
TEST(TransferTest, DefaultInitializerReference) {
@@ -1737,12 +1701,11 @@ TEST(TransferTest, DefaultInitializerReference) {
};
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const auto *ThisLoc = dyn_cast<AggregateStorageLocation>(
Env.getThisPointeeStorageLocation());
@@ -1775,12 +1738,11 @@ TEST(TransferTest, TemporaryObject) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1814,12 +1776,10 @@ TEST(TransferTest, ElidableConstructor) {
)";
runDataflow(
Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1854,13 +1814,12 @@ TEST(TransferTest, AssignmentOperator) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p1", _), Pair("p2", _)));
- const Environment &Env1 = Results[0].second.Env;
- const Environment &Env2 = Results[1].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
+ const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
+ const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1916,12 +1875,11 @@ TEST(TransferTest, CopyConstructor) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -1962,12 +1920,11 @@ TEST(TransferTest, CopyConstructorWithParens) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2024,13 +1981,12 @@ TEST(TransferTest, MoveConstructor) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p1", _), Pair("p2", _)));
- const Environment &Env1 = Results[0].second.Env;
- const Environment &Env2 = Results[1].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p1", "p2"));
+ const Environment &Env1 = getEnvironmentAtAnnotation(Results, "p1");
+ const Environment &Env2 = getEnvironmentAtAnnotation(Results, "p2");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2080,29 +2036,28 @@ TEST(TransferTest, BindTemporary) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- const auto &FooVal =
- *cast<StructValue>(Env.getValue(*FooDecl, SkipPast::None));
- const auto *BarVal =
- cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_EQ(BarVal, FooVal.getChild(*BazDecl));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ const auto &FooVal =
+ *cast<StructValue>(Env.getValue(*FooDecl, SkipPast::None));
+ const auto *BarVal =
+ cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_EQ(BarVal, FooVal.getChild(*BazDecl));
+ });
}
TEST(TransferTest, StaticCast) {
@@ -2112,26 +2067,25 @@ TEST(TransferTest, StaticCast) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
- EXPECT_TRUE(isa<IntegerValue>(FooVal));
- EXPECT_TRUE(isa<IntegerValue>(BarVal));
- EXPECT_EQ(FooVal, BarVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+ EXPECT_TRUE(isa<IntegerValue>(FooVal));
+ EXPECT_TRUE(isa<IntegerValue>(BarVal));
+ EXPECT_EQ(FooVal, BarVal);
+ });
}
TEST(TransferTest, IntegralCast) {
@@ -2141,26 +2095,25 @@ TEST(TransferTest, IntegralCast) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
- EXPECT_TRUE(isa<IntegerValue>(FooVal));
- EXPECT_TRUE(isa<IntegerValue>(BarVal));
- EXPECT_EQ(FooVal, BarVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+ EXPECT_TRUE(isa<IntegerValue>(FooVal));
+ EXPECT_TRUE(isa<IntegerValue>(BarVal));
+ EXPECT_EQ(FooVal, BarVal);
+ });
}
TEST(TransferTest, IntegraltoBooleanCast) {
@@ -2170,25 +2123,24 @@ TEST(TransferTest, IntegraltoBooleanCast) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
- EXPECT_TRUE(isa<IntegerValue>(FooVal));
- EXPECT_TRUE(isa<BoolValue>(BarVal));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+ EXPECT_TRUE(isa<IntegerValue>(FooVal));
+ EXPECT_TRUE(isa<BoolValue>(BarVal));
+ });
}
TEST(TransferTest, IntegralToBooleanCastFromBool) {
@@ -2199,26 +2151,25 @@ TEST(TransferTest, IntegralToBooleanCastFromBool) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
- const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
- EXPECT_TRUE(isa<BoolValue>(FooVal));
- EXPECT_TRUE(isa<BoolValue>(BarVal));
- EXPECT_EQ(FooVal, BarVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+ const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+ EXPECT_TRUE(isa<BoolValue>(FooVal));
+ EXPECT_TRUE(isa<BoolValue>(BarVal));
+ EXPECT_EQ(FooVal, BarVal);
+ });
}
TEST(TransferTest, NullToPointerCast) {
@@ -2234,80 +2185,77 @@ TEST(TransferTest, NullToPointerCast) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooXDecl = findValueDecl(ASTCtx, "FooX");
- ASSERT_THAT(FooXDecl, NotNull());
-
- const ValueDecl *FooYDecl = findValueDecl(ASTCtx, "FooY");
- ASSERT_THAT(FooYDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- const ValueDecl *NullDecl = findValueDecl(ASTCtx, "Null");
- ASSERT_THAT(NullDecl, NotNull());
-
- const auto *FooXVal =
- cast<PointerValue>(Env.getValue(*FooXDecl, SkipPast::None));
- const auto *FooYVal =
- cast<PointerValue>(Env.getValue(*FooYDecl, SkipPast::None));
- const auto *BarVal =
- cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
- const auto *BazVal =
- cast<PointerValue>(Env.getValue(*BazDecl, SkipPast::None));
- const auto *NullVal =
- cast<PointerValue>(Env.getValue(*NullDecl, SkipPast::None));
-
- EXPECT_EQ(FooXVal, FooYVal);
- EXPECT_NE(FooXVal, BarVal);
- EXPECT_NE(FooXVal, BazVal);
- EXPECT_NE(BarVal, BazVal);
-
- const StorageLocation &FooPointeeLoc = FooXVal->getPointeeLoc();
- EXPECT_TRUE(isa<ScalarStorageLocation>(FooPointeeLoc));
- EXPECT_THAT(Env.getValue(FooPointeeLoc), IsNull());
-
- const StorageLocation &BarPointeeLoc = BarVal->getPointeeLoc();
- EXPECT_TRUE(isa<ScalarStorageLocation>(BarPointeeLoc));
- EXPECT_THAT(Env.getValue(BarPointeeLoc), IsNull());
-
- const StorageLocation &BazPointeeLoc = BazVal->getPointeeLoc();
- EXPECT_TRUE(isa<AggregateStorageLocation>(BazPointeeLoc));
- EXPECT_THAT(Env.getValue(BazPointeeLoc), IsNull());
-
- const StorageLocation &NullPointeeLoc =
- NullVal->getPointeeLoc();
- EXPECT_TRUE(isa<ScalarStorageLocation>(NullPointeeLoc));
- EXPECT_THAT(Env.getValue(NullPointeeLoc), IsNull());
- });
-}
-
-TEST(TransferTest, NullToMemberPointerCast) {
- std::string Code = R"(
- struct Foo {};
- void target(Foo *Foo) {
- int Foo::*MemberPointer = nullptr;
- // [[p]]
- }
- )";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooXDecl = findValueDecl(ASTCtx, "FooX");
+ ASSERT_THAT(FooXDecl, NotNull());
+
+ const ValueDecl *FooYDecl = findValueDecl(ASTCtx, "FooY");
+ ASSERT_THAT(FooYDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ const ValueDecl *NullDecl = findValueDecl(ASTCtx, "Null");
+ ASSERT_THAT(NullDecl, NotNull());
+
+ const auto *FooXVal =
+ cast<PointerValue>(Env.getValue(*FooXDecl, SkipPast::None));
+ const auto *FooYVal =
+ cast<PointerValue>(Env.getValue(*FooYDecl, SkipPast::None));
+ const auto *BarVal =
+ cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ const auto *BazVal =
+ cast<PointerValue>(Env.getValue(*BazDecl, SkipPast::None));
+ const auto *NullVal =
+ cast<PointerValue>(Env.getValue(*NullDecl, SkipPast::None));
+
+ EXPECT_EQ(FooXVal, FooYVal);
+ EXPECT_NE(FooXVal, BarVal);
+ EXPECT_NE(FooXVal, BazVal);
+ EXPECT_NE(BarVal, BazVal);
+
+ const StorageLocation &FooPointeeLoc = FooXVal->getPointeeLoc();
+ EXPECT_TRUE(isa<ScalarStorageLocation>(FooPointeeLoc));
+ EXPECT_THAT(Env.getValue(FooPointeeLoc), IsNull());
+
+ const StorageLocation &BarPointeeLoc = BarVal->getPointeeLoc();
+ EXPECT_TRUE(isa<ScalarStorageLocation>(BarPointeeLoc));
+ EXPECT_THAT(Env.getValue(BarPointeeLoc), IsNull());
+
+ const StorageLocation &BazPointeeLoc = BazVal->getPointeeLoc();
+ EXPECT_TRUE(isa<AggregateStorageLocation>(BazPointeeLoc));
+ EXPECT_THAT(Env.getValue(BazPointeeLoc), IsNull());
+
+ const StorageLocation &NullPointeeLoc = NullVal->getPointeeLoc();
+ EXPECT_TRUE(isa<ScalarStorageLocation>(NullPointeeLoc));
+ EXPECT_THAT(Env.getValue(NullPointeeLoc), IsNull());
+ });
+}
+
+TEST(TransferTest, NullToMemberPointerCast) {
+ std::string Code = R"(
+ struct Foo {};
+ void target(Foo *Foo) {
+ int Foo::*MemberPointer = nullptr;
+ // [[p]]
+ }
+ )";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
const ValueDecl *MemberPointerDecl =
findValueDecl(ASTCtx, "MemberPointer");
ASSERT_THAT(MemberPointerDecl, NotNull());
@@ -2328,26 +2276,25 @@ TEST(TransferTest, AddrOfValue) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooLoc = cast<ScalarStorageLocation>(
- Env.getStorageLocation(*FooDecl, SkipPast::None));
- const auto *BarVal =
- cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooLoc = cast<ScalarStorageLocation>(
+ Env.getStorageLocation(*FooDecl, SkipPast::None));
+ const auto *BarVal =
+ cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc);
+ });
}
TEST(TransferTest, AddrOfReference) {
@@ -2357,26 +2304,25 @@ TEST(TransferTest, AddrOfReference) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooVal =
- cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None));
- const auto *BarVal =
- cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_EQ(&BarVal->getPointeeLoc(), &FooVal->getPointeeLoc());
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal =
+ cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None));
+ const auto *BarVal =
+ cast<PointerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_EQ(&BarVal->getPointeeLoc(), &FooVal->getPointeeLoc());
+ });
}
TEST(TransferTest, DerefDependentPtr) {
@@ -2388,12 +2334,11 @@ TEST(TransferTest, DerefDependentPtr) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2419,12 +2364,11 @@ TEST(TransferTest, VarDeclInitAssignConditionalOperator) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2459,31 +2403,30 @@ TEST(TransferTest, VarDeclInDoWhile) {
/*[[p]]*/
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *FooVal =
- cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None));
- const auto *FooPointeeVal =
- cast<IntegerValue>(Env.getValue(FooVal->getPointeeLoc()));
-
- const auto *BarVal = dyn_cast_or_null<IntegerValue>(
- Env.getValue(*BarDecl, SkipPast::None));
- ASSERT_THAT(BarVal, NotNull());
-
- EXPECT_EQ(BarVal, FooPointeeVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *FooVal =
+ cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None));
+ const auto *FooPointeeVal =
+ cast<IntegerValue>(Env.getValue(FooVal->getPointeeLoc()));
+
+ const auto *BarVal = dyn_cast_or_null<IntegerValue>(
+ Env.getValue(*BarDecl, SkipPast::None));
+ ASSERT_THAT(BarVal, NotNull());
+
+ EXPECT_EQ(BarVal, FooPointeeVal);
+ });
}
TEST(TransferTest, AggregateInitialization) {
@@ -2521,12 +2464,11 @@ TEST(TransferTest, AggregateInitialization) {
)";
for (const std::string &Code : {BracesCode, BraceEllisionCode}) {
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2585,25 +2527,24 @@ TEST(TransferTest, AssignToUnionMember) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
- ASSERT_TRUE(BazDecl->getType()->isUnionType());
-
- const auto *BazLoc = dyn_cast_or_null<AggregateStorageLocation>(
- Env.getStorageLocation(*BazDecl, SkipPast::None));
- ASSERT_THAT(BazLoc, NotNull());
-
- // FIXME: Add support for union types.
- EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+ ASSERT_TRUE(BazDecl->getType()->isUnionType());
+
+ const auto *BazLoc = dyn_cast_or_null<AggregateStorageLocation>(
+ Env.getStorageLocation(*BazDecl, SkipPast::None));
+ ASSERT_THAT(BazLoc, NotNull());
+
+ // FIXME: Add support for union types.
+ EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+ });
}
TEST(TransferTest, AssignFromBoolLiteral) {
@@ -2614,31 +2555,30 @@ TEST(TransferTest, AssignFromBoolLiteral) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const auto *FooVal = dyn_cast_or_null<AtomicBoolValue>(
- Env.getValue(*FooDecl, SkipPast::None));
- ASSERT_THAT(FooVal, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *BarVal = dyn_cast_or_null<AtomicBoolValue>(
- Env.getValue(*BarDecl, SkipPast::None));
- ASSERT_THAT(BarVal, NotNull());
-
- EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
- EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const auto *FooVal = dyn_cast_or_null<AtomicBoolValue>(
+ Env.getValue(*FooDecl, SkipPast::None));
+ ASSERT_THAT(FooVal, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *BarVal = dyn_cast_or_null<AtomicBoolValue>(
+ Env.getValue(*BarDecl, SkipPast::None));
+ ASSERT_THAT(BarVal, NotNull());
+
+ EXPECT_EQ(FooVal, &Env.getBoolLiteralValue(true));
+ EXPECT_EQ(BarVal, &Env.getBoolLiteralValue(false));
+ });
}
TEST(TransferTest, AssignFromCompositeBoolExpression) {
@@ -2650,12 +2590,11 @@ TEST(TransferTest, AssignFromCompositeBoolExpression) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2701,12 +2640,11 @@ TEST(TransferTest, AssignFromCompositeBoolExpression) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -2753,12 +2691,11 @@ TEST(TransferTest, AssignFromCompositeBoolExpression) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *ADecl = findValueDecl(ASTCtx, "A");
ASSERT_THAT(ADecl, NotNull());
@@ -2815,30 +2752,29 @@ TEST(TransferTest, AssignFromBoolNegation) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const auto *FooVal = dyn_cast_or_null<AtomicBoolValue>(
- Env.getValue(*FooDecl, SkipPast::None));
- ASSERT_THAT(FooVal, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const auto *BarVal = dyn_cast_or_null<NegationValue>(
- Env.getValue(*BarDecl, SkipPast::None));
- ASSERT_THAT(BarVal, NotNull());
-
- EXPECT_EQ(&BarVal->getSubVal(), FooVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const auto *FooVal = dyn_cast_or_null<AtomicBoolValue>(
+ Env.getValue(*FooDecl, SkipPast::None));
+ ASSERT_THAT(FooVal, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const auto *BarVal = dyn_cast_or_null<NegationValue>(
+ Env.getValue(*BarDecl, SkipPast::None));
+ ASSERT_THAT(BarVal, NotNull());
+
+ EXPECT_EQ(&BarVal->getSubVal(), FooVal);
+ });
}
TEST(TransferTest, BuiltinExpect) {
@@ -2848,23 +2784,22 @@ TEST(TransferTest, BuiltinExpect) {
/*[[p]]*/
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const auto &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
- Env.getValue(*BarDecl, SkipPast::None));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
+ Env.getValue(*BarDecl, SkipPast::None));
+ });
}
// `__builtin_expect` takes and returns a `long` argument, so other types
@@ -2877,23 +2812,22 @@ TEST(TransferTest, BuiltinExpectBoolArg) {
/*[[p]]*/
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const auto &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
- Env.getValue(*BarDecl, SkipPast::None));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
+ Env.getValue(*BarDecl, SkipPast::None));
+ });
}
TEST(TransferTest, BuiltinUnreachable) {
@@ -2908,26 +2842,25 @@ TEST(TransferTest, BuiltinUnreachable) {
/*[[p]]*/
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const auto &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- // `__builtin_unreachable` promises that the code is
- // unreachable, so the compiler treats the "then" branch as the
- // only possible predecessor of this statement.
- EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
- Env.getValue(*BarDecl, SkipPast::None));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ // `__builtin_unreachable` promises that the code is
+ // unreachable, so the compiler treats the "then" branch as the
+ // only possible predecessor of this statement.
+ EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
+ Env.getValue(*BarDecl, SkipPast::None));
+ });
}
TEST(TransferTest, BuiltinTrap) {
@@ -2942,25 +2875,24 @@ TEST(TransferTest, BuiltinTrap) {
/*[[p]]*/
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const auto &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- // `__builtin_trap` ensures program termination, so only the
- // "then" branch is a predecessor of this statement.
- EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
- Env.getValue(*BarDecl, SkipPast::None));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ // `__builtin_trap` ensures program termination, so only the
+ // "then" branch is a predecessor of this statement.
+ EXPECT_EQ(Env.getValue(*FooDecl, SkipPast::None),
+ Env.getValue(*BarDecl, SkipPast::None));
+ });
}
TEST(TransferTest, BuiltinDebugTrap) {
@@ -2975,24 +2907,23 @@ TEST(TransferTest, BuiltinDebugTrap) {
/*[[p]]*/
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const auto &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- // `__builtin_debugtrap` doesn't ensure program termination.
- EXPECT_NE(Env.getValue(*FooDecl, SkipPast::None),
- Env.getValue(*BarDecl, SkipPast::None));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ // `__builtin_debugtrap` doesn't ensure program termination.
+ EXPECT_NE(Env.getValue(*FooDecl, SkipPast::None),
+ Env.getValue(*BarDecl, SkipPast::None));
+ });
}
TEST(TransferTest, StaticIntSingleVarDecl) {
@@ -3002,24 +2933,23 @@ TEST(TransferTest, StaticIntSingleVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
-
- const Value *FooVal = Env.getValue(*FooLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+
+ const Value *FooVal = Env.getValue(*FooLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ });
}
TEST(TransferTest, StaticIntGroupVarDecl) {
@@ -3030,36 +2960,35 @@ TEST(TransferTest, StaticIntGroupVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
- const StorageLocation *FooLoc =
- Env.getStorageLocation(*FooDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
+ const StorageLocation *FooLoc =
+ Env.getStorageLocation(*FooDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(FooLoc));
- const StorageLocation *BarLoc =
- Env.getStorageLocation(*BarDecl, SkipPast::None);
- ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(BarLoc));
+ const StorageLocation *BarLoc =
+ Env.getStorageLocation(*BarDecl, SkipPast::None);
+ ASSERT_TRUE(isa_and_nonnull<ScalarStorageLocation>(BarLoc));
- const Value *FooVal = Env.getValue(*FooLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
+ const Value *FooVal = Env.getValue(*FooLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(FooVal));
- const Value *BarVal = Env.getValue(*BarLoc);
- EXPECT_TRUE(isa_and_nonnull<IntegerValue>(BarVal));
+ const Value *BarVal = Env.getValue(*BarLoc);
+ EXPECT_TRUE(isa_and_nonnull<IntegerValue>(BarVal));
- EXPECT_NE(FooVal, BarVal);
- });
+ EXPECT_NE(FooVal, BarVal);
+ });
}
TEST(TransferTest, GlobalIntVarDecl) {
@@ -3072,26 +3001,25 @@ TEST(TransferTest, GlobalIntVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- const Value *BarVal =
- cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
- const Value *BazVal =
- cast<IntegerValue>(Env.getValue(*BazDecl, SkipPast::None));
- EXPECT_EQ(BarVal, BazVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ const Value *BarVal =
+ cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ const Value *BazVal =
+ cast<IntegerValue>(Env.getValue(*BazDecl, SkipPast::None));
+ EXPECT_EQ(BarVal, BazVal);
+ });
}
TEST(TransferTest, StaticMemberIntVarDecl) {
@@ -3106,26 +3034,25 @@ TEST(TransferTest, StaticMemberIntVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- const Value *BarVal =
- cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
- const Value *BazVal =
- cast<IntegerValue>(Env.getValue(*BazDecl, SkipPast::None));
- EXPECT_EQ(BarVal, BazVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ const Value *BarVal =
+ cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ const Value *BazVal =
+ cast<IntegerValue>(Env.getValue(*BazDecl, SkipPast::None));
+ EXPECT_EQ(BarVal, BazVal);
+ });
}
TEST(TransferTest, StaticMemberRefVarDecl) {
@@ -3140,26 +3067,25 @@ TEST(TransferTest, StaticMemberRefVarDecl) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- const Value *BarVal =
- cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
- const Value *BazVal =
- cast<IntegerValue>(Env.getValue(*BazDecl, SkipPast::None));
- EXPECT_EQ(BarVal, BazVal);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ const Value *BarVal =
+ cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ const Value *BazVal =
+ cast<IntegerValue>(Env.getValue(*BazDecl, SkipPast::None));
+ EXPECT_EQ(BarVal, BazVal);
+ });
}
TEST(TransferTest, AssignMemberBeforeCopy) {
@@ -3177,33 +3103,32 @@ TEST(TransferTest, AssignMemberBeforeCopy) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
- const ValueDecl *A1Decl = findValueDecl(ASTCtx, "A1");
- ASSERT_THAT(A1Decl, NotNull());
+ const ValueDecl *A1Decl = findValueDecl(ASTCtx, "A1");
+ ASSERT_THAT(A1Decl, NotNull());
- const ValueDecl *A2Decl = findValueDecl(ASTCtx, "A2");
- ASSERT_THAT(A2Decl, NotNull());
+ const ValueDecl *A2Decl = findValueDecl(ASTCtx, "A2");
+ ASSERT_THAT(A2Decl, NotNull());
- const auto *BarVal =
- cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
+ const auto *BarVal =
+ cast<IntegerValue>(Env.getValue(*BarDecl, SkipPast::None));
- const auto *A2Val =
- cast<StructValue>(Env.getValue(*A2Decl, SkipPast::None));
- EXPECT_EQ(A2Val->getChild(*FooDecl), BarVal);
- });
+ const auto *A2Val =
+ cast<StructValue>(Env.getValue(*A2Decl, SkipPast::None));
+ EXPECT_EQ(A2Val->getChild(*FooDecl), BarVal);
+ });
}
TEST(TransferTest, BooleanEquality) {
@@ -3220,13 +3145,14 @@ TEST(TransferTest, BooleanEquality) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p-else", _), Pair("p-then", _)));
- const Environment &EnvElse = Results[0].second.Env;
- const Environment &EnvThen = Results[1].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p-then", "p-else"));
+ const Environment &EnvThen =
+ getEnvironmentAtAnnotation(Results, "p-then");
+ const Environment &EnvElse =
+ getEnvironmentAtAnnotation(Results, "p-else");
const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
ASSERT_THAT(BarDecl, NotNull());
@@ -3255,13 +3181,14 @@ TEST(TransferTest, BooleanInequality) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p-else", _), Pair("p-then", _)));
- const Environment &EnvElse = Results[0].second.Env;
- const Environment &EnvThen = Results[1].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p-then", "p-else"));
+ const Environment &EnvThen =
+ getEnvironmentAtAnnotation(Results, "p-then");
+ const Environment &EnvElse =
+ getEnvironmentAtAnnotation(Results, "p-else");
const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
ASSERT_THAT(BarDecl, NotNull());
@@ -3295,18 +3222,16 @@ TEST(TransferTest, CorrelatedBranches) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, SizeIs(3));
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p0", "p1", "p2"));
const ValueDecl *CDecl = findValueDecl(ASTCtx, "C");
ASSERT_THAT(CDecl, NotNull());
{
- ASSERT_THAT(Results[0], Pair("p0", _));
- const Environment &Env = Results[0].second.Env;
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p0");
const ValueDecl *BDecl = findValueDecl(ASTCtx, "B");
ASSERT_THAT(BDecl, NotNull());
auto &BVal = *cast<BoolValue>(Env.getValue(*BDecl, SkipPast::None));
@@ -3315,15 +3240,13 @@ TEST(TransferTest, CorrelatedBranches) {
}
{
- ASSERT_THAT(Results[1], Pair("p1", _));
- const Environment &Env = Results[1].second.Env;
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p1");
auto &CVal = *cast<BoolValue>(Env.getValue(*CDecl, SkipPast::None));
EXPECT_TRUE(Env.flowConditionImplies(CVal));
}
{
- ASSERT_THAT(Results[2], Pair("p2", _));
- const Environment &Env = Results[2].second.Env;
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p2");
auto &CVal = *cast<BoolValue>(Env.getValue(*CDecl, SkipPast::None));
EXPECT_TRUE(Env.flowConditionImplies(CVal));
}
@@ -3348,12 +3271,11 @@ TEST(TransferTest, LoopWithAssignmentConverges) {
// namely, that the analysis succeeds, rather than hitting the maximum number
// of iterations.
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
ASSERT_THAT(BarDecl, NotNull());
@@ -3381,12 +3303,11 @@ TEST(TransferTest, LoopWithReferenceAssignmentConverges) {
// namely, that the analysis succeeds, rather than hitting the maximum number
// of iterations.
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
ASSERT_THAT(BarDecl, NotNull());
@@ -3417,14 +3338,14 @@ TEST(TransferTest, LoopWithStructReferenceAssignmentConverges) {
// namely, that the analysis succeeds, rather than hitting the maximum number
// of iterations.
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results,
- ElementsAre(Pair("p-inner", _), Pair("p-outer", _)));
- const Environment &InnerEnv = Results[0].second.Env;
- const Environment &OuterEnv = Results[1].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p-inner", "p-outer"));
+ const Environment &InnerEnv =
+ getEnvironmentAtAnnotation(Results, "p-inner");
+ const Environment &OuterEnv =
+ getEnvironmentAtAnnotation(Results, "p-outer");
const ValueDecl *ValDecl = findValueDecl(ASTCtx, "val");
ASSERT_THAT(ValDecl, NotNull());
@@ -3469,8 +3390,7 @@ TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
// `CXXThisExpr` that refers to a union.
runDataflow(
Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
ASTContext &) {},
LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "operator=");
}
@@ -3493,12 +3413,11 @@ TEST(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
ASSERT_THAT(FooRefDecl, NotNull());
@@ -3555,12 +3474,11 @@ TEST(TransferTest, StructuredBindingAssignFromStructRefMembersToRefs) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
ASSERT_THAT(FooRefDecl, NotNull());
@@ -3618,12 +3536,11 @@ TEST(TransferTest, StructuredBindingAssignFromStructIntMembersToInts) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
ASSERT_THAT(FooRefDecl, NotNull());
@@ -3670,28 +3587,27 @@ TEST(TransferTest, BinaryOperatorComma) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- const StorageLocation *BarLoc =
- Env.getStorageLocation(*BarDecl, SkipPast::Reference);
- ASSERT_THAT(BarLoc, NotNull());
-
- const StorageLocation *BazLoc =
- Env.getStorageLocation(*BazDecl, SkipPast::Reference);
- EXPECT_EQ(BazLoc, BarLoc);
- });
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ const StorageLocation *BarLoc =
+ Env.getStorageLocation(*BarDecl, SkipPast::Reference);
+ ASSERT_THAT(BarLoc, NotNull());
+
+ const StorageLocation *BazLoc =
+ Env.getStorageLocation(*BazDecl, SkipPast::Reference);
+ EXPECT_EQ(BazLoc, BarLoc);
+ });
}
TEST(TransferTest, IfStmtBranchExtendsFlowCondition) {
@@ -3707,14 +3623,14 @@ TEST(TransferTest, IfStmtBranchExtendsFlowCondition) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results,
- ElementsAre(Pair("if_else", _), Pair("if_then", _)));
- const Environment &ThenEnv = Results[1].second.Env;
- const Environment &ElseEnv = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("if_then", "if_else"));
+ const Environment &ThenEnv =
+ getEnvironmentAtAnnotation(Results, "if_then");
+ const Environment &ElseEnv =
+ getEnvironmentAtAnnotation(Results, "if_else");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -3741,14 +3657,15 @@ TEST(TransferTest, WhileStmtBranchExtendsFlowCondition) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results,
- ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
- const Environment &LoopBodyEnv = Results[1].second.Env;
- const Environment &AfterLoopEnv = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(),
+ UnorderedElementsAre("loop_body", "after_loop"));
+ const Environment &LoopBodyEnv =
+ getEnvironmentAtAnnotation(Results, "loop_body");
+ const Environment &AfterLoopEnv =
+ getEnvironmentAtAnnotation(Results, "after_loop");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -3778,14 +3695,15 @@ TEST(TransferTest, DoWhileStmtBranchExtendsFlowCondition) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results,
- ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
- const Environment &LoopBodyEnv = Results[1].second.Env;
- const Environment &AfterLoopEnv = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(),
+ UnorderedElementsAre("loop_body", "after_loop"));
+ const Environment &LoopBodyEnv =
+ getEnvironmentAtAnnotation(Results, "loop_body");
+ const Environment &AfterLoopEnv =
+ getEnvironmentAtAnnotation(Results, "after_loop");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -3823,14 +3741,15 @@ TEST(TransferTest, ForStmtBranchExtendsFlowCondition) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results,
- ElementsAre(Pair("after_loop", _), Pair("loop_body", _)));
- const Environment &LoopBodyEnv = Results[1].second.Env;
- const Environment &AfterLoopEnv = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(),
+ UnorderedElementsAre("loop_body", "after_loop"));
+ const Environment &LoopBodyEnv =
+ getEnvironmentAtAnnotation(Results, "loop_body");
+ const Environment &AfterLoopEnv =
+ getEnvironmentAtAnnotation(Results, "after_loop");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -3856,12 +3775,12 @@ TEST(TransferTest, ForStmtBranchWithoutConditionDoesNotExtendFlowCondition) {
}
)";
runDataflow(
- Code, [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("loop_body", _)));
- const Environment &LoopBodyEnv = Results[0].second.Env;
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("loop_body"));
+ const Environment &LoopBodyEnv =
+ getEnvironmentAtAnnotation(Results, "loop_body");
const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
ASSERT_THAT(FooDecl, NotNull());
@@ -3883,23 +3802,21 @@ TEST(TransferTest, ContextSensitiveOptionDisabled) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{/*.ContextSensitiveOpts=*/llvm::None}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{/*.ContextSensitiveOpts=*/llvm::None}});
}
TEST(TransferTest, ContextSensitiveDepthZero) {
@@ -3913,23 +3830,21 @@ TEST(TransferTest, ContextSensitiveDepthZero) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{ContextSensitiveOptions{/*.Depth=*/0}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{/*.Depth=*/0}}});
}
TEST(TransferTest, ContextSensitiveSetTrue) {
@@ -3943,22 +3858,20 @@ TEST(TransferTest, ContextSensitiveSetTrue) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveSetFalse) {
@@ -3972,22 +3885,20 @@ TEST(TransferTest, ContextSensitiveSetFalse) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveSetBothTrueAndFalse) {
@@ -4003,31 +3914,28 @@ TEST(TransferTest, ContextSensitiveSetBothTrueAndFalse) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
-
- auto &BarVal =
- *cast<BoolValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(BarVal));
- EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(BarVal)));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+
+ auto &BarVal = *cast<BoolValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(BarVal));
+ EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(BarVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveSetTwoLayersDepthOne) {
@@ -4042,23 +3950,21 @@ TEST(TransferTest, ContextSensitiveSetTwoLayersDepthOne) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{ContextSensitiveOptions{/*.Depth=*/1}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{/*.Depth=*/1}}});
}
TEST(TransferTest, ContextSensitiveSetTwoLayersDepthTwo) {
@@ -4073,22 +3979,20 @@ TEST(TransferTest, ContextSensitiveSetTwoLayersDepthTwo) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{/*.Depth=*/2}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{/*.Depth=*/2}}});
}
TEST(TransferTest, ContextSensitiveSetThreeLayersDepthTwo) {
@@ -4104,23 +4008,21 @@ TEST(TransferTest, ContextSensitiveSetThreeLayersDepthTwo) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{ContextSensitiveOptions{/*.Depth=*/2}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{/*.Depth=*/2}}});
}
TEST(TransferTest, ContextSensitiveSetThreeLayersDepthThree) {
@@ -4136,22 +4038,20 @@ TEST(TransferTest, ContextSensitiveSetThreeLayersDepthThree) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{/*.Depth=*/3}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{/*.Depth=*/3}}});
}
TEST(TransferTest, ContextSensitiveMutualRecursion) {
@@ -4179,25 +4079,23 @@ TEST(TransferTest, ContextSensitiveMutualRecursion) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- // The analysis doesn't crash...
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- // ... but it also can't prove anything here.
- EXPECT_FALSE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{ContextSensitiveOptions{/*.Depth=*/4}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ // The analysis doesn't crash...
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ // ... but it also can't prove anything here.
+ EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{/*.Depth=*/4}}});
}
TEST(TransferTest, ContextSensitiveSetMultipleLines) {
@@ -4214,31 +4112,28 @@ TEST(TransferTest, ContextSensitiveSetMultipleLines) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
-
- auto &BarVal =
- *cast<BoolValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(BarVal));
- EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(BarVal)));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+
+ auto &BarVal = *cast<BoolValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(BarVal));
+ EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(BarVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveSetMultipleBlocks) {
@@ -4259,31 +4154,28 @@ TEST(TransferTest, ContextSensitiveSetMultipleBlocks) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
- ASSERT_THAT(BarDecl, NotNull());
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- auto &BarVal =
- *cast<BoolValue>(Env.getValue(*BarDecl, SkipPast::None));
- EXPECT_FALSE(Env.flowConditionImplies(BarVal));
- EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(BarVal)));
-
- auto &BazVal =
- *cast<BoolValue>(Env.getValue(*BazDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(BazVal));
- EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(BazVal)));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ ASSERT_THAT(BarDecl, NotNull());
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ auto &BarVal = *cast<BoolValue>(Env.getValue(*BarDecl, SkipPast::None));
+ EXPECT_FALSE(Env.flowConditionImplies(BarVal));
+ EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(BarVal)));
+
+ auto &BazVal = *cast<BoolValue>(Env.getValue(*BazDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(BazVal));
+ EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(BazVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveReturnVoid) {
@@ -4295,15 +4187,14 @@ TEST(TransferTest, ContextSensitiveReturnVoid) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- // This just tests that the analysis doesn't crash.
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ // This just tests that the analysis doesn't crash.
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveReturnTrue) {
@@ -4315,22 +4206,20 @@ TEST(TransferTest, ContextSensitiveReturnTrue) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveReturnFalse) {
@@ -4342,22 +4231,20 @@ TEST(TransferTest, ContextSensitiveReturnFalse) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveReturnArg) {
@@ -4372,22 +4259,20 @@ TEST(TransferTest, ContextSensitiveReturnArg) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
- ASSERT_THAT(BazDecl, NotNull());
-
- auto &BazVal =
- *cast<BoolValue>(Env.getValue(*BazDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(BazVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+ ASSERT_THAT(BazDecl, NotNull());
+
+ auto &BazVal = *cast<BoolValue>(Env.getValue(*BazDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(BazVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveReturnInt) {
@@ -4399,15 +4284,14 @@ TEST(TransferTest, ContextSensitiveReturnInt) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- // This just tests that the analysis doesn't crash.
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ // This just tests that the analysis doesn't crash.
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveMethodLiteral) {
@@ -4423,22 +4307,20 @@ TEST(TransferTest, ContextSensitiveMethodLiteral) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveMethodGetter) {
@@ -4457,22 +4339,20 @@ TEST(TransferTest, ContextSensitiveMethodGetter) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveMethodSetter) {
@@ -4491,22 +4371,20 @@ TEST(TransferTest, ContextSensitiveMethodSetter) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveMethodGetterAndSetter) {
@@ -4527,22 +4405,20 @@ TEST(TransferTest, ContextSensitiveMethodGetterAndSetter) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveConstructorBody) {
@@ -4560,22 +4436,20 @@ TEST(TransferTest, ContextSensitiveConstructorBody) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveConstructorInitializer) {
@@ -4593,22 +4467,20 @@ TEST(TransferTest, ContextSensitiveConstructorInitializer) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
TEST(TransferTest, ContextSensitiveConstructorDefault) {
@@ -4626,22 +4498,20 @@ TEST(TransferTest, ContextSensitiveConstructorDefault) {
// [[p]]
}
)";
- runDataflow(Code,
- [](llvm::ArrayRef<
- std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
- Results,
- ASTContext &ASTCtx) {
- ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
- const Environment &Env = Results[0].second.Env;
-
- const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
- ASSERT_THAT(FooDecl, NotNull());
-
- auto &FooVal =
- *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
- EXPECT_TRUE(Env.flowConditionImplies(FooVal));
- },
- {TransferOptions{ContextSensitiveOptions{}}});
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ auto &FooVal = *cast<BoolValue>(Env.getValue(*FooDecl, SkipPast::None));
+ EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+ },
+ {TransferOptions{ContextSensitiveOptions{}}});
}
} // namespace
More information about the cfe-commits
mailing list