================
@@ -64,29 +93,42 @@ void FactsGenerator::run() {
void FactsGenerator::VisitDeclStmt(const DeclStmt *DS) {
for (const Decl *D : DS->decls())
if (const auto *VD = dyn_cast<VarDecl>(D))
- if (hasOrigin(VD))
- if (const Expr *InitExpr = VD->getInit())
- killAndFlowOrigin(*VD, *InitExpr);
+ if (const Expr *InitExpr = VD->getInit()) {
+ OriginList *VDList = getOriginsList(*VD);
+ if (!VDList)
+ continue;
+ OriginList *InitList = getOriginsList(*InitExpr);
+ assert(InitList && "VarDecl had origins but InitExpr did not");
+ flow(VDList, InitList, /*Kill=*/true);
+ }
}
void FactsGenerator::VisitDeclRefExpr(const DeclRefExpr *DRE) {
+ // Skip function references as they are lifetimes are not interesting. Skip
+ // EnumConstants as they are not GLValues.
+ if (DRE->getFoundDecl()->isFunctionOrFunctionTemplate() ||
+ DRE->getEnumConstantDecl())
+ return;
+ assert(DRE->isGLValue());
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.
-
- // TODO: A single origin for a `DeclRefExpr` for a pointer or view type is
- // not sufficient to model the different levels of indirection. The current
- // single-origin model cannot distinguish between a loan to the variable's
- // storage and a loan to what it points to. A multi-origin model would be
- // required for this.
- if (!isPointerType(DRE->getType())) {
- if (const Loan *L = createLoan(FactMgr, DRE)) {
- OriginID ExprOID = FactMgr.getOriginMgr().getOrCreate(*DRE);
- CurrentBlockFacts.push_back(
- FactMgr.createFact<IssueFact>(L->ID, ExprOID));
- }
+ // For all declarations with storage (non-references), we issue a loan
+ // representing the borrow of the variable's storage itself.
+ //
+ // Examples:
+ // - `int x; x` issues loan to x's storage
+ // - `int* p; p` issues loan to p's storage (the pointer variable)
+ // - `View v; v` issues loan to v's storage (the view object)
+ // - `int& r = x; r`issues no loan (r has no storage, it's an alias to x)
----------------
ymand wrote:
```suggestion
// - `int& r = x; r` issues no loan (r has no storage, it's an alias to x)
```
https://github.com/llvm/llvm-project/pull/168344
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits