[llvm-branch-commits] [Hashing] Use a non-deterministic seed (PR #96282)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jun 20 23:46:35 PDT 2024


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/96282

Hashing.h provides hash_value/hash_combine/hash_combine_range, which are
primarily used by

* `DenseMap<StringRef, X>`
* `FoldingSetNodeIDRef::ComputeHash` (will be fixed by #96136)

Users shouldn't rely on specific hash values due to potential algorithm
changes. `set_fixed_execution_hash_seed` is provided but it has never
been used.

Take the the address of a static storage duration variable as the seed
like absl/hash/internal/hash.h `kSeed`.
(See https://reviews.llvm.org/D93931 for workaround for older Clang.
Mach-O x86-64 forces PIC, so absl's `__apple_build_version__` check is
unnecessary.)

A few users relying on the iteration order of `DenseMap<StringRef, X>`
have been fixed (e.g., f8f4235612b9 c025bd1fdbbd 89e8e63f47ff
86eb6bf6715c eb8d03656549 0ea6b8e476c2 58d7a6e0e636 8ea31db27211
255986e27fcf).
>From my experience fixing `DenseMap<A *, X>` and
[`StringMap`](https://discourse.llvm.org/t/reverse-iteration-bots/72224)
iteration order issues, the scale of breakage is smaller.





More information about the llvm-branch-commits mailing list