[clang] [LifetimeSafety] Add ExpireOriginFact to fix false positives for pointers in loops (PR #182368)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 20 04:04:22 PST 2026


================
@@ -454,6 +462,17 @@ void FactsGenerator::handleLifetimeEnds(const CFGLifetimeEnds &LifetimeEnds) {
             BL->getID(), LifetimeEnds.getTriggerStmt()->getEndLoc()));
     }
   }
+  // In loops, the back-edge can make a dead origin appear live at its
+  // pointee's ExpireFact. Expiring the origin here prevents that.
+  if (OriginList *List = getOriginsList(*LifetimeEndsVD)) {
+    for (OriginList *L = List; L; L = L->peelOuterOrigin()) {
----------------
Xazax-hun wrote:

I don't think we want o go through the whole origin list.

E.g., if I have a pointer `int ***p;` and the lifetime of `p` ends that does not necessarily mean that the lifetime of the pointees would also end. 

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


More information about the cfe-commits mailing list