@@ -25,21 +25,11 @@ namespace {
2525
2626// / Represents the storage location being borrowed, e.g., a specific stack
2727// / variable.
28+ // / TODO: Model access paths of other types, e.g., s.field, heap and globals.
2829struct AccessPath {
2930 const clang::ValueDecl *D;
3031
31- enum class Kind : uint8_t {
32- StackVariable,
33- Temporary, // TODO: Handle.
34- Field, // TODO: Handle like `s.y`.
35- Heap, // TODO: Handle.
36- ArrayElement, // TODO: Handle.
37- Static, // TODO: Handle.
38- };
39-
40- Kind PathKind;
41-
42- AccessPath (const clang::ValueDecl *D, Kind K) : D(D), PathKind(K) {}
32+ AccessPath (const clang::ValueDecl *D) : D(D) {}
4333};
4434
4535// / A generic, type-safe wrapper for an ID, distinguished by its `Tag` type.
@@ -399,11 +389,11 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
399389 if (!hasOrigin (ICE->getType ()))
400390 return ;
401391 Visit (ICE->getSubExpr ());
402- // / TODO: Consider if this is actually useful in practice. Alternatively, we
403- // / could directly use the sub-expression's OriginID instead of creating a
404- // / new one.
405392 // An ImplicitCastExpr node itself gets an origin, which flows from the
406393 // origin of its sub-expression (after stripping its own parens/casts).
394+ // TODO: Consider if this is actually useful in practice. Alternatively, we
395+ // could directly use the sub-expression's OriginID instead of creating a
396+ // new one.
407397 addAssignOriginFact (*ICE, *ICE->getSubExpr ());
408398 }
409399
@@ -415,9 +405,9 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
415405 // Check if it's a local variable.
416406 if (VD->hasLocalStorage ()) {
417407 OriginID OID = FactMgr.getOriginMgr ().getOrCreate (*UO);
418- AccessPath AddrOfLocalVarPath (VD, AccessPath::Kind::StackVariable );
419- Loan &L = FactMgr.getLoanMgr ().addLoan (AddrOfLocalVarPath,
420- UO->getOperatorLoc ());
408+ AccessPath AddrOfLocalVarPath (VD);
409+ const Loan &L = FactMgr.getLoanMgr ().addLoan (AddrOfLocalVarPath,
410+ UO->getOperatorLoc ());
421411 CurrentBlockFacts.push_back (
422412 FactMgr.createFact <IssueFact>(L.ID , OID));
423413 }
@@ -469,6 +459,8 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
469459 // / TODO: Also handle trivial destructors (e.g., for `int`
470460 // / variables) which will never have a CFGAutomaticObjDtor node.
471461 // / TODO: Handle loans to temporaries.
462+ // / TODO: Consider using clang::CFG::BuildOptions::AddLifetime to reuse the
463+ // / lifetime ends.
472464 const VarDecl *DestructedVD = DtorOpt.getVarDecl ();
473465 if (!DestructedVD)
474466 return ;
@@ -479,9 +471,8 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
479471 const AccessPath &LoanPath = L.Path ;
480472 // Check if the loan is for a stack variable and if that variable
481473 // is the one being destructed.
482- if (LoanPath.PathKind == AccessPath::Kind::StackVariable)
483- if (LoanPath.D == DestructedVD)
484- CurrentBlockFacts.push_back (FactMgr.createFact <ExpireFact>(L.ID ));
474+ if (LoanPath.D == DestructedVD)
475+ CurrentBlockFacts.push_back (FactMgr.createFact <ExpireFact>(L.ID ));
485476 }
486477 }
487478
@@ -495,9 +486,9 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
495486// ========================================================================= //
496487} // anonymous namespace
497488
498- void runLifetimeAnalysis (const DeclContext &DC, const CFG &Cfg,
499- AnalysisDeclContext &AC) {
500- llvm::TimeTraceScope TimeProfile (" Lifetime Analysis " );
489+ void runLifetimeSafetyAnalysis (const DeclContext &DC, const CFG &Cfg,
490+ AnalysisDeclContext &AC) {
491+ llvm::TimeTraceScope TimeProfile (" LifetimeSafetyAnalysis " );
501492 DEBUG_WITH_TYPE (" PrintCFG" , Cfg.dump (AC.getASTContext ().getLangOpts (),
502493 /* ShowColors=*/ true ));
503494 FactManager FactMgr;
0 commit comments