summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-10-16 17:49:09 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-10-16 17:49:09 +0000
commite3a9a676f9e3000662c05ff35a3b4312e04b5ee2 (patch)
tree2d733fa5c64945bc3a7ce34986d92327baffef35 /llvm
parent62ce463a35d7d0dd919672a0a824352b1847de06 (diff)
downloadbcm5719-llvm-e3a9a676f9e3000662c05ff35a3b4312e04b5ee2.tar.gz
bcm5719-llvm-e3a9a676f9e3000662c05ff35a3b4312e04b5ee2.zip
PR30711: Fix incorrect profiling of 'long long' in FoldingSet, then use it to
fix TBAA violation in profiling of pointers. llvm-svn: 284336
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Support/FoldingSet.cpp8
-rw-r--r--llvm/unittests/ADT/FoldingSet.cpp21
2 files changed, 25 insertions, 4 deletions
diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp
index a27d3174a4f..c9bca7f4c1a 100644
--- a/llvm/lib/Support/FoldingSet.cpp
+++ b/llvm/lib/Support/FoldingSet.cpp
@@ -54,8 +54,9 @@ void FoldingSetNodeID::AddPointer(const void *Ptr) {
// depend on the host. It doesn't matter, however, because hashing on
// pointer values is inherently unstable. Nothing should depend on the
// ordering of nodes in the folding set.
- Bits.append(reinterpret_cast<unsigned *>(&Ptr),
- reinterpret_cast<unsigned *>(&Ptr+1));
+ static_assert(sizeof(uintptr_t) <= sizeof(unsigned long long),
+ "unexpected pointer size");
+ AddInteger(reinterpret_cast<uintptr_t>(Ptr));
}
void FoldingSetNodeID::AddInteger(signed I) {
Bits.push_back(I);
@@ -80,8 +81,7 @@ void FoldingSetNodeID::AddInteger(long long I) {
}
void FoldingSetNodeID::AddInteger(unsigned long long I) {
AddInteger(unsigned(I));
- if ((uint64_t)(unsigned)I != I)
- Bits.push_back(unsigned(I >> 32));
+ AddInteger(unsigned(I >> 32));
}
void FoldingSetNodeID::AddString(StringRef String) {
diff --git a/llvm/unittests/ADT/FoldingSet.cpp b/llvm/unittests/ADT/FoldingSet.cpp
index 927ef313cb9..69646388119 100644
--- a/llvm/unittests/ADT/FoldingSet.cpp
+++ b/llvm/unittests/ADT/FoldingSet.cpp
@@ -35,6 +35,27 @@ TEST(FoldingSetTest, UnalignedStringTest) {
EXPECT_EQ(a.ComputeHash(), b.ComputeHash());
}
+TEST(FoldingSetTest, LongLongComparison) {
+ struct LongLongContainer : FoldingSetNode {
+ unsigned long long A, B;
+ LongLongContainer(unsigned long long A, unsigned long long B)
+ : A(A), B(B) {}
+ void Profile(FoldingSetNodeID &ID) const {
+ ID.AddInteger(A);
+ ID.AddInteger(B);
+ }
+ };
+
+ LongLongContainer C1((1ULL << 32) + 1, 1ULL);
+ LongLongContainer C2(1ULL, (1ULL << 32) + 1);
+
+ FoldingSet<LongLongContainer> Set;
+
+ EXPECT_EQ(&C1, Set.GetOrInsertNode(&C1));
+ EXPECT_EQ(&C2, Set.GetOrInsertNode(&C2));
+ EXPECT_EQ(2U, Set.size());
+}
+
struct TrivialPair : public FoldingSetNode {
unsigned Key = 0;
unsigned Value = 0;
OpenPOWER on IntegriCloud