clang 22.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. | |
void | addFlowConditionDeps (Atom Token, const llvm::DenseSet< Atom > &Deps) |
Adds Deps to the dependencies of 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. | |
SimpleLogicalContext | exportLogicalContext (llvm::DenseSet< dataflow::Atom > TargetTokens) const |
Export the logical-context portions of AC, limited to the given target flow-condition tokens. | |
void | initLogicalContext (SimpleLogicalContext LC) |
Initializes this context's "logical" components with LC. |
Friends | |
class | Environment |
Owns objects that encompass the state of a program and stores context that is used during dataflow analysis.
Definition at line 59 of file DataflowAnalysisContext.h.
|
inline |
Constructs a dataflow analysis context.
Requirements:
S must not be null.
Definition at line 79 of file DataflowAnalysisContext.h.
|
inline |
Constructs a dataflow analysis context.
Requirements:
S must outlive the DataflowAnalysisContext.
Definition at line 90 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 141 of file DataflowAnalysisContext.cpp.
References arena(), and clang::dataflow::Arena::makeAnd().
Referenced by forkFlowCondition(), and joinFlowConditions().
|
inline |
Adds Deps to the dependencies of the flow condition identified by Token.
Intended for use in deserializing contexts. The formula alone doesn't have enough information to indicate its deps.
Definition at line 158 of file DataflowAnalysisContext.h.
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 134 of file DataflowAnalysisContext.cpp.
References arena(), clang::Invariant, and clang::dataflow::Arena::makeAnd().
|
inline |
Definition at line 199 of file DataflowAnalysisContext.h.
Referenced by addFlowConditionConstraint(), addInvariant(), createRecordStorageLocation(), createStorageLocation(), dumpFlowCondition(), equivalentFormulas(), flowConditionAllows(), flowConditionImplies(), forkFlowCondition(), getOrCreateNullPointerValue(), joinFlowConditions(), 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 90 of file DataflowAnalysisContext.cpp.
References arena(), clang::dataflow::containsSameFields(), clang::dataflow::Arena::create(), clang::dataflow::getKeys(), getModeledFields(), getSyntheticFields(), 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 61 of file DataflowAnalysisContext.cpp.
References arena(), clang::dataflow::Arena::create(), createRecordStorageLocation(), createStorageLocation(), getModeledFields(), getSyntheticFields(), and clang::Type::isRecordType().
Referenced by createStorageLocation(), getOrCreateNullPointerValue(), getStableStorageLocation(), and getStableStorageLocation().
void clang::dataflow::DataflowAnalysisContext::dumpFlowCondition | ( | Atom | Token, |
llvm::raw_ostream & | OS = llvm::dbgs() ) |
Definition at line 332 of file DataflowAnalysisContext.cpp.
References arena(), clang::Class, clang::dataflow::SimplifyConstraintsInfo::EquivalentAtoms, clang::dataflow::SimplifyConstraintsInfo::FalseAtoms, clang::dataflow::printAtomList(), clang::dataflow::simplifyConstraints(), and clang::dataflow::SimplifyConstraintsInfo::TrueAtoms.
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 204 of file DataflowAnalysisContext.cpp.
References arena().
SimpleLogicalContext clang::dataflow::DataflowAnalysisContext::exportLogicalContext | ( | llvm::DenseSet< dataflow::Atom > | TargetTokens | ) | const |
Export the logical-context portions of AC, limited to the given target flow-condition tokens.
Definition at line 284 of file DataflowAnalysisContext.cpp.
References clang::dataflow::getReferencedAtoms(), clang::dataflow::SimpleLogicalContext::Invariant, clang::Invariant, clang::dataflow::SimpleLogicalContext::TokenDefs, and clang::dataflow::SimpleLogicalContext::TokenDeps.
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 192 of file DataflowAnalysisContext.cpp.
References arena(), and clang::dataflow::Formula::isLiteral().
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 175 of file DataflowAnalysisContext.cpp.
References arena(), and clang::dataflow::Formula::isLiteral().
Creates a new flow condition with the same constraints as the flow condition identified by Token and returns its token.
Definition at line 150 of file DataflowAnalysisContext.cpp.
References addFlowConditionConstraint(), arena(), and clang::dataflow::Arena::makeFlowConditionToken().
const AdornedCFG * clang::dataflow::DataflowAnalysisContext::getAdornedCFG | ( | const FunctionDecl * | F | ) |
Returns the AdornedCFG registered for F, if any.
Otherwise, returns null.
Definition at line 371 of file DataflowAnalysisContext.cpp.
References clang::dataflow::AdornedCFG::build(), 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 43 of file DataflowAnalysisContext.cpp.
References clang::dataflow::getObjectFields().
Referenced by clang::dataflow::copyRecord(), createRecordStorageLocation(), and createStorageLocation().
|
inline |
Definition at line 197 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 123 of file DataflowAnalysisContext.cpp.
References arena(), clang::dataflow::Arena::create(), createStorageLocation(), clang::QualType::getCanonicalType(), and clang::QualType::isNull().
StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation | ( | const Expr & | E | ) |
Returns a stable storage location for E.
Definition at line 112 of file DataflowAnalysisContext.cpp.
References createStorageLocation(), clang::Expr::getType(), and clang::dataflow::ignoreCFGOmittedNodes().
StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation | ( | const ValueDecl & | D | ) |
Returns a stable storage location for D.
Definition at line 103 of file DataflowAnalysisContext.cpp.
References createStorageLocation(), clang::QualType::getNonReferenceType(), and clang::ValueDecl::getType().
|
inline |
Returns the names and types of the synthetic fields for the given record type.
Definition at line 215 of file DataflowAnalysisContext.h.
References clang::Type::isRecordType(), and clang::Result.
Referenced by clang::dataflow::copyRecord(), createRecordStorageLocation(), and createStorageLocation().
void clang::dataflow::DataflowAnalysisContext::initLogicalContext | ( | SimpleLogicalContext | LC | ) |
Initializes this context's "logical" components with LC.
Definition at line 312 of file DataflowAnalysisContext.cpp.
References clang::dataflow::SimpleLogicalContext::Invariant, clang::Invariant, clang::dataflow::SimpleLogicalContext::TokenDefs, and clang::dataflow::SimpleLogicalContext::TokenDeps.
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 158 of file DataflowAnalysisContext.cpp.
References addFlowConditionConstraint(), arena(), and clang::dataflow::Arena::makeFlowConditionToken().
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 170 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 RecordStorageLocations of a given type have the same fields:
Definition at line 108 of file DataflowAnalysisContext.h.
References std::function.
|
friend |
Definition at line 240 of file DataflowAnalysisContext.h.
References Environment.
Referenced by Environment.