15#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWENVIRONMENT_H
16#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DATAFLOWENVIRONMENT_H
28#include "llvm/ADT/DenseMap.h"
29#include "llvm/ADT/DenseSet.h"
30#include "llvm/Support/ErrorHandling.h"
149 switch (
compare(
Type, Prev, PrevEnv, Current, CurrentEnv)) {
157 llvm_unreachable(
"all cases in switch covered");
328 template <
typename T>
329 std::enable_if_t<std::is_base_of<StorageLocation, T>::value, T &>
340 template <
typename T>
341 std::enable_if_t<std::is_base_of<Value, T>::value, T &>
408 llvm::DenseMap<AtomicBoolValue *, BoolValue *> Substitutions) {
410 std::move(Substitutions));
435 LLVM_DUMP_METHOD
void dump()
const;
436 LLVM_DUMP_METHOD
void dump(raw_ostream &
OS)
const;
452 int Depth,
int &CreatedValuesCount);
475 std::vector<const DeclContext *> CallStack;
488 llvm::DenseMap<const ValueDecl *, StorageLocation *> DeclToLoc;
489 llvm::DenseMap<const Expr *, StorageLocation *> ExprToLoc;
491 llvm::DenseMap<const StorageLocation *, Value *> LocToVal;
496 std::pair<StructValue *, const ValueDecl *>>
C Language Family Type Representation.
Represents a call to a C++ constructor.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
This represents one expression.
Represents a function declaration or definition.
A (possibly-)qualified type.
Token - This structure provides full information about a lexed token.
The base class of the type hierarchy.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
Models an atomic boolean.
Holds CFG and other derived context that is needed to perform dataflow analysis.
Owns objects that encompass the state of a program and stores context that is used during dataflow an...
BoolValue & buildAndSubstituteFlowCondition(AtomicBoolValue &Token, llvm::DenseMap< AtomicBoolValue *, BoolValue * > Substitutions)
Builds and returns the logical formula defining the flow condition identified by Token.
const Options & getOptions()
BoolValue & getOrCreateImplication(BoolValue &LHS, BoolValue &RHS)
Returns a boolean value that represents LHS => RHS.
std::enable_if_t< std::is_base_of< StorageLocation, T >::value, T & > takeOwnership(std::unique_ptr< T > Loc)
Takes ownership of Loc and returns a reference to it.
TopBoolValue & createTopBoolValue()
Creates a Top value for booleans.
AtomicBoolValue & getBoolLiteralValue(bool Value) const
Returns a symbolic boolean value that models a boolean literal equal to Value.
AtomicBoolValue & createAtomicBoolValue()
Creates an atomic boolean value.
BoolValue & getOrCreateNegation(BoolValue &Val)
Returns a boolean value that represents the negation of Val.
BoolValue & getOrCreateConjunction(BoolValue &LHS, BoolValue &RHS)
Returns a boolean value that represents the conjunction of LHS and RHS.
BoolValue & getOrCreateDisjunction(BoolValue &LHS, BoolValue &RHS)
Returns a boolean value that represents the disjunction of LHS and RHS.
BoolValue & getOrCreateIff(BoolValue &LHS, BoolValue &RHS)
Returns a boolean value that represents LHS <=> RHS.
const ControlFlowContext * getControlFlowContext(const FunctionDecl *F)
Returns the ControlFlowContext registered for F, if any.
Supplements Environment with non-standard comparison and join operations.
virtual ~ValueModel()=default
virtual ComparisonResult compare(QualType Type, const Value &Val1, const Environment &Env1, const Value &Val2, const Environment &Env2)
Returns: Same: Val1 is equivalent to Val2, according to the model.
virtual Value * widen(QualType Type, Value &Prev, const Environment &PrevEnv, Value &Current, Environment &CurrentEnv)
This function may widen the current value – replace it with an approximation that can reach a fixed p...
virtual bool merge(QualType Type, const Value &Val1, const Environment &Env1, const Value &Val2, const Environment &Env2, Value &MergedVal, Environment &MergedEnv)
Modifies MergedVal to approximate both Val1 and Val2.
Holds the state of the program (store and heap) at a given program point.
StorageLocation * getStorageLocation(const ValueDecl &D, SkipPast SP) const
Returns the storage location assigned to D in the environment, applying the SP policy for skipping pa...
const ControlFlowContext * getControlFlowContext(const FunctionDecl *F)
Returns the ControlFlowContext registered for F, if any.
std::enable_if_t< std::is_base_of< StorageLocation, T >::value, T & > takeOwnership(std::unique_ptr< T > Loc)
Transfers ownership of Loc to the analysis context and returns a reference to it.
PointerValue & getOrCreateNullPointerValue(QualType PointeeType)
Returns a pointer value that represents a null pointer.
BoolValue & makeAnd(BoolValue &LHS, BoolValue &RHS) const
Returns a boolean value that represents the conjunction of LHS and RHS.
std::enable_if_t< std::is_base_of< Value, T >::value, T & > takeOwnership(std::unique_ptr< T > Val)
Transfers ownership of Val to the analysis context and returns a reference to it.
LatticeJoinEffect widen(const Environment &PrevEnv, Environment::ValueModel &Model)
Widens the environment point-wise, using PrevEnv as needed to inform the approximation.
BoolValue & makeIff(BoolValue &LHS, BoolValue &RHS) const
Returns a boolean value represents LHS <=> RHS.
void addToFlowCondition(BoolValue &Val)
Adds Val to the set of clauses that constitute the flow condition.
BoolValue & buildAndSubstituteFlowCondition(AtomicBoolValue &Token, llvm::DenseMap< AtomicBoolValue *, BoolValue * > Substitutions)
Builds and returns the logical formula defining the flow condition identified by Token.
Environment pushCall(const CallExpr *Call) const
Creates and returns an environment to use for an inline analysis of the callee.
LLVM_DUMP_METHOD void dump() const
Environment(Environment &&Other)=default
StorageLocation * getThisPointeeStorageLocation() const
Returns the storage location assigned to the this pointee in the environment or null if the this poin...
BoolValue & makeTopBoolValue() const
Returns a unique instance of boolean Top.
StorageLocation & createStorageLocation(QualType Type)
Creates a storage location appropriate for Type.
bool equivalentTo(const Environment &Other, Environment::ValueModel &Model) const
Returns true if and only if the environment is equivalent to Other, i.e the two environments:
BoolValue & makeAtomicBoolValue() const
Returns an atomic boolean value.
Value * getValue(const StorageLocation &Loc) const
Returns the value assigned to Loc in the environment or null if Loc isn't assigned a value in the env...
bool canDescend(unsigned MaxDepth, const DeclContext *Callee) const
Returns whether this Environment can be extended to analyze the given Callee (i.e.
void setStorageLocation(const ValueDecl &D, StorageLocation &Loc)
Assigns Loc as the storage location of D in the environment.
Value * createValue(QualType Type)
Creates a value appropriate for Type, if Type is supported, otherwise return null.
void popCall(const Environment &CalleeEnv)
Moves gathered information back into this from a CalleeEnv created via pushCall.
void setValue(const StorageLocation &Loc, Value &Val)
Assigns Val as the value of Loc in the environment.
Environment & operator=(Environment &&Other)=default
BoolValue & makeNot(BoolValue &Val) const
Returns a boolean value that represents the negation of Val.
const DeclContext * getDeclCtx() const
Returns the DeclContext of the block being analysed, if any.
AtomicBoolValue & getFlowConditionToken() const
Returns the token that identifies the flow condition of the environment.
BoolValue & makeOr(BoolValue &LHS, BoolValue &RHS) const
Returns a boolean value that represents the disjunction of LHS and RHS.
LatticeJoinEffect join(const Environment &Other, Environment::ValueModel &Model)
Joins the environment with Other by taking the intersection of storage locations and values that are ...
bool flowConditionImplies(BoolValue &Val) const
Returns true if and only if the clauses that constitute the flow condition imply that Val is true.
StorageLocation * getReturnStorageLocation() const
Returns the storage location of the return value or null, if unset.
AtomicBoolValue & getBoolLiteralValue(bool Value) const
Returns a symbolic boolean value that models a boolean literal equal to Value
const DataflowAnalysisContext::Options & getAnalysisOptions() const
Environment & operator=(const Environment &Other)
BoolValue & makeImplication(BoolValue &LHS, BoolValue &RHS) const
Returns a boolean value represents LHS => RHS.
A logger is notified as the analysis progresses.
Models a symbolic pointer. Specifically, any value of type T*.
Base class for elements of the local variable store and of the heap.
Base class for all values computed by abstract interpretation.
ComparisonResult
Indicates the result of a tentative comparison.
LatticeJoinEffect
Effect indicating whether a lattice join operation resulted in a new value.
SkipPast
Indicates what kind of indirections should be skipped past when retrieving storage locations or value...
@ ReferenceThenPointer
An optional reference should be skipped past, then an optional pointer should be skipped past.
@ Reference
An optional reference should be skipped past.
@ None
No indirections should be skipped past.
Logger * Log
If provided, analysis details will be recorded here.