[PATCH] D130497: [clang][dataflow] Fix MapLattice::insert() to not drop return value
Eric Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 25 11:25:07 PDT 2022
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(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130497.447416.patch
Type: text/x-patch
Size: 1945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220725/72a6cfd5/attachment.bin>
More information about the cfe-commits
mailing list