diff --git a/clang/include/clang/Analysis/FlowSensitive/MapLattice.h b/clang/include/clang/Analysis/FlowSensitive/MapLattice.h --- a/clang/include/clang/Analysis/FlowSensitive/MapLattice.h +++ b/clang/include/clang/Analysis/FlowSensitive/MapLattice.h @@ -19,11 +19,8 @@ #include #include -#include "DataflowAnalysis.h" #include "clang/AST/Decl.h" -#include "clang/Analysis/FlowSensitive/DataflowLattice.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/StringRef.h" namespace clang { namespace dataflow { @@ -92,17 +89,14 @@ /// If an entry exists in one map but not the other, the missing entry is /// treated as implicitly mapping to `bottom`. So, the joined map contains the /// entry as it was in the source map. - LatticeJoinEffect join(const MapLattice &Other) { - LatticeJoinEffect Effect = LatticeJoinEffect::Unchanged; + void join(const MapLattice &Other) { for (const auto &O : Other.C) { auto It = C.find(O.first); - if (It == C.end()) { + if (It == C.end()) C.insert(O); - Effect = LatticeJoinEffect::Changed; - } else if (It->second.join(O.second) == LatticeJoinEffect::Changed) - Effect = LatticeJoinEffect::Changed; + else + It->second.join(O.second); } - return Effect; } }; diff --git a/clang/include/clang/Analysis/FlowSensitive/NoopLattice.h b/clang/include/clang/Analysis/FlowSensitive/NoopLattice.h --- a/clang/include/clang/Analysis/FlowSensitive/NoopLattice.h +++ b/clang/include/clang/Analysis/FlowSensitive/NoopLattice.h @@ -13,7 +13,6 @@ #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_NOOP_LATTICE_H #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_NOOP_LATTICE_H -#include "clang/Analysis/FlowSensitive/DataflowLattice.h" #include namespace clang { @@ -26,15 +25,13 @@ public: bool operator==(const NoopLattice &Other) const { return true; } - LatticeJoinEffect join(const NoopLattice &Other) { - return LatticeJoinEffect::Unchanged; + void join(const NoopLattice &) {} + + friend std::ostream &operator<<(std::ostream &OS, const NoopLattice &) { + return OS << "noop"; } }; -inline std::ostream &operator<<(std::ostream &OS, const NoopLattice &) { - return OS << "noop"; -} - } // namespace dataflow } // namespace clang diff --git a/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp b/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp @@ -1,6 +1,4 @@ #include "clang/Analysis/FlowSensitive/MapLattice.h" -#include "clang/Analysis/FlowSensitive/DataflowLattice.h" -#include "llvm/Support/Error.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include @@ -19,12 +17,7 @@ static BooleanLattice top() { return BooleanLattice(true); } - LatticeJoinEffect join(BooleanLattice Other) { - auto Prev = Value; - Value = Value || Other.Value; - return Prev == Value ? LatticeJoinEffect::Unchanged - : LatticeJoinEffect::Changed; - } + void join(BooleanLattice Other) { Value = Value || Other.Value; } friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) { return LHS.Value == RHS.Value; @@ -91,7 +84,7 @@ UnorderedElementsAre(Pair(Key1, BooleanLattice(false)), Pair(Key2, BooleanLattice(false)))); - ASSERT_EQ(Lattice1.join(Lattice2), LatticeJoinEffect::Changed); + Lattice1.join(Lattice2); EXPECT_THAT(Lattice1, UnorderedElementsAre(Pair(Key1, BooleanLattice(true)), Pair(Key2, BooleanLattice(true)))); } @@ -101,7 +94,7 @@ Lattice.insert({Key1, BooleanLattice(false)}); Lattice.insert({Key2, BooleanLattice(false)}); - ASSERT_EQ(Lattice.join(Lattice), LatticeJoinEffect::Unchanged); + Lattice.join(Lattice); EXPECT_THAT(Lattice, UnorderedElementsAre(Pair(Key1, BooleanLattice(false)), Pair(Key2, BooleanLattice(false)))); } @@ -122,7 +115,7 @@ ASSERT_THAT(Lattice2, UnorderedElementsAre(Pair(Key1, BooleanLattice(true)), Pair(Key2, BooleanLattice(true)))); - ASSERT_EQ(Lattice2.join(Lattice1), LatticeJoinEffect::Unchanged); + Lattice2.join(Lattice1); EXPECT_THAT(Lattice2, UnorderedElementsAre(Pair(Key1, BooleanLattice(true)), Pair(Key2, BooleanLattice(true)))); } @@ -133,7 +126,7 @@ MapLattice Lattice2; Lattice2.insert({Key2, BooleanLattice(true)}); - ASSERT_EQ(Lattice1.join(Lattice2), LatticeJoinEffect::Changed); + Lattice1.join(Lattice2); EXPECT_THAT(Lattice1, UnorderedElementsAre(Pair(Key1, BooleanLattice(true)), Pair(Key2, BooleanLattice(true)))); } diff --git a/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp b/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp @@ -22,7 +22,6 @@ #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h" #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" @@ -56,12 +55,7 @@ static BooleanLattice top() { return BooleanLattice(true); } - LatticeJoinEffect join(BooleanLattice Other) { - auto Prev = Value; - Value = Value || Other.Value; - return Prev == Value ? LatticeJoinEffect::Unchanged - : LatticeJoinEffect::Changed; - } + void join(BooleanLattice Other) { Value = Value || Other.Value; } friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) { return LHS.Value == RHS.Value; diff --git a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp @@ -21,15 +21,12 @@ #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h" #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/Support/Error.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -79,17 +76,16 @@ return !(Lhs == Rhs); } - LatticeJoinEffect join(const ValueLattice &Other) { + void join(const ValueLattice &Other) { if (*this == Other || Other == bottom() || *this == top()) - return LatticeJoinEffect::Unchanged; + return; if (*this == bottom()) { *this = Other; - return LatticeJoinEffect::Changed; + return; } *this = top(); - return LatticeJoinEffect::Changed; } }; diff --git a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp @@ -21,14 +21,11 @@ #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h" #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" -#include "clang/Analysis/FlowSensitive/DataflowLattice.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/Support/Error.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -72,17 +69,16 @@ return Lhs.Data == Rhs.Data; } - LatticeJoinEffect join(const ConstantPropagationLattice &Other) { + void join(const ConstantPropagationLattice &Other) { if (*this == Other || Other == bottom() || *this == top()) - return LatticeJoinEffect::Unchanged; + return; if (*this == bottom()) { *this = Other; - return LatticeJoinEffect::Changed; + return; } *this = top(); - return LatticeJoinEffect::Changed; } }; diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp --- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp @@ -16,7 +16,6 @@ #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h" #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h" #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h" -#include "clang/Analysis/FlowSensitive/DataflowLattice.h" #include "clang/Analysis/FlowSensitive/NoopAnalysis.h" #include "clang/Analysis/FlowSensitive/Value.h" #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h" @@ -92,17 +91,13 @@ } struct HasWidenLattice { - HasWidenLattice() { - ON_CALL(*this, join).WillByDefault([](const HasWidenLattice &) { - return LatticeJoinEffect::Unchanged; - }); - } + HasWidenLattice() = default; // Mock objects are not copyable by default. Since this is a monostate, // delegate to the default ctor. HasWidenLattice(const HasWidenLattice &) : HasWidenLattice() {} HasWidenLattice &operator=(const HasWidenLattice &) { return *this; } - MOCK_METHOD(LatticeJoinEffect, join, (const HasWidenLattice &)); + MOCK_METHOD(void, join, (const HasWidenLattice &)); MOCK_METHOD(void, widen, (const HasWidenLattice &)); friend bool operator==(const HasWidenLattice &, const HasWidenLattice &) { @@ -140,17 +135,13 @@ } struct OnlyJoinLattice { - OnlyJoinLattice() { - ON_CALL(*this, join).WillByDefault([](const OnlyJoinLattice &) { - return LatticeJoinEffect::Unchanged; - }); - } + OnlyJoinLattice() = default; // Mock objects are not copyable by default. Since this is a monostate, // delegate to the default ctor. OnlyJoinLattice(const OnlyJoinLattice &) : OnlyJoinLattice() {} OnlyJoinLattice &operator=(const OnlyJoinLattice &) { return *this; } - MOCK_METHOD(LatticeJoinEffect, join, (const OnlyJoinLattice &)); + MOCK_METHOD(void, join, (const OnlyJoinLattice &)); friend bool operator==(const OnlyJoinLattice &, const OnlyJoinLattice &) { return true; @@ -191,12 +182,7 @@ return State == Other.State; } - LatticeJoinEffect join(const NonConvergingLattice &Other) { - if (Other.State == 0) - return LatticeJoinEffect::Unchanged; - State += Other.State; - return LatticeJoinEffect::Changed; - } + void join(const NonConvergingLattice &Other) { State += Other.State; } }; class NonConvergingAnalysis @@ -236,12 +222,9 @@ return State == Other.State; } - LatticeJoinEffect join(const ConvergesOnWidenLattice &Other) { - auto Prev = *this; + void join(const ConvergesOnWidenLattice &Other) { Top = Top || Other.Top; State += Other.State; - return Prev == *this ? LatticeJoinEffect::Unchanged - : LatticeJoinEffect::Changed; } void widen(const ConvergesOnWidenLattice &Other) { Top = true; } @@ -286,14 +269,9 @@ return CalledFunctions == Other.CalledFunctions; } - LatticeJoinEffect join(const FunctionCallLattice &Other) { - if (Other.CalledFunctions.empty()) - return LatticeJoinEffect::Unchanged; - const size_t size_before = CalledFunctions.size(); + void join(const FunctionCallLattice &Other) { CalledFunctions.insert(Other.CalledFunctions.begin(), Other.CalledFunctions.end()); - return CalledFunctions.size() == size_before ? LatticeJoinEffect::Unchanged - : LatticeJoinEffect::Changed; } };