[clang] [LifetimeSafety] Add UseFacts for function arguments and assignment RHS (PR #180446)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 04:09:16 PST 2026


================
@@ -260,9 +260,22 @@ void PointerToVectorElement() {
 }
 
 void SelfInvalidatingMap() {
-  std::unordered_map<int, int> mp;
-  mp[1] = 1;
-  mp[2] = mp[1];  // FIXME: Detect this. We are mising a UseFact for the assignment params.
+  std::unordered_map<int, std::string> mp;
+  // TODO: We do not have a way to differentiate between pointer stability and iterator stability!
+  // std::unordered_map and other containers provide pointer/reference stability. Therefore the
+  // following is safe in practice.
+  // On the other hand, std::flat_hash_map (since C++23) does not provide pointer stability on
+  // insertion and following is unsafe for this container.
+  mp[1] = "42";
+  mp[2] = mp[1];  // expected-warning {{object whose reference is captured is later invalidated}} \
----------------
Xazax-hun wrote:

Interesting. How come we do not generate a `UseFact` for the `DeclRefExpr` in this expression before these changes?


https://github.com/llvm/llvm-project/pull/180446


More information about the cfe-commits mailing list