clang 17.0.0git
|
Owns objects that encompass the state of a program and stores context that is used during dataflow analysis. More...
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
Classes | |
struct | Options |
Public Member Functions | |
DataflowAnalysisContext (std::unique_ptr< Solver > S, Options Opts=Options{ std::nullopt}) | |
Constructs a dataflow analysis context. | |
template<typename T > | |
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. | |
template<typename T > | |
std::enable_if_t< std::is_base_of< Value, T >::value, T & > | takeOwnership (std::unique_ptr< T > Val) |
Takes ownership of Val and returns a reference to it. | |
StorageLocation & | createStorageLocation (QualType Type) |
Returns a new storage location appropriate for Type . | |
StorageLocation & | getStableStorageLocation (const VarDecl &D) |
Returns a stable storage location for D . | |
StorageLocation & | getStableStorageLocation (const Expr &E) |
Returns a stable storage location for E . | |
void | setStorageLocation (const ValueDecl &D, StorageLocation &Loc) |
Assigns Loc as the storage location of D . | |
StorageLocation * | getStorageLocation (const ValueDecl &D) const |
Returns the storage location assigned to D or null if D has no assigned storage location. | |
void | setStorageLocation (const Expr &E, StorageLocation &Loc) |
Assigns Loc as the storage location of E . | |
StorageLocation * | getStorageLocation (const Expr &E) const |
Returns the storage location assigned to E or null if E has no assigned storage location. | |
PointerValue & | getOrCreateNullPointerValue (QualType PointeeType) |
Returns a pointer value that represents a null pointer. | |
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. | |
TopBoolValue & | createTopBoolValue () |
Creates a Top value for booleans. | |
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 & | getOrCreateNegation (BoolValue &Val) |
Returns a boolean value that represents the negation of Val . | |
BoolValue & | getOrCreateImplication (BoolValue &LHS, BoolValue &RHS) |
Returns a boolean value that represents LHS => RHS . | |
BoolValue & | getOrCreateIff (BoolValue &LHS, BoolValue &RHS) |
Returns a boolean value that represents LHS <=> RHS . | |
AtomicBoolValue & | makeFlowConditionToken () |
Creates a fresh flow condition and returns a token that identifies it. | |
void | addFlowConditionConstraint (AtomicBoolValue &Token, BoolValue &Constraint) |
Adds Constraint to the flow condition identified by Token . | |
AtomicBoolValue & | forkFlowCondition (AtomicBoolValue &Token) |
Creates a new flow condition with the same constraints as the flow condition identified by Token and returns its token. | |
AtomicBoolValue & | joinFlowConditions (AtomicBoolValue &FirstToken, AtomicBoolValue &SecondToken) |
Creates a new flow condition that represents the disjunction of the flow conditions identified by FirstToken and SecondToken , and returns its token. | |
BoolValue & | buildAndSubstituteFlowCondition (AtomicBoolValue &Token, llvm::DenseMap< AtomicBoolValue *, BoolValue * > Substitutions) |
Builds and returns the logical formula defining the flow condition identified by Token . | |
bool | flowConditionImplies (AtomicBoolValue &Token, BoolValue &Val) |
Returns true if and only if the constraints of the flow condition identified by Token imply that Val is true. | |
bool | flowConditionIsTautology (AtomicBoolValue &Token) |
Returns true if and only if the constraints of the flow condition identified by Token are always true. | |
bool | equivalentBoolValues (BoolValue &Val1, BoolValue &Val2) |
Returns true if Val1 is equivalent to Val2 . | |
LLVM_DUMP_METHOD void | dumpFlowCondition (AtomicBoolValue &Token) |
const ControlFlowContext * | getControlFlowContext (const FunctionDecl *F) |
Returns the ControlFlowContext registered for F , if any. | |
const Options & | getOptions () |
Friends | |
class | Environment |
Owns objects that encompass the state of a program and stores context that is used during dataflow analysis.
Definition at line 62 of file DataflowAnalysisContext.h.
|
inline |
Constructs a dataflow analysis context.
Requirements:
S
must not be null.
Definition at line 77 of file DataflowAnalysisContext.h.
void clang::dataflow::DataflowAnalysisContext::addFlowConditionConstraint | ( | AtomicBoolValue & | Token, |
BoolValue & | Constraint | ||
) |
Adds Constraint
to the flow condition identified by Token
.
Definition at line 162 of file DataflowAnalysisContext.cpp.
References getOrCreateConjunction().
Referenced by clang::dataflow::Environment::addToFlowCondition(), forkFlowCondition(), and joinFlowConditions().
BoolValue & clang::dataflow::DataflowAnalysisContext::buildAndSubstituteFlowCondition | ( | AtomicBoolValue & | Token, |
llvm::DenseMap< AtomicBoolValue *, BoolValue * > | Substitutions | ||
) |
Builds and returns the logical formula defining the flow condition identified by Token
.
If a value in the formula is present as a key in Substitutions
, it will be substituted with the value it maps to. As an example, say we have flow condition tokens FC1, FC2, FC3 and FlowConditionConstraints: { FC1: C1, FC2: C2, FC3: (FC1 v FC2) ^ C3 } buildAndSubstituteFlowCondition(FC3, {{C1 -> C1'}}) will return a value corresponding to (C1' v C2) ^ C3.
Definition at line 316 of file DataflowAnalysisContext.cpp.
References getBoolLiteralValue().
Referenced by clang::dataflow::Environment::buildAndSubstituteFlowCondition().
|
inline |
Creates an atomic boolean value.
Definition at line 169 of file DataflowAnalysisContext.h.
References takeOwnership().
Referenced by clang::dataflow::Environment::makeAtomicBoolValue(), and makeFlowConditionToken().
StorageLocation & clang::dataflow::DataflowAnalysisContext::createStorageLocation | ( | QualType | Type | ) |
Returns a new storage location appropriate for Type
.
A null Type
is interpreted as the pointee type of std::nullptr_t
.
Definition at line 40 of file DataflowAnalysisContext.cpp.
References clang::dataflow::DataflowAnalysisContext::Options::ContextSensitiveOpts, createStorageLocation(), clang::dataflow::getObjectFields(), clang::Type::isStructureOrClassType(), clang::Type::isUnionType(), and takeOwnership().
Referenced by createStorageLocation(), clang::dataflow::Environment::createStorageLocation(), getOrCreateNullPointerValue(), and getStableStorageLocation().
|
inline |
Creates a Top value for booleans.
Each instance is unique and can be assigned a distinct truth value during solving.
FIXME: Top iff Top
is true when both Tops are identical (by pointer equality), but not when they are distinct values. We should improve the implementation so that Top iff Top
has a consistent meaning, regardless of the identity of Top
. Moreover, I think the meaning should be false
.
Definition at line 181 of file DataflowAnalysisContext.h.
References takeOwnership().
Referenced by clang::dataflow::Environment::makeTopBoolValue().
void clang::dataflow::DataflowAnalysisContext::dumpFlowCondition | ( | AtomicBoolValue & | Token | ) |
Definition at line 346 of file DataflowAnalysisContext.cpp.
References clang::dataflow::debugString(), and getBoolLiteralValue().
Referenced by clang::dataflow::Environment::dump().
bool clang::dataflow::DataflowAnalysisContext::equivalentBoolValues | ( | BoolValue & | Val1, |
BoolValue & | Val2 | ||
) |
Returns true if Val1
is equivalent to Val2
.
Note: This function doesn't take into account constraints on Val1
and Val2
imposed by the flow condition.
Definition at line 218 of file DataflowAnalysisContext.cpp.
References getOrCreateIff(), and getOrCreateNegation().
bool clang::dataflow::DataflowAnalysisContext::flowConditionImplies | ( | AtomicBoolValue & | Token, |
BoolValue & | Val | ||
) |
Returns true if and only if the constraints of the flow condition identified by Token
imply that Val
is true.
Definition at line 196 of file DataflowAnalysisContext.cpp.
References getOrCreateNegation().
Referenced by clang::dataflow::Environment::flowConditionImplies().
bool clang::dataflow::DataflowAnalysisContext::flowConditionIsTautology | ( | AtomicBoolValue & | Token | ) |
Returns true if and only if the constraints of the flow condition identified by Token
are always true.
Definition at line 209 of file DataflowAnalysisContext.cpp.
References getOrCreateNegation().
AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::forkFlowCondition | ( | AtomicBoolValue & | Token | ) |
Creates a new flow condition with the same constraints as the flow condition identified by Token
and returns its token.
Definition at line 171 of file DataflowAnalysisContext.cpp.
References addFlowConditionConstraint(), and makeFlowConditionToken().
|
inline |
Returns a symbolic boolean value that models a boolean literal equal to Value
.
Definition at line 164 of file DataflowAnalysisContext.h.
Referenced by buildAndSubstituteFlowCondition(), dumpFlowCondition(), clang::dataflow::Environment::getBoolLiteralValue(), getOrCreateIff(), and getOrCreateImplication().
const ControlFlowContext * clang::dataflow::DataflowAnalysisContext::getControlFlowContext | ( | const FunctionDecl * | F | ) |
Returns the ControlFlowContext
registered for F
, if any.
Otherwise, returns null.
Definition at line 358 of file DataflowAnalysisContext.cpp.
References clang::dataflow::ControlFlowContext::build(), clang::Decl::getASTContext(), clang::FunctionDecl::getBody(), clang::FunctionDecl::getDefinition(), and clang::Result.
Referenced by clang::dataflow::Environment::getControlFlowContext().
|
inline |
Definition at line 273 of file DataflowAnalysisContext.h.
Referenced by clang::dataflow::Environment::getAnalysisOptions().
BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateConjunction | ( | BoolValue & | LHS, |
BoolValue & | RHS | ||
) |
Returns a boolean value that represents the conjunction of LHS
and RHS
.
Subsequent calls with the same arguments, regardless of their order, will return the same result. If the given boolean values represent the same value, the result will be the value itself.
Definition at line 100 of file DataflowAnalysisContext.cpp.
References clang::dataflow::makeCanonicalBoolValuePair(), and takeOwnership().
Referenced by addFlowConditionConstraint(), and clang::dataflow::Environment::makeAnd().
BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateDisjunction | ( | BoolValue & | LHS, |
BoolValue & | RHS | ||
) |
Returns a boolean value that represents the disjunction of LHS
and RHS
.
Subsequent calls with the same arguments, regardless of their order, will return the same result. If the given boolean values represent the same value, the result will be the value itself.
Definition at line 113 of file DataflowAnalysisContext.cpp.
References clang::dataflow::makeCanonicalBoolValuePair(), and takeOwnership().
Referenced by joinFlowConditions(), and clang::dataflow::Environment::makeOr().
BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateIff | ( | BoolValue & | LHS, |
BoolValue & | RHS | ||
) |
Returns a boolean value that represents LHS <=> RHS
.
Subsequent calls with the same arguments, regardless of their order, will return the same result. If the given boolean values represent the same value, the result will be a value that represents the true boolean literal.
Definition at line 145 of file DataflowAnalysisContext.cpp.
References getBoolLiteralValue(), clang::dataflow::makeCanonicalBoolValuePair(), and takeOwnership().
Referenced by equivalentBoolValues(), and clang::dataflow::Environment::makeIff().
BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateImplication | ( | BoolValue & | LHS, |
BoolValue & | RHS | ||
) |
Returns a boolean value that represents LHS => RHS
.
Subsequent calls with the same arguments, will return the same result. If the given boolean values represent the same value, the result will be a value that represents the true boolean literal.
Definition at line 133 of file DataflowAnalysisContext.cpp.
References getBoolLiteralValue(), and takeOwnership().
Referenced by clang::dataflow::Environment::makeImplication().
Returns a boolean value that represents the negation of Val
.
Subsequent calls with the same argument will return the same result.
Definition at line 126 of file DataflowAnalysisContext.cpp.
References takeOwnership().
Referenced by equivalentBoolValues(), flowConditionImplies(), flowConditionIsTautology(), and clang::dataflow::Environment::makeNot().
PointerValue & clang::dataflow::DataflowAnalysisContext::getOrCreateNullPointerValue | ( | QualType | PointeeType | ) |
Returns a pointer value that represents a null pointer.
Calls with PointeeType
that are canonically equivalent will return the same result. A null PointeeType
can be used for the pointee of std::nullptr_t
.
Definition at line 80 of file DataflowAnalysisContext.cpp.
References createStorageLocation(), clang::QualType::getCanonicalType(), clang::QualType::isNull(), and takeOwnership().
Referenced by clang::dataflow::Environment::getOrCreateNullPointerValue().
StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation | ( | const Expr & | E | ) |
Returns a stable storage location for E
.
Definition at line 71 of file DataflowAnalysisContext.cpp.
References createStorageLocation(), getStorageLocation(), clang::Expr::getType(), and setStorageLocation().
StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation | ( | const VarDecl & | D | ) |
Returns a stable storage location for D
.
Definition at line 62 of file DataflowAnalysisContext.cpp.
References createStorageLocation(), getStorageLocation(), clang::ValueDecl::getType(), and setStorageLocation().
Referenced by clang::dataflow::Environment::createStorageLocation().
|
inline |
Returns the storage location assigned to E
or null if E
has no assigned storage location.
Definition at line 152 of file DataflowAnalysisContext.h.
References clang::dataflow::ignoreCFGOmittedNodes().
|
inline |
Returns the storage location assigned to D
or null if D
has no assigned storage location.
Definition at line 134 of file DataflowAnalysisContext.h.
Referenced by getStableStorageLocation().
AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::joinFlowConditions | ( | AtomicBoolValue & | FirstToken, |
AtomicBoolValue & | SecondToken | ||
) |
Creates a new flow condition that represents the disjunction of the flow conditions identified by FirstToken
and SecondToken
, and returns its token.
Definition at line 179 of file DataflowAnalysisContext.cpp.
References addFlowConditionConstraint(), getOrCreateDisjunction(), and makeFlowConditionToken().
Referenced by clang::dataflow::Environment::join().
AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::makeFlowConditionToken | ( | ) |
Creates a fresh flow condition and returns a token that identifies it.
The token can be used to perform various operations on the flow condition such as adding constraints to it, forking it, joining it with another flow condition, or checking implications.
Definition at line 158 of file DataflowAnalysisContext.cpp.
References createAtomicBoolValue().
Referenced by forkFlowCondition(), and joinFlowConditions().
|
inline |
Assigns Loc
as the storage location of E
.
Requirements:
E
must not be assigned a storage location.
Definition at line 144 of file DataflowAnalysisContext.h.
References clang::dataflow::ignoreCFGOmittedNodes().
|
inline |
Assigns Loc
as the storage location of D
.
Requirements:
D
must not be assigned a storage location.
Definition at line 127 of file DataflowAnalysisContext.h.
Referenced by getStableStorageLocation().
|
inline |
Takes ownership of Loc
and returns a reference to it.
Requirements:
Loc
must not be null.
Definition at line 92 of file DataflowAnalysisContext.h.
Referenced by createAtomicBoolValue(), createStorageLocation(), createTopBoolValue(), getOrCreateConjunction(), getOrCreateDisjunction(), getOrCreateIff(), getOrCreateImplication(), getOrCreateNegation(), getOrCreateNullPointerValue(), and clang::dataflow::Environment::takeOwnership().
|
inline |
Takes ownership of Val
and returns a reference to it.
Requirements:
Val
must not be null.
Definition at line 105 of file DataflowAnalysisContext.h.
|
friend |
Definition at line 276 of file DataflowAnalysisContext.h.