clang 24.0.0git
clang::lifetimes Namespace Reference

Namespaces

namespace  internal

Classes

struct  LifetimeSafetyOpts
class  LifetimeSafetySemaHelper
 Abstract interface for operations requiring Sema access. More...
class  LifetimeSafetySemaHelperImpl
struct  LifetimeSafetyStats
 A structure to hold the statistics related to LifetimeAnalysis. More...
class  UseSite
 Where and how an origin is used, for diagnostics. More...

Enumerations

enum class  UseKind { Explicit , Destructor , Cleanup }
 How an origin is used: by an expression, or implicitly at scope exit by a destructor or a cleanup callback that may read the borrows it holds. More...
enum class  WarningScope { CrossTU , IntraTU }
 Enum to track functions visible across or within TU. More...

Functions

void runLifetimeSafetyAnalysis (AnalysisDeclContext &AC, LifetimeSafetySemaHelper *SemaHelper, const LifetimeSafetyOpts &Opts, LifetimeSafetyStats &Stats, bool CollectStats)
 The main entry point for the analysis.
void printStats (const LifetimeSafetyStats &Stats)
 Utility function to print missing origin stats.
const FunctionDecl * getDeclWithMergedLifetimeBoundAttrs (const FunctionDecl *FD)
const CXXMethodDecl * getDeclWithMergedLifetimeBoundAttrs (const CXXMethodDecl *CMD)
bool isNormalAssignmentOperator (const FunctionDecl *FD)
bool isAssignmentOperatorLifetimeBound (const CXXMethodDecl *CMD)
template<typename AttrType>
static const AttrType * getAttrFromFunctionType (const FunctionDecl *FD)
 Check if a function has an attribute on its function type (which represents the implicit 'this' parameter for methods).
template<typename AttrType>
static const AttrType * getImplicitObjectParamAttr (const FunctionDecl *FD)
const LifetimeBoundAttr * getDirectImplicitObjectLifetimeBoundAttr (const FunctionDecl *FD)
const LifetimeBoundAttr * getImplicitObjectParamLifetimeBoundAttr (const FunctionDecl *FD)
bool implicitObjectParamIsLifetimeBound (const FunctionDecl *FD)
const LifetimeCaptureByAttr * getCaptureByAttrFromFunctionType (const FunctionDecl *FD)
std::optional< LifetimeBoundParamInfo > getTrackedArgInfo (const FunctionDecl *FD, llvm::ArrayRef< const Expr * > Args, unsigned I)
std::optional< LifetimeBoundParamInfo > getTrackingInfoForCallArg (const Expr *Call, const Expr *Source)
bool isInStlNamespace (const Decl *D)
bool isPointerLikeType (QualType QT)
static bool isReferenceOrPointerLikeType (QualType QT)
bool shouldTrackImplicitObjectArg (const Expr &ImplicitObjectArgument, const CXXMethodDecl *Callee, bool RunningUnderLifetimeSafety)
bool shouldTrackFirstArgument (const FunctionDecl *FD)
bool shouldTrackSecondArgument (const FunctionDecl *FD)
template<typename T>
static bool isRecordWithAttr (const CXXRecordDecl *RD)
template<typename T>
static bool isRecordWithAttr (QualType Type)
bool isGslPointerType (QualType QT)
bool isGslOwnerType (QualType QT)
bool isGslOwnerType (const CXXRecordDecl *RD)
bool isOwnerPtrCtor (const CXXConstructorDecl *Ctor, const ParmVarDecl *PVD)
static StringRef getName (const CXXRecordDecl &RD)
static StringRef getName (const FunctionDecl &FD)
static bool isStdUniquePtr (const CXXRecordDecl &RD)
bool isUniquePtrRelease (const CXXMethodDecl &MD)
bool isInvalidationMethod (const CXXMethodDecl &MD)
bool destructsFirstArg (const FunctionDecl &FD)
bool isStdCallableWrapperType (const CXXRecordDecl *RD)
bool isStdReferenceCast (const FunctionDecl *FD)
bool ShouldCheckSafety (Sema &S, const Decl *D)
bool ShouldCheckNoescapeViolations (Sema &S, const Decl *D)
bool ShouldCheckLifetimeboundViolations (Sema &S, const Decl *D)
bool ShouldCheckMisplacedLifetimebound (Sema &S, const Decl *D)
bool ShouldCheckInapplicableLifetimebound (Sema &S, const Decl *D)
bool ShouldCheckFieldOriginEscape (Sema &S, const Decl *D)
bool ShouldCheckDestructorUses (Sema &S, const Decl *D)
bool ShouldSuggestLifetimeAnnotations (Sema &S, const Decl *D)
bool IsLifetimeSafetyEnabled (Sema &S, const Decl *D)
LifetimeSafetyOpts GetLifetimeSafetyOpts (Sema &S, const Decl *D)

