aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorEric Li <li.zhe.hua@gmail.com>2022-07-25 12:18:53 -0400
committerEric Li <li.zhe.hua@gmail.com>2022-07-25 14:24:33 -0400
commit29d35ece8249f2d8a51437a5c008e6bf63da9874 (patch)
tree0a88f142de088446bf101dfd4856ed8a595326ad /clang/unittests
parentfb95b8dc350ea84cf51b5f65aaaf1a5146ff3e47 (diff)
downloadllvm-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.cpp9
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))));