clang 20.0.0git
Public Member Functions | List of all members
clang::dataflow::CachedConstAccessorsLattice< Base > Class Template Reference

A mixin for a lattice that additionally maintains a cache of stable method call return values to model const accessors methods. More...

#include "clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h"

Inheritance diagram for clang::dataflow::CachedConstAccessorsLattice< Base >:
Inheritance graph
[legend]

Public Member Functions

ValuegetOrCreateConstMethodReturnValue (const RecordStorageLocation &RecordLoc, const CallExpr *CE, Environment &Env)
 Creates or returns a previously created Value associated with a const method call obj.getFoo() where RecordLoc is the RecordStorageLocation of obj.
 
StorageLocationgetOrCreateConstMethodReturnStorageLocation (const RecordStorageLocation &RecordLoc, const CallExpr *CE, Environment &Env, llvm::function_ref< void(StorageLocation &)> Initialize)
 Creates or returns a previously created StorageLocation associated with a const method call obj.getFoo() where RecordLoc is the RecordStorageLocation of obj.
 
void clearConstMethodReturnValues (const RecordStorageLocation &RecordLoc)
 
void clearConstMethodReturnStorageLocations (const RecordStorageLocation &RecordLoc)
 
bool operator== (const CachedConstAccessorsLattice &Other) const
 
LatticeJoinEffect join (const CachedConstAccessorsLattice &Other)
 

Detailed Description

template<typename Base>
class clang::dataflow::CachedConstAccessorsLattice< Base >

A mixin for a lattice that additionally maintains a cache of stable method call return values to model const accessors methods.

When a non-const method is called, the cache should be cleared causing the next call to a const method to be considered a different value. NOTE: The user is responsible for clearing the cache.

For example:

class Bar { public: const std::optional<Foo>& getFoo() const; void clear(); }; void func(Bar& s) { if (s.getFoo().has_value()) { use(s.getFoo().value()); // safe (checked earlier getFoo()) s.clear(); use(s.getFoo().value()); // unsafe (invalidate cache for s) } }

Definition at line 48 of file CachedConstAccessorsLattice.h.

Member Function Documentation

◆ clearConstMethodReturnStorageLocations()

template<typename Base >
void clang::dataflow::CachedConstAccessorsLattice< Base >::clearConstMethodReturnStorageLocations ( const RecordStorageLocation RecordLoc)
inline

Definition at line 82 of file CachedConstAccessorsLattice.h.

◆ clearConstMethodReturnValues()

template<typename Base >
void clang::dataflow::CachedConstAccessorsLattice< Base >::clearConstMethodReturnValues ( const RecordStorageLocation RecordLoc)
inline

Definition at line 78 of file CachedConstAccessorsLattice.h.

◆ getOrCreateConstMethodReturnStorageLocation()

template<typename Base >
StorageLocation * clang::dataflow::CachedConstAccessorsLattice< Base >::getOrCreateConstMethodReturnStorageLocation ( const RecordStorageLocation RecordLoc,
const CallExpr CE,
Environment Env,
llvm::function_ref< void(StorageLocation &)>  Initialize 
)

Creates or returns a previously created StorageLocation associated with a const method call obj.getFoo() where RecordLoc is the RecordStorageLocation of obj.

The callback Initialize runs on the storage location if newly created. Returns nullptr if unable to find or create a value.

Requirements:

  • CE should return a location (GLValue or a record type).

Definition at line 194 of file CachedConstAccessorsLattice.h.

References clang::dataflow::Environment::createStorageLocation(), Env, clang::CallExpr::getDirectCallee(), clang::QualType::getNonReferenceType(), clang::Expr::getType(), clang::Expr::isGLValue(), clang::QualType::isNull(), clang::Type::isRecordType(), and Loc.

◆ getOrCreateConstMethodReturnValue()

template<typename Base >
Value * clang::dataflow::CachedConstAccessorsLattice< Base >::getOrCreateConstMethodReturnValue ( const RecordStorageLocation RecordLoc,
const CallExpr CE,
Environment Env 
)

Creates or returns a previously created Value associated with a const method call obj.getFoo() where RecordLoc is the RecordStorageLocation of obj.

Returns nullptr if unable to find or create a value.

Requirements:

  • CE should return a value (not a reference or record type)

Definition at line 170 of file CachedConstAccessorsLattice.h.

References clang::dataflow::Environment::createValue(), Env, clang::CallExpr::getDirectCallee(), clang::Expr::getType(), clang::Type::isRecordType(), and clang::Type::isReferenceType().

◆ join()

Definition at line 148 of file CachedConstAccessorsLattice.h.

References clang::Other.

◆ operator==()

template<typename Base >
bool clang::dataflow::CachedConstAccessorsLattice< Base >::operator== ( const CachedConstAccessorsLattice< Base > &  Other) const
inline

Definition at line 87 of file CachedConstAccessorsLattice.h.

References clang::Other.


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