[llvm] r284336 - PR30711: Fix incorrect profiling of 'long long' in FoldingSet, then use it to
Richard Smith via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 16 10:49:10 PDT 2016
Author: rsmith
Date: Sun Oct 16 12:49:09 2016
New Revision: 284336
URL: http://llvm.org/viewvc/llvm-project?rev=284336&view=rev
Log:
PR30711: Fix incorrect profiling of 'long long' in FoldingSet, then use it to
fix TBAA violation in profiling of pointers.
Modified:
llvm/trunk/lib/Support/FoldingSet.cpp
llvm/trunk/unittests/ADT/FoldingSet.cpp
Modified: llvm/trunk/lib/Support/FoldingSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FoldingSet.cpp?rev=284336&r1=284335&r2=284336&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FoldingSet.cpp (original)
+++ llvm/trunk/lib/Support/FoldingSet.cpp Sun Oct 16 12:49:09 2016
@@ -54,8 +54,9 @@ void FoldingSetNodeID::AddPointer(const
// 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 l
}
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) {
Modified: llvm/trunk/unittests/ADT/FoldingSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/FoldingSet.cpp?rev=284336&r1=284335&r2=284336&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/FoldingSet.cpp (original)
+++ llvm/trunk/unittests/ADT/FoldingSet.cpp Sun Oct 16 12:49:09 2016
@@ -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;
More information about the llvm-commits
mailing list