@@ -25,21 +25,11 @@ namespace {
25
25
26
26
// / Represents the storage location being borrowed, e.g., a specific stack
27
27
// / variable.
28
+ // / TODO: Model access paths of other types, e.g., s.field, heap and globals.
28
29
struct AccessPath {
29
30
const clang::ValueDecl *D;
30
31
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) {}
43
33
};
44
34
45
35
// / A generic, type-safe wrapper for an ID, distinguished by its `Tag` type.
@@ -399,11 +389,11 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
399
389
if (!hasOrigin (ICE->getType ()))
400
390
return ;
401
391
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.
405
392
// An ImplicitCastExpr node itself gets an origin, which flows from the
406
393
// 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.
407
397
addAssignOriginFact (*ICE, *ICE->getSubExpr ());
408
398
}
409
399
@@ -415,9 +405,9 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
415
405
// Check if it's a local variable.
416
406
if (VD->hasLocalStorage ()) {
417
407
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 ());
421
411
CurrentBlockFacts.push_back (
422
412
FactMgr.createFact <IssueFact>(L.ID , OID));
423
413
}
@@ -469,6 +459,8 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
469
459
// / TODO: Also handle trivial destructors (e.g., for `int`
470
460
// / variables) which will never have a CFGAutomaticObjDtor node.
471
461
// / TODO: Handle loans to temporaries.
462
+ // / TODO: Consider using clang::CFG::BuildOptions::AddLifetime to reuse the
463
+ // / lifetime ends.
472
464
const VarDecl *DestructedVD = DtorOpt.getVarDecl ();
473
465
if (!DestructedVD)
474
466
return ;
@@ -479,9 +471,8 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
479
471
const AccessPath &LoanPath = L.Path ;
480
472
// Check if the loan is for a stack variable and if that variable
481
473
// 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 ));
485
476
}
486
477
}
487
478
@@ -495,9 +486,9 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
495
486
// ========================================================================= //
496
487
} // anonymous namespace
497
488
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 " );
501
492
DEBUG_WITH_TYPE (" PrintCFG" , Cfg.dump (AC.getASTContext ().getLangOpts (),
502
493
/* ShowColors=*/ true ));
503
494
FactManager FactMgr;
0 commit comments