Skip to content

Commit 50923aa

Browse files
committed
[Serialization] Use specialized decl hash function for GlobalDeclID
See the comment: llvm#92083 (comment) After the patch, llvm#92083, the lower 32 bits of DeclID can be the same commonly. This may produce many collisions. It will be best to change the default hash implementation for uint64_t. But sent this one as a quick workaround.
1 parent 15bb026 commit 50923aa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clang/include/clang/AST/DeclID.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ template <> struct DenseMapInfo<clang::GlobalDeclID> {
230230
}
231231

232232
static unsigned getHashValue(const GlobalDeclID &Key) {
233-
return DenseMapInfo<DeclID>::getHashValue(Key.get());
233+
// Our default hash algorithm for 64 bits integer may not be very good.
234+
// In GlobalDeclID's case, it is pretty common that the lower 32 bits can
235+
// be same.
236+
return DenseMapInfo<uint32_t>::getHashValue(Key.getModuleFileIndex()) ^
237+
DenseMapInfo<uint32_t>::getHashValue(Key.getLocalDeclIndex());
234238
}
235239

236240
static bool isEqual(const GlobalDeclID &L, const GlobalDeclID &R) {

0 commit comments

Comments
 (0)