clang 20.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, nullptr}) | |
Constructs a dataflow analysis context. | |
DataflowAnalysisContext (Solver &S, Options Opts=Options{ std::nullopt, nullptr}) | |
Constructs a dataflow analysis context. | |
~DataflowAnalysisContext () | |
void | setSyntheticFieldCallback (std::function< llvm::StringMap< QualType >(QualType)> CB) |
Sets a callback that returns the names and types of the synthetic fields to add to a RecordStorageLocation of a given type. | |
StorageLocation & | createStorageLocation (QualType Type) |
Returns a new storage location appropriate for Type . | |
RecordStorageLocation & | createRecordStorageLocation (QualType Type, RecordStorageLocation::FieldToLoc FieldLocs, RecordStorageLocation::SyntheticFieldMap SyntheticFields) |
Creates a RecordStorageLocation for the given type and with the given fields. | |
StorageLocation & | getStableStorageLocation (const ValueDecl &D) |
Returns a stable storage location for D . | |
StorageLocation & | getStableStorageLocation (const Expr &E) |
Returns a stable storage location for E . | |
PointerValue & | getOrCreateNullPointerValue (QualType PointeeType) |
Returns a pointer value that represents a null pointer. | |
void | addInvariant (const Formula &Constraint) |
Adds Constraint to current and future flow conditions in this context. | |
void | addFlowConditionConstraint (Atom Token, const Formula &Constraint) |
Adds Constraint to the flow condition identified by Token . | |
Atom | forkFlowCondition (Atom Token) |
Creates a new flow condition with the same constraints as the flow condition identified by Token and returns its token. | |
Atom | joinFlowConditions (Atom FirstToken, Atom SecondToken) |
Creates a new flow condition that represents the disjunction of the flow conditions identified by FirstToken and SecondToken , and returns its token. | |
bool | flowConditionImplies (Atom Token, const Formula &F) |
Returns true if the constraints of the flow condition identified by Token imply that F is true. | |
bool | flowConditionAllows (Atom Token, const Formula &F) |
Returns true if the constraints of the flow condition identified by Token still allow F to be true. | |
bool | equivalentFormulas (const Formula &Val1, const Formula &Val2) |
Returns true if Val1 is equivalent to Val2 . | |
LLVM_DUMP_METHOD void | dumpFlowCondition (Atom Token, llvm::raw_ostream &OS=llvm::dbgs()) |
const AdornedCFG * | getAdornedCFG (const FunctionDecl *F) |
Returns the AdornedCFG registered for F , if any. | |
const Options & | getOptions () |
Arena & | arena () |
Solver::Result | querySolver (llvm::SetVector< const Formula * > Constraints) |
Returns the outcome of satisfiability checking on Constraints . | |
FieldSet | getModeledFields (QualType Type) |
Returns the fields of Type , limited to the set of fields modeled by this context. | |
llvm::StringMap< QualType > | getSyntheticFields (QualType Type) |
Returns the names and types of the synthetic fields for the given record type. | |
Friends | |
class | Environment |
Owns objects that encompass the state of a program and stores context that is used during dataflow analysis.
Definition at line 47 of file DataflowAnalysisContext.h.
|
inline |
Constructs a dataflow analysis context.
Requirements:
S
must not be null.
Definition at line 67 of file DataflowAnalysisContext.h.
|
inline |
Constructs a dataflow analysis context.
Requirements:
S
must outlive the DataflowAnalysisContext
.
Definition at line 78 of file DataflowAnalysisContext.h.
|
default |
void clang::dataflow::DataflowAnalysisContext::addFlowConditionConstraint | ( | Atom | Token, |
const Formula & | Constraint | ||
) |
Adds Constraint
to the flow condition identified by Token
.
Definition at line 143 of file DataflowAnalysisContext.cpp.
Referenced by clang::dataflow::Environment::assume().
void clang::dataflow::DataflowAnalysisContext::addInvariant | ( | const Formula & | Constraint | ) |
Adds Constraint
to current and future flow conditions in this context.
Invariants must contain only flow-insensitive information, i.e. facts that are true on all paths through the program. Information can be added eagerly (when analysis begins), or lazily (e.g. when values are first used). The analysis must be careful that the same information is added regardless of which order blocks are analyzed in.
Definition at line 136 of file DataflowAnalysisContext.cpp.
References clang::Invariant.
|
inline |
Definition at line 178 of file DataflowAnalysisContext.h.
Referenced by clang::dataflow::Environment::arena(), and clang::dataflow::unpackValue().
RecordStorageLocation & clang::dataflow::DataflowAnalysisContext::createRecordStorageLocation | ( | QualType | Type, |
RecordStorageLocation::FieldToLoc | FieldLocs, | ||
RecordStorageLocation::SyntheticFieldMap | SyntheticFields | ||
) |
Creates a RecordStorageLocation
for the given type and with the given fields.
Requirements:
FieldLocs
must contain exactly the fields returned by getModeledFields(Type)
. SyntheticFields
must contain exactly the fields returned by getSyntheticFields(Type)
.
Definition at line 92 of file DataflowAnalysisContext.cpp.
References clang::dataflow::containsSameFields(), clang::dataflow::getKeys(), and clang::Type::isRecordType().
Referenced by createStorageLocation().
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 63 of file DataflowAnalysisContext.cpp.
References createRecordStorageLocation(), createStorageLocation(), getModeledFields(), getSyntheticFields(), and clang::Type::isRecordType().
Referenced by createStorageLocation(), and clang::dataflow::Environment::createStorageLocation().
void clang::dataflow::DataflowAnalysisContext::dumpFlowCondition | ( | Atom | Token, |
llvm::raw_ostream & | OS = llvm::dbgs() |
||
) |
Definition at line 254 of file DataflowAnalysisContext.cpp.
References clang::Class, clang::dataflow::SimplifyConstraintsInfo::EquivalentAtoms, clang::dataflow::SimplifyConstraintsInfo::FalseAtoms, clang::dataflow::printAtomList(), clang::dataflow::simplifyConstraints(), and clang::dataflow::SimplifyConstraintsInfo::TrueAtoms.
Referenced by clang::dataflow::Environment::dump().
bool clang::dataflow::DataflowAnalysisContext::equivalentFormulas | ( | const Formula & | Val1, |
const Formula & | 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 205 of file DataflowAnalysisContext.cpp.
bool clang::dataflow::DataflowAnalysisContext::flowConditionAllows | ( | Atom | Token, |
const Formula & | F | ||
) |
Returns true if the constraints of the flow condition identified by Token
still allow F
to be true.
Returns false if the flow condition implies that F
is false or if the solver times out.
Definition at line 193 of file DataflowAnalysisContext.cpp.
References clang::dataflow::Formula::isLiteral().
Referenced by clang::dataflow::Environment::allows().
bool clang::dataflow::DataflowAnalysisContext::flowConditionImplies | ( | Atom | Token, |
const Formula & | F | ||
) |
Returns true if the constraints of the flow condition identified by Token
imply that F
is true.
Returns false if the flow condition does not imply F
or if the solver times out.
Definition at line 176 of file DataflowAnalysisContext.cpp.
References clang::dataflow::Formula::isLiteral().
Referenced by clang::dataflow::Environment::proves().
Creates a new flow condition with the same constraints as the flow condition identified by Token
and returns its token.
Definition at line 152 of file DataflowAnalysisContext.cpp.
Referenced by clang::dataflow::Environment::fork().
const AdornedCFG * clang::dataflow::DataflowAnalysisContext::getAdornedCFG | ( | const FunctionDecl * | F | ) |
Returns the AdornedCFG
registered for F
, if any.
Otherwise, returns null.
Definition at line 293 of file DataflowAnalysisContext.cpp.
References clang::FunctionDecl::doesThisDeclarationHaveABody(), clang::FunctionDecl::getDefinition(), and clang::Result.
Returns the fields of Type
, limited to the set of fields modeled by this context.
Definition at line 45 of file DataflowAnalysisContext.cpp.
References clang::dataflow::DataflowAnalysisContext::Options::ContextSensitiveOpts, and clang::dataflow::getObjectFields().
Referenced by createStorageLocation().
|
inline |
Definition at line 176 of file DataflowAnalysisContext.h.
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 125 of file DataflowAnalysisContext.cpp.
References clang::QualType::getCanonicalType(), and clang::QualType::isNull().
Referenced by clang::dataflow::Environment::getOrCreateNullPointerValue().
StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation | ( | const Expr & | E | ) |
Returns a stable storage location for E
.
Definition at line 114 of file DataflowAnalysisContext.cpp.
References E, clang::Expr::getType(), clang::dataflow::ignoreCFGOmittedNodes(), and Loc.
StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation | ( | const ValueDecl & | D | ) |
Returns a stable storage location for D
.
Definition at line 105 of file DataflowAnalysisContext.cpp.
Referenced by clang::dataflow::Environment::createStorageLocation(), and clang::dataflow::Environment::getResultObjectLocation().
|
inline |
Returns the names and types of the synthetic fields for the given record type.
Definition at line 194 of file DataflowAnalysisContext.h.
References clang::Type::isRecordType(), and clang::Result.
Referenced by createStorageLocation().
Atom clang::dataflow::DataflowAnalysisContext::joinFlowConditions | ( | Atom | FirstToken, |
Atom | 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 160 of file DataflowAnalysisContext.cpp.
Referenced by clang::dataflow::Environment::join().
Solver::Result clang::dataflow::DataflowAnalysisContext::querySolver | ( | llvm::SetVector< const Formula * > | Constraints | ) |
Returns the outcome of satisfiability checking on Constraints
.
Flow conditions are not incorporated, so they may need to be manually included in Constraints
to provide contextually-accurate results, e.g. if any definitions or relationships of the values in Constraints
have been stored in flow conditions.
Definition at line 171 of file DataflowAnalysisContext.cpp.
|
inline |
Sets a callback that returns the names and types of the synthetic fields to add to a RecordStorageLocation
of a given type.
Typically, this is called from the constructor of a DataflowAnalysis
The field types returned by the callback may not have reference type.
To maintain the invariant that all RecordStorageLocation
s of a given type have the same fields:
setSyntheticFieldCallback()
must be called before any Definition at line 96 of file DataflowAnalysisContext.h.
|
friend |
Definition at line 211 of file DataflowAnalysisContext.h.