diff options
| author | Weverything <rtrieu@google.com> | 2022-10-04 14:34:10 -0700 | 
|---|---|---|
| committer | Weverything <rtrieu@google.com> | 2022-11-01 16:23:32 -0700 | 
| commit | cbdb81e60b45e90996541f2661bad99606bfda06 (patch) | |
| tree | a47959ae3d2dc270dc665aaabe74c91957febbd8 /llvm/unittests/ADT/APIntTest.cpp | |
| parent | f357a412654cf5ae750a14b6f56900aaa029cec2 (diff) | |
| download | llvm-cbdb81e60b45e90996541f2661bad99606bfda06.zip llvm-cbdb81e60b45e90996541f2661bad99606bfda06.tar.gz llvm-cbdb81e60b45e90996541f2661bad99606bfda06.tar.bz2 | |
Fix DenseMap with APInt keys
The empty key value for APInt was colliding with a valid zero-width
APInt.  Change the internal value of empty key and tombstone values
for APInt to avoid this collision.
Fixes: https://github.com/llvm/llvm-project/issues/58013
Differential Revision: https://reviews.llvm.org/D135741
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 8 | 
1 files changed, 8 insertions, 0 deletions
| diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 0af294c..3dba0fa 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/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 @@ TEST(APIntTest, ScaleBitMask) {    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 | 
