[llvm] [ADT] Fix FoldingSetIterator::operator* pointer adjustment for multiple inheritance (PR #219349)
Wenju He via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 19:51:33 PDT 2026
https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/219349
b7dc8e356b89 replaced the void*->FoldingSetNode*->T* cast in FoldingSetIteratorImpl::getNode() with a direct void*->T* cast, dropping the base-to-derived adjustment needed when FoldingSetNode isn't T's first base. Restore the FoldingSetNode* intermediate cast.
Found via a downstream user with a multiply-inherited FoldingSetNode type that iterates its FoldingSet directly (via find_if over begin()/end()), corrupting the dereferenced pointer and crashing.
>From e07695ad75c3e191fba907a45decf9bff1f297cd Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Fri, 28 Aug 2026 04:50:57 +0200
Subject: [PATCH] [ADT] Fix FoldingSetIterator::operator* pointer adjustment
for multiple inheritance
b7dc8e356b89 replaced the void*->FoldingSetNode*->T* cast in
FoldingSetIteratorImpl::getNode() with a direct void*->T* cast,
dropping the base-to-derived adjustment needed when FoldingSetNode
isn't T's first base. Restore the FoldingSetNode* intermediate cast.
Found via a downstream user with a multiply-inherited FoldingSetNode
type that iterates its FoldingSet directly (via find_if over
begin()/end()), corrupting the dereferenced pointer and crashing.
Co-Authored-By: Claude Sonnet 5 <noreply at anthropic.com>
---
llvm/include/llvm/ADT/FoldingSet.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/FoldingSet.h b/llvm/include/llvm/ADT/FoldingSet.h
index 48c2467754074..036d782a51d7d 100644
--- a/llvm/include/llvm/ADT/FoldingSet.h
+++ b/llvm/include/llvm/ADT/FoldingSet.h
@@ -659,7 +659,7 @@ template <class T> class FoldingSetIterator : DebugEpochBase::HandleBase {
T &operator*() const {
assert(isHandleInSync() && "invalid iterator access!");
- return *static_cast<T *>(*Bucket);
+ return *static_cast<T *>(static_cast<FoldingSetNode *>(*Bucket));
}
T *operator->() const { return &operator*(); }
More information about the llvm-commits
mailing list