|
clang 22.0.0git
|
Namespaces | |
| namespace | utils |
Classes | |
| struct | AccessPath |
| Represents the storage location being borrowed, e.g., a specific stack variable. More... | |
| class | DataflowAnalysis |
| A generic, policy-based driver for dataflow analyses. More... | |
| class | ExpireFact |
| class | Fact |
| An abstract base class for a single, atomic lifetime-relevant event. More... | |
| class | FactManager |
| class | FactsGenerator |
| class | IssueFact |
| struct | LifetimeFactory |
| An object to hold the factories for immutable collections, ensuring that all created states share the same underlying memory management. More... | |
| class | LifetimeSafetyAnalysis |
| Running the lifetime safety analysis and querying its results. More... | |
| struct | LivenessInfo |
| Information about why an origin is live at a program point. More... | |
| class | LiveOriginsAnalysis |
| class | Loan |
| An abstract base class for a single "Loan" which represents lending a storage in memory. More... | |
| class | LoanManager |
| Manages the creation, storage and retrieval of loans. More... | |
| class | LoanPropagationAnalysis |
| struct | Origin |
| An Origin is a symbolic identifier that represents the set of possible loans a pointer-like object could hold at any given time. More... | |
| class | OriginEscapesFact |
| class | OriginFlowFact |
| class | OriginList |
| A list of origins representing levels of indirection for pointer-like types. More... | |
| class | OriginManager |
| Manages the creation, storage, and retrieval of origins for pointer-like variables and expressions. More... | |
| class | PathLoan |
| PathLoan represents lending a storage location that is visible within the function's scope (e.g., a local variable on stack). More... | |
| class | PlaceholderLoan |
| A placeholder loan held by a function parameter, representing a borrow from the caller's scope. More... | |
| class | TestPointFact |
| A dummy-fact used to mark a specific point in the code for testing. More... | |
| class | UseFact |
Typedefs | |
| using | FactID = utils::ID<struct FactTag> |
| using | ProgramPoint = const Fact * |
| A ProgramPoint identifies a location in the CFG by pointing to a specific Fact. | |
| using | CausingFactType |
| using | LivenessMap = llvm::ImmutableMap<OriginID, LivenessInfo> |
| using | LoanSet = llvm::ImmutableSet<LoanID> |
| using | OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet> |
| using | LoanID = utils::ID<struct LoanTag> |
| using | OriginID = utils::ID<struct OriginTag> |
Enumerations | |
| enum class | LivenessKind : uint8_t { Dead , Maybe , Must } |
| enum class | Direction { Forward , Backward } |
Functions | |
| void | runLifetimeChecker (const LoanPropagationAnalysis &LoanPropagation, const LiveOriginsAnalysis &LiveOrigins, const FactManager &FactMgr, AnalysisDeclContext &ADC, LifetimeSafetyReporter *Reporter) |
| Runs the lifetime checker, which detects use-after-free errors by examining loan expiration points and checking if any live origins hold the expired loan. | |
| void | collectLifetimeStats (AnalysisDeclContext &AC, OriginManager &OM, LifetimeSafetyStats &Stats) |
| llvm::raw_ostream & | operator<< (llvm::raw_ostream &OS, LoanID ID) |
| llvm::raw_ostream & | operator<< (llvm::raw_ostream &OS, OriginID ID) |
| bool | hasOrigins (QualType QT) |
| bool | hasOrigins (const Expr *E) |
| Determines if an expression has origins that need to be tracked. | |
| bool | doesDeclHaveStorage (const ValueDecl *D) |
| Returns true if the declaration has its own storage that can be borrowed. | |
| static Confidence | livenessKindToConfidence (LivenessKind K) |
| static const PathLoan * | createLoan (FactManager &FactMgr, const DeclRefExpr *DRE) |
| Creates a loan for the storage path of a given declaration reference. | |
| static OriginList * | getRValueOrigins (const Expr *E, OriginList *List) |
| Simulates LValueToRValue conversion by peeling the outer lvalue origin if the expression is a GLValue. | |
| static void | DebugOnlyFunction (AnalysisDeclContext &AC, const CFG &Cfg, FactManager &FactMgr) |
| static llvm::BitVector | computePersistentOrigins (const FactManager &FactMgr, const CFG &C) |
Definition at line 34 of file LiveOrigins.h.
| using clang::lifetimes::internal::FactID = utils::ID<struct FactTag> |
| using clang::lifetimes::internal::LivenessMap = llvm::ImmutableMap<OriginID, LivenessInfo> |
Definition at line 76 of file LiveOrigins.h.
| using clang::lifetimes::internal::LoanID = utils::ID<struct LoanTag> |
| using clang::lifetimes::internal::LoanSet = llvm::ImmutableSet<LoanID> |
Definition at line 29 of file LoanPropagation.h.
| using clang::lifetimes::internal::OriginID = utils::ID<struct OriginTag> |
| using clang::lifetimes::internal::OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet> |
Definition at line 30 of file LoanPropagation.h.
| using clang::lifetimes::internal::ProgramPoint = const Fact * |
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
identified by a lifetime-related event (Fact).
A ProgramPoint has "after" semantics: it represents the location immediately after its corresponding Fact.
|
strong |
| Enumerator | |
|---|---|
| Forward | |
| Backward | |
Definition at line 29 of file Dataflow.h.
|
strong |
| Enumerator | |
|---|---|
| Dead | |
| Maybe | |
| Must | |
Definition at line 37 of file LiveOrigins.h.
| void clang::lifetimes::internal::collectLifetimeStats | ( | AnalysisDeclContext & | AC, |
| OriginManager & | OM, | ||
| LifetimeSafetyStats & | Stats ) |
Definition at line 96 of file LifetimeSafety.cpp.
References clang::lifetimes::internal::OriginManager::collectMissingOrigins(), and clang::AnalysisDeclContext::getBody().
|
static |
Definition at line 29 of file LoanPropagation.cpp.
References clang::C, clang::lifetimes::internal::Fact::Expire, clang::lifetimes::internal::FactManager::getFacts(), clang::lifetimes::internal::OriginManager::getNumOrigins(), clang::lifetimes::internal::IssueFact::getOriginID(), clang::lifetimes::internal::FactManager::getOriginMgr(), clang::lifetimes::internal::UseFact::getUsedOrigins(), clang::lifetimes::internal::Fact::Issue, clang::lifetimes::internal::Fact::OriginEscapes, clang::lifetimes::internal::Fact::OriginFlow, clang::lifetimes::internal::OriginList::peelOuterOrigin(), clang::lifetimes::internal::Fact::TestPoint, and clang::lifetimes::internal::Fact::Use.
|
static |
Creates a loan for the storage path of a given declaration reference.
This function should be called whenever a DeclRefExpr represents a borrow.
| DRE | The declaration reference expression that initiates the borrow. |
Definition at line 64 of file FactsGenerator.cpp.
References clang::lifetimes::internal::LoanManager::createLoan(), clang::DeclRefExpr::getDecl(), and clang::lifetimes::internal::FactManager::getLoanMgr().
Referenced by clang::lifetimes::internal::FactsGenerator::VisitDeclRefExpr().
|
static |
Definition at line 37 of file LifetimeSafety.cpp.
References clang::CFG::dump(), clang::lifetimes::internal::FactManager::dump(), clang::Decl::dumpColor(), clang::AnalysisDeclContext::getASTContext(), clang::AnalysisDeclContext::getDecl(), and clang::ASTContext::getLangOpts().
Referenced by clang::lifetimes::internal::LifetimeSafetyAnalysis::run().
Returns true if the declaration has its own storage that can be borrowed.
References generally have no storage - they are aliases to other storage. For example: int x; // has storage (can issue loans to x's storage) int& r = x; // no storage (r is an alias to x's storage) int* p; // has storage (the pointer variable p itself has storage)
TODO: Handle lifetime extension. References initialized by temporaries can have storage when the temporary's lifetime is extended: const int& r = 42; // temporary has storage, lifetime extended Foo&& f = Foo{}; // temporary has storage, lifetime extended Currently, this function returns false for all reference types.
Definition at line 84 of file Origins.cpp.
References clang::ValueDecl::getType(), and clang::Type::isReferenceType().
Referenced by clang::lifetimes::internal::OriginManager::getOrCreateList(), and clang::lifetimes::internal::FactsGenerator::VisitDeclRefExpr().
|
static |
Simulates LValueToRValue conversion by peeling the outer lvalue origin if the expression is a GLValue.
For pointer/view GLValues, this strips the origin representing the storage location to get the origins of the pointed-to value.
Example: For View& v, returns the origin of what v points to, not v's storage.
Definition at line 107 of file FactsGenerator.cpp.
References clang::Expr::isGLValue(), and clang::lifetimes::internal::OriginList::peelOuterOrigin().
Referenced by clang::lifetimes::internal::FactsGenerator::VisitImplicitCastExpr(), and clang::lifetimes::internal::FactsGenerator::VisitMaterializeTemporaryExpr().
Determines if an expression has origins that need to be tracked.
An expression has origins if:
Examples:
Definition at line 67 of file Origins.cpp.
References clang::Expr::getType(), hasOrigins(), and clang::Expr::isGLValue().
Definition at line 51 of file Origins.cpp.
References clang::lifetimes::isGslPointerType(), and clang::Type::isPointerOrReferenceType().
Referenced by clang::lifetimes::internal::OriginManager::getOrCreateList(), clang::lifetimes::internal::OriginManager::getOrCreateList(), hasOrigins(), clang::lifetimes::internal::FactsGenerator::VisitConditionalOperator(), clang::lifetimes::internal::FactsGenerator::VisitCXXOperatorCallExpr(), and clang::lifetimes::internal::FactsGenerator::VisitInitListExpr().
|
static |
Definition at line 30 of file Checker.cpp.
References Dead, clang::lifetimes::Definite, clang::lifetimes::Maybe, Maybe, Must, and clang::lifetimes::None.
|
inline |
|
inline |
| void clang::lifetimes::internal::runLifetimeChecker | ( | const LoanPropagationAnalysis & | LoanPropagation, |
| const LiveOriginsAnalysis & | LiveOrigins, | ||
| const FactManager & | FactMgr, | ||
| AnalysisDeclContext & | ADC, | ||
| LifetimeSafetyReporter * | Reporter ) |
Runs the lifetime checker, which detects use-after-free errors by examining loan expiration points and checking if any live origins hold the expired loan.
Definition at line 212 of file Checker.cpp.
Referenced by clang::lifetimes::internal::LifetimeSafetyAnalysis::run().