summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/HashingTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-02 09:26:36 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-02 09:26:36 +0000
commit40119fb9c6708ff5add5a8a830a2e456eec286f8 (patch)
tree83c9b962754bd7262999f2179f2a104871f25b5c /llvm/unittests/ADT/HashingTest.cpp
parent4718430a5a4300bc4d8441ff6112ffb8280229a8 (diff)
downloadbcm5719-llvm-40119fb9c6708ff5add5a8a830a2e456eec286f8.tar.gz
bcm5719-llvm-40119fb9c6708ff5add5a8a830a2e456eec286f8.zip
We really want to hash pairs of directly-hashable data as directly
hashable data. This matters when we have pair<T*, U*> as a key, which is quite common in DenseMap, etc. To that end, we need to detect when this is safe. The requirements on a generic std::pair<T, U> are: 1) Both T and U must satisfy the existing is_hashable_data trait. Note that this includes the requirement that T and U have no internal padding bits or other bits not contributing directly to equality. 2) The alignment constraints of std::pair<T, U> do not require padding between consecutive objects. 3) The alignment constraints of U and the size of T do not conspire to require padding between the first and second elements. Grow two somewhat magical traits to detect this by forming a pod structure and inspecting offset artifacts on it. Hopefully this won't cause any compilers to panic. Added and adjusted tests now that pairs, even nested pairs, are treated as just sequences of data. Thanks to Jeffrey Yasskin for helping me sort through this and reviewing the somewhat subtle traits. llvm-svn: 151883
Diffstat (limited to 'llvm/unittests/ADT/HashingTest.cpp')
-rw-r--r--llvm/unittests/ADT/HashingTest.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp
index a9458bb5a5a..19a036cdf53 100644
--- a/llvm/unittests/ADT/HashingTest.cpp
+++ b/llvm/unittests/ADT/HashingTest.cpp
@@ -66,11 +66,13 @@ TEST(HashingTest, HashValueBasicTest) {
EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43ull)));
EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42, 43ull)));
EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43)));
- EXPECT_EQ(hash_combine(42, hash_combine(43, hash_combine(44, 45))),
- hash_value(
- std::make_pair(42, std::make_pair(43, std::make_pair(44, 45)))));
- EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
- EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
+
+ // Note that pairs are implicitly flattened to a direct sequence of data and
+ // hashed efficiently as a consequence.
+ EXPECT_EQ(hash_combine(42, 43, 44),
+ 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)));
}
template <typename T, size_t N> T *begin(T (&arr)[N]) { return arr; }
OpenPOWER on IntegriCloud