[PATCH] D135741: Change DenseMap keys for APInt to avoid collision with valid APIint
Richard Trieu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 16:50:20 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcbdb81e60b45: Fix DenseMap with APInt keys (authored by rtrieu).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135741/new/
https://reviews.llvm.org/D135741
Files:
llvm/include/llvm/ADT/APInt.h
llvm/unittests/ADT/APIntTest.cpp
Index: llvm/unittests/ADT/APIntTest.cpp
===================================================================
--- llvm/unittests/ADT/APIntTest.cpp
+++ llvm/unittests/ADT/APIntTest.cpp
@@ -8,6 +8,7 @@
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "gtest/gtest.h"
@@ -3126,4 +3127,11 @@
EXPECT_EQ(APIntOps::ScaleBitMask(APInt(8, 0xE4), 4, true), APInt(4, 0x08));
}
+TEST(APIntTest, DenseMap) {
+ DenseMap<APInt, int> Map;
+ APInt ZeroWidthInt(0, 0, false);
+ Map.insert({ZeroWidthInt, 0});
+ Map.find(ZeroWidthInt);
+}
+
} // end anonymous namespace
Index: llvm/include/llvm/ADT/APInt.h
===================================================================
--- llvm/include/llvm/ADT/APInt.h
+++ llvm/include/llvm/ADT/APInt.h
@@ -2287,13 +2287,13 @@
template <> struct DenseMapInfo<APInt, void> {
static inline APInt getEmptyKey() {
APInt V(nullptr, 0);
- V.U.VAL = 0;
+ V.U.VAL = ~0ULL;
return V;
}
static inline APInt getTombstoneKey() {
APInt V(nullptr, 0);
- V.U.VAL = 1;
+ V.U.VAL = ~1ULL;
return V;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135741.472452.patch
Type: text/x-patch
Size: 1183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221101/72b955de/attachment.bin>
More information about the llvm-commits
mailing list