aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringMapTest.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2018-01-11 18:47:15 +0000
committerAaron Ballman <aaron@aaronballman.com>2018-01-11 18:47:15 +0000
commitaac638eb1e96629badbdd68a0e68e96c61bf9d21 (patch)
treeeb0d17f31c5e500637cf50e1ab9f26bf6a6ca76f /llvm/unittests/ADT/StringMapTest.cpp
parent29102b30023991ec1f15af5fd371d9504ed24ad5 (diff)
downloadllvm-aac638eb1e96629badbdd68a0e68e96c61bf9d21.zip
llvm-aac638eb1e96629badbdd68a0e68e96c61bf9d21.tar.gz
llvm-aac638eb1e96629badbdd68a0e68e96c61bf9d21.tar.bz2
Use size_t to represent the size of a StringMapEntry length and alignment rather than unsigned.
Patch by Matt Davis. llvm-svn: 322305
Diffstat (limited to 'llvm/unittests/ADT/StringMapTest.cpp')
-rw-r--r--llvm/unittests/ADT/StringMapTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp
index b5c6369..6e0ea0e 100644
--- a/llvm/unittests/ADT/StringMapTest.cpp
+++ b/llvm/unittests/ADT/StringMapTest.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/DataTypes.h"
#include "gtest/gtest.h"
+#include <limits>
#include <tuple>
using namespace llvm;
@@ -492,4 +493,43 @@ TEST(StringMapCustomTest, EmplaceTest) {
EXPECT_EQ(42, Map["abcd"].Data);
}
+// Test that StringMapEntryBase can handle size_t wide sizes.
+TEST(StringMapCustomTest, StringMapEntryBaseSize) {
+ size_t LargeValue;
+
+ // Test that the entry can represent max-unsigned.
+ if (sizeof(size_t) <= sizeof(unsigned))
+ LargeValue = std::numeric_limits<unsigned>::max();
+ else
+ LargeValue = std::numeric_limits<unsigned>::max() + 1ULL;
+ StringMapEntryBase LargeBase(LargeValue);
+ EXPECT_EQ(LargeValue, LargeBase.getKeyLength());
+
+ // Test that the entry can hold at least max size_t.
+ LargeValue = std::numeric_limits<size_t>::max();
+ StringMapEntryBase LargerBase(LargeValue);
+ LargeValue = std::numeric_limits<size_t>::max();
+ EXPECT_EQ(LargeValue, LargerBase.getKeyLength());
+}
+
+// Test that StringMapEntry can handle size_t wide sizes.
+TEST(StringMapCustomTest, StringMapEntrySize) {
+ size_t LargeValue;
+
+ // Test that the entry can represent max-unsigned.
+ if (sizeof(size_t) <= sizeof(unsigned))
+ LargeValue = std::numeric_limits<unsigned>::max();
+ else
+ LargeValue = std::numeric_limits<unsigned>::max() + 1ULL;
+ StringMapEntry<int> LargeEntry(LargeValue);
+ StringRef Key = LargeEntry.getKey();
+ EXPECT_EQ(LargeValue, Key.size());
+
+ // Test that the entry can hold at least max size_t.
+ LargeValue = std::numeric_limits<size_t>::max();
+ StringMapEntry<int> LargerEntry(LargeValue);
+ Key = LargerEntry.getKey();
+ EXPECT_EQ(LargeValue, Key.size());
+}
+
} // end anonymous namespace