This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG29d35ece8249: [clang][dataflow] Fix MapLattice::insert() to not drop return value (authored by li.zhe.hua).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D130497/new/ https://reviews.llvm.org/D130497 Files: clang/include/clang/Analysis/FlowSensitive/MapLattice.h clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp Index: clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp +++ clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp @@ -50,13 +50,18 @@ static constexpr int Key2 = 1; namespace { +using ::testing::_; using ::testing::Pair; using ::testing::UnorderedElementsAre; TEST(MapLatticeTest, InsertWorks) { MapLattice<int, BooleanLattice> Lattice; - Lattice.insert({Key1, BooleanLattice(false)}); - Lattice.insert({Key2, BooleanLattice(false)}); + EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, true)); + EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, true)); + + // Insertion fails on collision. + EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, false)); + EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, false)); EXPECT_THAT(Lattice, UnorderedElementsAre(Pair(Key1, BooleanLattice(false)), Pair(Key2, BooleanLattice(false)))); Index: clang/include/clang/Analysis/FlowSensitive/MapLattice.h =================================================================== --- clang/include/clang/Analysis/FlowSensitive/MapLattice.h +++ clang/include/clang/Analysis/FlowSensitive/MapLattice.h @@ -54,10 +54,13 @@ // The `bottom` element is the empty map. static MapLattice bottom() { return MapLattice(); } - void insert(const std::pair<const key_type, mapped_type> &P) { C.insert(P); } + std::pair<iterator, bool> + insert(const std::pair<const key_type, mapped_type> &P) { + return C.insert(P); + } - void insert(std::pair<const key_type, mapped_type> &&P) { - C.insert(std::move(P)); + std::pair<iterator, bool> insert(std::pair<const key_type, mapped_type> &&P) { + return C.insert(std::move(P)); } unsigned size() const { return C.size(); }
Index: clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp +++ clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp @@ -50,13 +50,18 @@ static constexpr int Key2 = 1; namespace { +using ::testing::_; using ::testing::Pair; using ::testing::UnorderedElementsAre; TEST(MapLatticeTest, InsertWorks) { MapLattice<int, BooleanLattice> Lattice; - Lattice.insert({Key1, BooleanLattice(false)}); - Lattice.insert({Key2, BooleanLattice(false)}); + EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, true)); + EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, true)); + + // Insertion fails on collision. + EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, false)); + EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, false)); EXPECT_THAT(Lattice, UnorderedElementsAre(Pair(Key1, BooleanLattice(false)), Pair(Key2, BooleanLattice(false)))); Index: clang/include/clang/Analysis/FlowSensitive/MapLattice.h =================================================================== --- clang/include/clang/Analysis/FlowSensitive/MapLattice.h +++ clang/include/clang/Analysis/FlowSensitive/MapLattice.h @@ -54,10 +54,13 @@ // The `bottom` element is the empty map. static MapLattice bottom() { return MapLattice(); } - void insert(const std::pair<const key_type, mapped_type> &P) { C.insert(P); } + std::pair<iterator, bool> + insert(const std::pair<const key_type, mapped_type> &P) { + return C.insert(P); + } - void insert(std::pair<const key_type, mapped_type> &&P) { - C.insert(std::move(P)); + std::pair<iterator, bool> insert(std::pair<const key_type, mapped_type> &&P) { + return C.insert(std::move(P)); } unsigned size() const { return C.size(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits