clang 22.0.0git
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 >:
[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 FunctionDecl *Callee, 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, Callee is the decl for getFoo.
void clearConstMethodReturnValues (const RecordStorageLocation &RecordLoc)
void clearConstMethodReturnStorageLocations (const RecordStorageLocation &RecordLoc)
bool operator== (const CachedConstAccessorsLattice &Other) const
LatticeEffect 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 50 of file CachedConstAccessorsLattice.h.

Member Function Documentation

◆ clearConstMethodReturnStorageLocations()

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

Definition at line 84 of file CachedConstAccessorsLattice.h.

◆ clearConstMethodReturnValues()

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

Definition at line 80 of file CachedConstAccessorsLattice.h.

◆ getOrCreateConstMethodReturnStorageLocation()

template<typename Base>
StorageLocation & clang::dataflow::CachedConstAccessorsLattice< Base >::getOrCreateConstMethodReturnStorageLocation ( const RecordStorageLocation & RecordLoc,
const FunctionDecl * Callee,
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, Callee is the decl for getFoo.

The callback Initialize runs on the storage location if newly created.

Requirements:

  • Callee should return a location (return type is a reference type or a record type).

Definition at line 197 of file CachedConstAccessorsLattice.h.

References clang::dataflow::Environment::createStorageLocation(), clang::Type::isRecordType(), and clang::Type::isReferenceType().

◆ 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 173 of file CachedConstAccessorsLattice.h.

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

◆ join()

◆ operator==()

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

Definition at line 89 of file CachedConstAccessorsLattice.h.


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