[clang] Reland "[LifetimeSafety] Detect iterator invalidation through container aliases" (PR #197873)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon May 18 06:22:46 PDT 2026


================
@@ -810,9 +810,11 @@ void FactsGenerator::handleInvalidatingCall(const Expr *Call,
 
   if (!isInvalidationMethod(*MD))
     return;
-  // Heuristics to turn-down false positives.
-  auto *DRE = dyn_cast<DeclRefExpr>(Args[0]);
-  if (!DRE || DRE->getDecl()->getType()->isReferenceType())
+
+  // Heuristics to turn-down false positives. Skip member field expressions for
+  // now. This is not a perfect filter and will still surface some false
+  // positives (e.g. `auto& r = s.v`).
+  if (!isa<DeclRefExpr>(Args[0]->IgnoreParenImpCasts()))
----------------
usx95 wrote:

I see. I would avoid special casing this. We need a more general solution for supporting lvalue expressions which are not `DeclRefExpr`. E.g. `(flag ? v1: v2).push_back(x)`.

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


More information about the cfe-commits mailing list