summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/HashingTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-02 10:56:40 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-02 10:56:40 +0000
commit627e86238972c7631644d514d46a14922cd810b4 (patch)
tree468f4c10de9f38482daf7e0e30c8d6311e01bdd6 /llvm/unittests/ADT/HashingTest.cpp
parent04e5ce2bc12723bb0a0e0b905c99e0ea36086b84 (diff)
downloadbcm5719-llvm-627e86238972c7631644d514d46a14922cd810b4.tar.gz
bcm5719-llvm-627e86238972c7631644d514d46a14922cd810b4.zip
Simplify the pair optimization. Rather than using complex type traits,
just ensure that the number of bytes in the pair is the sum of the bytes in each side of the pair. As long as thats true, there are no extra bytes that might be padding. Also add a few tests that previously would have slipped through the checking. The more accurate checking mechanism catches these and ensures they are handled conservatively correctly. Thanks to Duncan for prodding me to do this right and more simply. llvm-svn: 151891
Diffstat (limited to 'llvm/unittests/ADT/HashingTest.cpp')
-rw-r--r--llvm/unittests/ADT/HashingTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp
index a12cf90e274..449b6afae23 100644
--- a/llvm/unittests/ADT/HashingTest.cpp
+++ b/llvm/unittests/ADT/HashingTest.cpp
@@ -42,6 +42,16 @@ using namespace llvm;
namespace {
+struct NonPOD {
+ uint64_t x, y;
+ NonPOD(uint64_t x, uint64_t y) : x(x), y(y) {}
+ ~NonPOD() {}
+ friend hash_code hash_value(const NonPOD &obj) {
+ return hash_combine(obj.x, obj.y);
+ }
+};
+
+
TEST(HashingTest, HashValueBasicTest) {
int x = 42, y = 43, c = 'x';
void *p = 0;
@@ -73,6 +83,16 @@ TEST(HashingTest, HashValueBasicTest) {
hash_value(std::make_pair(42, std::make_pair(43, 44))));
EXPECT_EQ(hash_value(std::make_pair(42, std::make_pair(43, 44))),
hash_value(std::make_pair(std::make_pair(42, 43), 44)));
+
+ // Ensure that pairs which have padding bytes *inside* them don't get treated
+ // this way.
+ EXPECT_EQ(hash_combine('0', hash_combine(1ull, '2')),
+ hash_value(std::make_pair('0', std::make_pair(1ull, '2'))));
+
+ // Ensure that non-POD pairs don't explode the traits used.
+ NonPOD obj1(1, 2), obj2(3, 4), obj3(5, 6);
+ EXPECT_EQ(hash_combine(obj1, hash_combine(obj2, obj3)),
+ hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
}
template <typename T, size_t N> T *begin(T (&arr)[N]) { return arr; }
OpenPOWER on IntegriCloud