clang 24.0.0git
clang::PtrRefSafetyModel Class Referenceabstract

Models one WebKit pointer-safety policy: ref-counted (RefPtr), checked (CheckedPtr), or retainable (RetainPtr/OSPtr). More...

#include "/work/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefSafetyModel.h"

Public Member Functions

virtual ~PtrRefSafetyModel ()=default
virtual std::optional< boolisUnsafeType (QualType QT) const =0
virtual std::optional< boolisUnsafePtr (QualType QT, bool IgnoreARC=false) const =0
virtual bool isSafePtr (const CXXRecordDecl *Record) const =0
virtual bool isSafePtrType (QualType T) const =0
virtual bool isPtrType (const std::string &Name) const =0
virtual bool isSafeExpr (const Expr *, bool PtrIsLifetimeBoundToOrigin) const
virtual bool checksForInteriorDestruction () const
virtual bool recognizesIndirectStores () const
virtual bool isSafeDecl (const Decl *, const SourceManager &) const
virtual const char * typeName () const =0
virtual void describeHazard (llvm::raw_ostream &Os, const Expr *, QualType SinkType) const
 Prints a phrase describing why the reported value is unsafe, completing a sentence of the form "Local variable 'x' is a ".
virtual RetainTypeCheckerretainTypeChecker () const

Detailed Description

Models one WebKit pointer-safety policy: ref-counted (RefPtr), checked (CheckedPtr), or retainable (RetainPtr/OSPtr).

It captures the family-specific "what is a safe/unsafe pointer" questions that are shared by the various RawPtrRef* checkers, independently of how each checker traverses the AST (call arguments, local variables, members, lambda captures, ...). This lets a single policy be defined once and reused across every traversal.

Definition at line 35 of file RawPtrRefSafetyModel.h.

Constructor & Destructor Documentation

◆ ~PtrRefSafetyModel()

virtual clang::PtrRefSafetyModel::~PtrRefSafetyModel ( )
virtualdefault

Member Function Documentation

◆ checksForInteriorDestruction()

virtual bool clang::PtrRefSafetyModel::checksForInteriorDestruction ( ) const
inlinevirtual
Returns
whether this policy checks for destruction of an object's interior while the object itself stays alive (borrow checking), rather than for deallocation of the object (the smart pointer policies).

Definition at line 69 of file RawPtrRefSafetyModel.h.

◆ describeHazard()

virtual void clang::PtrRefSafetyModel::describeHazard ( llvm::raw_ostream & Os,
const Expr * ,
QualType SinkType ) const
inlinevirtual

Prints a phrase describing why the reported value is unsafe, completing a sentence of the form "Local variable 'x' is a ".

Origin is the expression the value was traced back to, or null when the trace found none. SinkType is the type of the reported location.

Definition at line 92 of file RawPtrRefSafetyModel.h.

References clang::QualType::getTypePtr(), clang::Type::getUnqualifiedDesugaredType(), clang::isa(), clang::printTypeName(), and typeName().

◆ isPtrType()

virtual bool clang::PtrRefSafetyModel::isPtrType ( const std::string & Name) const
pure virtual
Returns
whether Name is the name of a safe smart pointer class for this policy.

◆ isSafeDecl()

virtual bool clang::PtrRefSafetyModel::isSafeDecl ( const Decl * ,
const SourceManager &  ) const
inlinevirtual
Returns
whether D refers to a declaration that is safe by construction for this policy (e.g. immortal system-header globals).

Definition at line 80 of file RawPtrRefSafetyModel.h.

◆ isSafeExpr()

virtual bool clang::PtrRefSafetyModel::isSafeExpr ( const Expr * ,
bool PtrIsLifetimeBoundToOrigin ) const
inlinevirtual
Returns
whether E is known to produce a safe value for this policy. PtrIsLifetimeBoundToOrigin is whether the traversal that reached E followed at least one [[clang::lifetimebound]] edge.

Definition at line 62 of file RawPtrRefSafetyModel.h.

◆ isSafePtr()

virtual bool clang::PtrRefSafetyModel::isSafePtr ( const CXXRecordDecl * Record) const
pure virtual
Returns
whether Record is a safe smart pointer for this policy.

◆ isSafePtrType()

virtual bool clang::PtrRefSafetyModel::isSafePtrType ( QualType T) const
pure virtual
Returns
whether T is a safe smart pointer type for this policy.

References clang::T.

◆ isUnsafePtr()

virtual std::optional< bool > clang::PtrRefSafetyModel::isUnsafePtr ( QualType QT,
bool IgnoreARC = false ) const
pure virtual
Returns
whether QT is a pointer/reference/view to an analyzed type, false if not, std::nullopt if inconclusive. IgnoreARC requests that Objective-C ARC be ignored when deciding retainability.

◆ isUnsafeType()

virtual std::optional< bool > clang::PtrRefSafetyModel::isUnsafeType ( QualType QT) const
pure virtual
Returns
whether QT itself is an unsafe (smart-pointer-capable but not managed) type, false if not, std::nullopt if inconclusive.

◆ recognizesIndirectStores()

virtual bool clang::PtrRefSafetyModel::recognizesIndirectStores ( ) const
inlinevirtual
Returns
whether this policy checks assignment through indirection, such as *out = _ or arr[0] = _. (Direct assignment to a named variable is always checked.)

FIXME: Make this flag true in all analyses and then remove it.

Definition at line 76 of file RawPtrRefSafetyModel.h.

◆ retainTypeChecker()

virtual RetainTypeChecker * clang::PtrRefSafetyModel::retainTypeChecker ( ) const
inlinevirtual
Returns
the RetainTypeChecker backing this policy, or nullptr if the policy does not track retain/OS types.

Definition at line 104 of file RawPtrRefSafetyModel.h.

◆ typeName()

virtual const char * clang::PtrRefSafetyModel::typeName ( ) const
pure virtual
Returns
a human readable name for the safe type category, used in diagnostics (e.g. "RefPtr-capable type").

Referenced by describeHazard().


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