clang 22.0.0git
|
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"
Public Member Functions | |
Value * | 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. | |
StorageLocation & | 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. | |
void | clearConstMethodReturnValues (const RecordStorageLocation &RecordLoc) |
void | clearConstMethodReturnStorageLocations (const RecordStorageLocation &RecordLoc) |
bool | operator== (const CachedConstAccessorsLattice &Other) const |
LatticeEffect | join (const CachedConstAccessorsLattice &Other) |
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.
|
inline |
Definition at line 84 of file CachedConstAccessorsLattice.h.
|
inline |
Definition at line 80 of file CachedConstAccessorsLattice.h.
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:
Definition at line 197 of file CachedConstAccessorsLattice.h.
References clang::dataflow::Environment::createStorageLocation(), clang::Type::isRecordType(), and clang::Type::isReferenceType().
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:
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().
LatticeEffect clang::dataflow::CachedConstAccessorsLattice< Base >::join | ( | const CachedConstAccessorsLattice< Base > & | Other | ) |
Definition at line 151 of file CachedConstAccessorsLattice.h.
References clang::dataflow::internal::joinConstMethodMap(), and clang::Other.
|
inline |
Definition at line 89 of file CachedConstAccessorsLattice.h.