[clang] [LifetimeSafety] Model GNU statement expressions (PR #204841)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 21 15:36:58 PDT 2026


================
@@ -780,6 +780,15 @@ void FactsGenerator::VisitCXXDeleteExpr(const CXXDeleteExpr *DE) {
       FactMgr.createFact<InvalidateOriginFact>(List->getOuterOriginID(), DE));
 }
 
+void FactsGenerator::VisitStmtExpr(const StmtExpr *SE) {
+  // Mark the value used here (its origins are shared with the final expression;
+  // see getOrCreateList). The CFG runs this point after the body's locals
+  // expire, so the use keeps that origin live across a body-local's expiry --
+  // the only way to catch such a borrow, since liveness comes only from a
+  // direct use, never backward through the flow that later delivers the value.
+  handleUse(SE);
----------------
usx95 wrote:

Once we model this as an origin flow (without sharing origins), I feel this might be not be required and could also fix the `discarded_body_local` false-positive.

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


More information about the cfe-commits mailing list