clang 23.0.0git
clang::lifetimes::internal::OriginManager Class Reference

Manages the creation, storage, and retrieval of origins for pointer-like variables and expressions. More...

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

Public Member Functions

 OriginManager (const AnalysisDeclContext &AC)
OriginListgetOrCreateList (const ValueDecl *D)
 Gets or creates the OriginList for a given ValueDecl.
OriginListgetOrCreateList (const Expr *E)
 Gets or creates the OriginList for a given Expr.
std::optional< OriginList * > getThisOrigins () const
 Returns the OriginList for the implicit 'this' parameter if the current declaration is an instance method.
const OrigingetOrigin (OriginID ID) const
llvm::ArrayRef< OrigingetOrigins () const
unsigned getNumOrigins () const
bool hasOrigins (QualType QT) const
bool hasOrigins (const Expr *E) const
 Determines if an expression has origins that need to be tracked.
void dump (OriginID OID, llvm::raw_ostream &OS) const
void collectMissingOrigins (Stmt &FunctionBody, LifetimeSafetyStats &LSStats)
 Collects statistics about expressions that lack associated origins.

Detailed Description

Manages the creation, storage, and retrieval of origins for pointer-like variables and expressions.

Definition at line 125 of file Origins.h.

Constructor & Destructor Documentation

◆ OriginManager()

clang::lifetimes::internal::OriginManager::OriginManager ( const AnalysisDeclContext & AC)
explicit

Definition at line 155 of file Origins.cpp.

References clang::AnalysisDeclContext::getDecl().

Member Function Documentation

◆ collectMissingOrigins()

void clang::lifetimes::internal::OriginManager::collectMissingOrigins ( Stmt & FunctionBody,
LifetimeSafetyStats & LSStats )

Collects statistics about expressions that lack associated origins.

Definition at line 291 of file Origins.cpp.

Referenced by clang::lifetimes::internal::collectLifetimeStats().

◆ dump()

◆ getNumOrigins()

unsigned clang::lifetimes::internal::OriginManager::getNumOrigins ( ) const
inline

Definition at line 155 of file Origins.h.

Referenced by clang::lifetimes::internal::computePersistentOrigins().

◆ getOrCreateList() [1/2]

OriginList * clang::lifetimes::internal::OriginManager::getOrCreateList ( const Expr * E)

Gets or creates the OriginList for a given Expr.

Creates a list based on the expression's type and value category:

  • Lvalues get an implicit reference level (modeling addressability)
  • Rvalues of non-pointer type return nullptr (no trackable origin)
  • DeclRefExpr may reuse the underlying declaration's list
Returns
The OriginList, or nullptr for non-pointer rvalues.

Definition at line 208 of file Origins.cpp.

References clang::lifetimes::internal::doesDeclHaveStorage(), getOrCreateList(), clang::Expr::getType(), hasOrigins(), clang::Expr::IgnoreParens(), clang::isa(), clang::Expr::isGLValue(), clang::Type::isReferenceType(), and clang::lifetimes::internal::OriginList::setInnerOriginList().

◆ getOrCreateList() [2/2]

OriginList * clang::lifetimes::internal::OriginManager::getOrCreateList ( const ValueDecl * D)

Gets or creates the OriginList for a given ValueDecl.

Creates a list structure mirroring the levels of indirection in the declaration's type (e.g., int** p creates list of size 2).

Returns
The OriginList, or nullptr if the type is not pointer-like.

Definition at line 199 of file Origins.cpp.

References clang::ValueDecl::getType(), and hasOrigins().

Referenced by getOrCreateList().

◆ getOrigin()

const Origin & clang::lifetimes::internal::OriginManager::getOrigin ( OriginID ID) const

Definition at line 286 of file Origins.cpp.

Referenced by dump().

◆ getOrigins()

llvm::ArrayRef< Origin > clang::lifetimes::internal::OriginManager::getOrigins ( ) const
inline

Definition at line 153 of file Origins.h.

◆ getThisOrigins()

std::optional< OriginList * > clang::lifetimes::internal::OriginManager::getThisOrigins ( ) const
inline

Returns the OriginList for the implicit 'this' parameter if the current declaration is an instance method.

Definition at line 149 of file Origins.h.

◆ hasOrigins() [1/2]

bool clang::lifetimes::internal::OriginManager::hasOrigins ( const Expr * E) const

Determines if an expression has origins that need to be tracked.

An expression has origins if:

  • It's a glvalue (has addressable storage), OR
  • Its type is pointer-like (pointer, reference, or gsl::Pointer), OR
  • Its type is registered for origin tracking (e.g., return type of a [[clang::lifetimebound]] function)

Examples:

  • int x; x : has origin (glvalue)
  • int* p; p : has 2 origins (1 for glvalue and 1 for pointer type)
  • std::string_view{} : has 1 origin (prvalue of pointer type)
  • 42 : no origin (prvalue of non-pointer type)
  • x + y : (where x, y are int) → no origin (prvalue of non-pointer type)

Definition at line 134 of file Origins.cpp.

References clang::Expr::getType(), hasOrigins(), and clang::Expr::isGLValue().

◆ hasOrigins() [2/2]


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