[clang] [llvm] [llvm] Don't assume non-erased DenseMap entries remain valid after erase. NFC (PR #198982)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sat May 23 11:29:30 PDT 2026
================
@@ -60,12 +61,12 @@ template <class S1Ty, class S2Ty> void set_intersect(S1Ty &S1, const S2Ty &S2) {
if constexpr (detail::HasMemberRemoveIf<S1Ty, decltype(Pred)>) {
S1.remove_if(Pred);
} else {
- typename S1Ty::iterator Next;
- for (typename S1Ty::iterator I = S1.begin(); I != S1.end(); I = Next) {
- Next = std::next(I);
- if (!S2.count(*I))
- S1.erase(I); // Erase element if not in S2
- }
+ SmallVector<typename S1Ty::value_type> ToRemove;
+ for (const auto &E : S1)
+ if (!S2.count(E))
+ ToRemove.push_back(E);
+ for (const auto &E : ToRemove)
+ S1.erase(E);
----------------
MaskRay wrote:
`if constexpr (HasMemberRemoveIf) branch (L60-61)` utilizes the added `remove_if`. This chunk has been reverted
https://github.com/llvm/llvm-project/pull/198982
More information about the cfe-commits
mailing list