clang 22.0.0git
Public Member Functions | List of all members
clang::lifetimes::internal::LifetimeSafetyAnalysis Class Reference

Running the lifetime safety analysis and querying its results. More...

#include "clang/Analysis/Analyses/LifetimeSafety.h"

Public Member Functions

 LifetimeSafetyAnalysis (AnalysisDeclContext &AC, LifetimeSafetyReporter *Reporter)
 
 ~LifetimeSafetyAnalysis ()
 
void run ()
 
LoanSet getLoansAtPoint (OriginID OID, ProgramPoint PP) const
 Returns the set of loans an origin holds at a specific program point.
 
std::vector< LoanIDgetExpiredLoansAtPoint (ProgramPoint PP) const
 Returns the set of loans that have expired at a specific program point.
 
std::optional< OriginIDgetOriginIDForDecl (const ValueDecl *D) const
 Finds the OriginID for a given declaration.
 
std::vector< LoanIDgetLoanIDForVar (const VarDecl *VD) const
 Finds the LoanID's for the loan created with the specific variable as their Path.
 
llvm::StringMap< ProgramPointgetTestPoints () const
 Retrieves program points that were specially marked in the source code for testing.
 

Detailed Description

Running the lifetime safety analysis and querying its results.

It encapsulates the various dataflow analyses.

Definition at line 101 of file LifetimeSafety.h.

Constructor & Destructor Documentation

◆ LifetimeSafetyAnalysis()

clang::lifetimes::internal::LifetimeSafetyAnalysis::LifetimeSafetyAnalysis ( AnalysisDeclContext AC,
LifetimeSafetyReporter Reporter 
)

Definition at line 1107 of file LifetimeSafety.cpp.

◆ ~LifetimeSafetyAnalysis()

clang::lifetimes::internal::LifetimeSafetyAnalysis::~LifetimeSafetyAnalysis ( )
default

Member Function Documentation

◆ getExpiredLoansAtPoint()

std::vector< LoanID > clang::lifetimes::internal::LifetimeSafetyAnalysis::getExpiredLoansAtPoint ( ProgramPoint  PP) const

Returns the set of loans that have expired at a specific program point.

Definition at line 1154 of file LifetimeSafety.cpp.

References clang::Result.

◆ getLoanIDForVar()

std::vector< LoanID > clang::lifetimes::internal::LifetimeSafetyAnalysis::getLoanIDForVar ( const VarDecl VD) const

Finds the LoanID's for the loan created with the specific variable as their Path.

Definition at line 1172 of file LifetimeSafety.cpp.

References clang::Result.

◆ getLoansAtPoint()

LoanSet clang::lifetimes::internal::LifetimeSafetyAnalysis::getLoansAtPoint ( OriginID  OID,
ProgramPoint  PP 
) const

Returns the set of loans an origin holds at a specific program point.

Definition at line 1147 of file LifetimeSafety.cpp.

◆ getOriginIDForDecl()

std::optional< OriginID > clang::lifetimes::internal::LifetimeSafetyAnalysis::getOriginIDForDecl ( const ValueDecl D) const

Finds the OriginID for a given declaration.

Returns a null optional if not found.

Definition at line 1163 of file LifetimeSafety.cpp.

References D.

◆ getTestPoints()

llvm::StringMap< ProgramPoint > clang::lifetimes::internal::LifetimeSafetyAnalysis::getTestPoints ( ) const

Retrieves program points that were specially marked in the source code for testing.

The analysis recognizes special function calls of the form void("__lifetime_test_point_<name>") as test points. This method returns a map from the annotation string (<name>) to the corresponding ProgramPoint. This allows test harnesses to query the analysis state at user-defined locations in the code.

Note
This is intended for testing only.

Definition at line 1181 of file LifetimeSafety.cpp.

References clang::Block.

◆ run()

void clang::lifetimes::internal::LifetimeSafetyAnalysis::run ( )

TODO(opt): Consider optimizing individual blocks before running the dataflow analysis.

  1. Expression Origins: These are assigned once and read at most once, forming simple chains. These chains can be compressed into a single assignment.
  2. Block-Local Loans: Origins of expressions are never read by other blocks; only Decls are visible. Therefore, loans in a block that never reach an Origin associated with a Decl can be safely dropped by the analysis.
  3. Collapse ExpireFacts belonging to same source location into a single Fact.

Definition at line 1112 of file LifetimeSafety.cpp.

References clang::CFG::dump(), clang::lifetimes::internal::FactGenerator::run(), and clang::lifetimes::internal::LifetimeChecker::run().


The documentation for this class was generated from the following files: