[llvm] [FoldingSet] Assert inserted node's profile matches its lookup (PR #220166)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 23:51:24 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
In FoldingSetImpl::insert, assert the node profile matches the insert
token. Otherwise, a memoized node can never be matched, leading to
missing hash consing.
This would catch SelectionDAG's missing CSE bug (#<!-- -->219911) and
a few clang sites.
---
Full diff: https://github.com/llvm/llvm-project/pull/220166.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/FoldingSet.h (+6)
``````````diff
diff --git a/llvm/include/llvm/ADT/FoldingSet.h b/llvm/include/llvm/ADT/FoldingSet.h
index a2ab413dcec94..c6a4cd77577b9 100644
--- a/llvm/include/llvm/ADT/FoldingSet.h
+++ b/llvm/include/llvm/ADT/FoldingSet.h
@@ -521,6 +521,12 @@ class FoldingSetImpl : public FoldingSetBase, public Trait::ContextStorage {
/// already in the folding set. \p Token must come from lookup for an ID that
/// \p N profiles identically to.
void insert(T *N, FoldingSetInsertToken Token) {
+#ifndef NDEBUG
+ FoldingSetNodeID ProfileID;
+ nodeProfile(N, ProfileID);
+ assert(makeInsertToken(ProfileID.computeHash()) == Token &&
+ "node profile must match the insert token");
+#endif
FoldingSetBase::insert(N, Token);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/220166
More information about the llvm-commits
mailing list