diff options
author | Eric Li <li.zhe.hua@gmail.com> | 2022-07-25 12:18:53 -0400 |
---|---|---|
committer | Eric Li <li.zhe.hua@gmail.com> | 2022-07-25 14:24:33 -0400 |
commit | 29d35ece8249f2d8a51437a5c008e6bf63da9874 (patch) | |
tree | 0a88f142de088446bf101dfd4856ed8a595326ad /clang/unittests | |
parent | fb95b8dc350ea84cf51b5f65aaaf1a5146ff3e47 (diff) | |
download | llvm-29d35ece8249f2d8a51437a5c008e6bf63da9874.zip llvm-29d35ece8249f2d8a51437a5c008e6bf63da9874.tar.gz llvm-29d35ece8249f2d8a51437a5c008e6bf63da9874.tar.bz2 |
[clang][dataflow] Fix MapLattice::insert() to not drop return value
Fix `MapLattice` API to return `std::pair<iterator, bool>`,
allowing users to detect when an element has been inserted without
performing a redundant map lookup.
Differential Revision: https://reviews.llvm.org/D130497
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp b/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp index d3436e8..f6fe81e 100644 --- a/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp @@ -50,13 +50,18 @@ static constexpr int Key1 = 0; 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)))); |