Enumeration Type Documentation

◆ UseKind

enum class clang::lifetimes::UseKind
strong

How an origin is used: by an expression, or implicitly at scope exit by a destructor or a cleanup callback that may read the borrows it holds.

Enumerator
Explicit 
Destructor 
Cleanup 

Definition at line 37 of file Facts.h.

◆ WarningScope

enum class clang::lifetimes::WarningScope
strong

Enum to track functions visible across or within TU.

Enumerator
CrossTU 
IntraTU 

Definition at line 55 of file LifetimeSafety.h.

Function Documentation

◆ destructsFirstArg()

bool clang::lifetimes::destructsFirstArg ( const FunctionDecl & FD)

Definition at line 536 of file LifetimeAnnotations.cpp.

References getName(), clang::isa(), and isInStlNamespace().

◆ getAttrFromFunctionType()

template<typename AttrType>
const AttrType * clang::lifetimes::getAttrFromFunctionType ( const FunctionDecl * FD)
static

Check if a function has an attribute on its function type (which represents the implicit 'this' parameter for methods).

Returns the attribute if found, nullptr otherwise.

Definition at line 64 of file LifetimeAnnotations.cpp.

References clang::TypeLoc::getAsAdjusted(), clang::TypeSourceInfo::getTypeLoc(), and clang::DeclaratorDecl::getTypeSourceInfo().

Referenced by getDirectImplicitObjectLifetimeBoundAttr(), and getImplicitObjectParamAttr().

◆ getCaptureByAttrFromFunctionType()

const LifetimeCaptureByAttr * clang::lifetimes::getCaptureByAttrFromFunctionType ( const FunctionDecl * FD)

Definition at line 118 of file LifetimeAnnotations.cpp.

References getImplicitObjectParamAttr().

◆ getDeclWithMergedLifetimeBoundAttrs() [1/2]

const CXXMethodDecl * clang::lifetimes::getDeclWithMergedLifetimeBoundAttrs ( const CXXMethodDecl * CMD)

Definition at line 30 of file LifetimeAnnotations.cpp.

References getDeclWithMergedLifetimeBoundAttrs().

◆ getDeclWithMergedLifetimeBoundAttrs() [2/2]

◆ getDirectImplicitObjectLifetimeBoundAttr()

const LifetimeBoundAttr * clang::lifetimes::getDirectImplicitObjectLifetimeBoundAttr ( const FunctionDecl * FD)

◆ getImplicitObjectParamAttr()

template<typename AttrType>
const AttrType * clang::lifetimes::getImplicitObjectParamAttr ( const FunctionDecl * FD)
static

◆ getImplicitObjectParamLifetimeBoundAttr()

const LifetimeBoundAttr * clang::lifetimes::getImplicitObjectParamLifetimeBoundAttr ( const FunctionDecl * FD)

◆ GetLifetimeSafetyOpts()

◆ getName() [1/2]

StringRef clang::lifetimes::getName ( const CXXRecordDecl & RD)
static

◆ getName() [2/2]

StringRef clang::lifetimes::getName ( const FunctionDecl & FD)
static

