[clang] [LifetimeSafety] Mark all DeclRefExpr as usages of the corresp. origin (PR #154316)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 5 13:11:44 PDT 2025
================
@@ -567,9 +565,47 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
return false;
}
+ void handleAssignment(const Expr *LHSExpr, const Expr *RHSExpr) {
+ // Find the underlying variable declaration for the left-hand side.
+ if (const auto *DRE_LHS =
+ dyn_cast<DeclRefExpr>(LHSExpr->IgnoreParenImpCasts())) {
+ markUseAsWrite(DRE_LHS);
+ if (const auto *VD_LHS = dyn_cast<ValueDecl>(DRE_LHS->getDecl()))
----------------
usx95 wrote:
(We are no more using an RAV to visit bottom-up but using `AC.getCFGBuildOptions().setAllAlwaysAdd();` to get a linearised AST stmts CFG essentially achieving the bottom up traversal order).
I am not a big fan either of the current top-down approach.
RAV only has a Traverse* which can be used as _before_ but not _after_. Also using RAV does not guarantee that CFG does not show the DRE earlier than required.
What we can instead do is generate UseFacts separately in another pass on AST (not on CFG, we don't need the CFG for this as we are only interested in all DRE expressions) which can be context aware.
https://github.com/llvm/llvm-project/pull/154316
More information about the cfe-commits
mailing list