================
@@ -243,6 +243,17 @@ OriginList *OriginManager::getOrCreateList(const Expr *E) {
if (It != ExprToList.end())
return It->second;
+ // A statement expression (`({ ...; e; })`) yields `e`'s value: share `e`'s
+ // origins rather than flowing into a fresh one. The flow would run at the
+ // statement expression's program point, which the CFG places after the
body's
+ // locals expire; sharing instead keeps the loan `e` produced in this origin
+ // from before those expiries. VisitStmtExpr adds the matching use.
+ if (const auto *SE = dyn_cast<StmtExpr>(E))
+ if (const CompoundStmt *CS = SE->getSubStmt(); CS && !CS->body_empty())
+ if (const auto *Last = dyn_cast<Expr>(CS->body_back()))
+ if (OriginList *List = getOrCreateList(Last))
+ return ExprToList[E] = List;
----------------
usx95 wrote:
Since we have a `CFGStmt` for the `StmtExpr`, I feel we can organically flow
the origin from the inner last stmt to the `StmtExpr` and lift this to
`VisitStmtExpr`.
https://github.com/llvm/llvm-project/pull/204841
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits