[clang] [LifetimeSafety] Add ExpireOriginFact to fix false positives for pointers in loops (PR #182368)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 03:13:17 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()) {
----------------
usx95 wrote:
I think the confusion might be stemming from the incapability of the analysis not being able to associate 7 and 2 here.
In principle, from language perspective, 2 and 7 should not be different and effecting should effect the other. These are essentially aliases to each other until `pp` is redefined to point to something else. Currently the analysis cannot model this flow-sensitive aliased origins and we observe this as a fallout.
I would also recommend to not clear these inner origins to better reflect the intention.
https://github.com/llvm/llvm-project/pull/182368
More information about the cfe-commits
mailing list