[llvm-branch-commits] [clang] [LifetimeSafety] Associate origins to all l-valued expressions (PR #156896)
Utkarsh Saxena via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Sep 5 13:13:39 PDT 2025
================
@@ -438,12 +452,31 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
void VisitDeclStmt(const DeclStmt *DS) {
for (const Decl *D : DS->decls())
if (const auto *VD = dyn_cast<VarDecl>(D))
- if (hasOrigin(VD->getType()))
+ if (hasOrigin(VD))
if (const Expr *InitExpr = VD->getInit())
addAssignOriginFact(*VD, *InitExpr);
}
- void VisitDeclRefExpr(const DeclRefExpr *DRE) { handleUse(DRE); }
+ void VisitDeclRefExpr(const DeclRefExpr *DRE) {
+ handleUse(DRE);
+ // For non-pointer/non-view types, a reference to the variable's storage
+ // is a borrow. We create a loan for it.
+ // For pointer/view types, we stick to the existing model for now and do
+ // not create an extra origin for the l-value expression itself.
+
+ // FIXME: A loan to `DeclRefExpr` for a pointer or view type can be
----------------
usx95 wrote:
I agree. An LValueToRValue would be responsible for propagating the correct (inner) origin when we have multiple origins for l-valued pointer-type expressions.
> // FIXME: A loan to `DeclRefExpr` for a pointer or view type can be ambiguous
Avoided mentioning the ambiguity here. Changed to
```
TODO: A single origin for a `DeclRefExpr` for a pointer or view type
is not sufficient to model the different levels of indirection.
```
https://github.com/llvm/llvm-project/pull/156896
More information about the llvm-branch-commits
mailing list