◆ getTrackedArgInfo()

◆ getTrackingInfoForCallArg()

std::optional< LifetimeBoundParamInfo > clang::lifetimes::getTrackingInfoForCallArg ( const Expr * Call,
const Expr * Source )

Definition at line 172 of file LifetimeAnnotations.cpp.

References clang::Call, and getTrackedArgInfo().

◆ implicitObjectParamIsLifetimeBound()

◆ isAssignmentOperatorLifetimeBound()

◆ isGslOwnerType() [1/2]

bool clang::lifetimes::isGslOwnerType ( const CXXRecordDecl * RD)

Definition at line 394 of file LifetimeAnnotations.cpp.

References isRecordWithAttr().

◆ isGslOwnerType() [2/2]

◆ isGslPointerType()

◆ isInStlNamespace()

◆ isInvalidationMethod()

◆ IsLifetimeSafetyEnabled()

◆ isNormalAssignmentOperator()

◆ isOwnerPtrCtor()

bool clang::lifetimes::isOwnerPtrCtor ( const CXXConstructorDecl * Ctor,
const ParmVarDecl * PVD )

◆ isPointerLikeType()

◆ isRecordWithAttr() [1/2]

template<typename T>
bool clang::lifetimes::isRecordWithAttr ( const CXXRecordDecl * RD)
static

◆ isRecordWithAttr() [2/2]

template<typename T>
bool clang::lifetimes::isRecordWithAttr ( QualType Type)
static

◆ isReferenceOrPointerLikeType()

bool clang::lifetimes::isReferenceOrPointerLikeType ( QualType QT)
static

◆ isStdCallableWrapperType()

◆ isStdReferenceCast()

bool clang::lifetimes::isStdReferenceCast ( const FunctionDecl * FD)

Definition at line 549 of file LifetimeAnnotations.cpp.

References clang::FunctionDecl::getBuiltinID().

◆ isStdUniquePtr()

bool clang::lifetimes::isStdUniquePtr ( const CXXRecordDecl & RD)
static

Definition at line 417 of file LifetimeAnnotations.cpp.

References getName(), and clang::Decl::isInStdNamespace().

Referenced by isUniquePtrRelease().

◆ isUniquePtrRelease()

◆ printStats()

◆ runLifetimeSafetyAnalysis()

◆ ShouldCheckDestructorUses()

bool clang::lifetimes::ShouldCheckDestructorUses ( Sema & S,
const Decl * D )
inline

◆ ShouldCheckFieldOriginEscape()

bool clang::lifetimes::ShouldCheckFieldOriginEscape ( Sema & S,
const Decl * D )
inline

◆ ShouldCheckInapplicableLifetimebound()

bool clang::lifetimes::ShouldCheckInapplicableLifetimebound ( Sema & S,
const Decl * D )
inline

◆ ShouldCheckLifetimeboundViolations()

bool clang::lifetimes::ShouldCheckLifetimeboundViolations ( Sema & S,
const Decl * D )
inline

◆ ShouldCheckMisplacedLifetimebound()

bool clang::lifetimes::ShouldCheckMisplacedLifetimebound ( Sema & S,
const Decl * D )
inline

◆ ShouldCheckNoescapeViolations()

bool clang::lifetimes::ShouldCheckNoescapeViolations ( Sema & S,
const Decl * D )
inline

◆ ShouldCheckSafety()

bool clang::lifetimes::ShouldCheckSafety ( Sema & S,
const Decl * D )
inline

◆ ShouldSuggestLifetimeAnnotations()

bool clang::lifetimes::ShouldSuggestLifetimeAnnotations ( Sema & S,
const Decl * D )
inline

◆ shouldTrackFirstArgument()

◆ shouldTrackImplicitObjectArg()

bool clang::lifetimes::shouldTrackImplicitObjectArg ( const Expr & ImplicitObjectArgument,
const CXXMethodDecl * Callee,
bool RunningUnderLifetimeSafety )

◆ shouldTrackSecondArgument()