clang 22.0.0git
clang::dataflow::DataflowAnalysisContext Class Reference

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.
StorageLocationcreateStorageLocation (QualType Type)
 Returns a new storage location appropriate for Type.
RecordStorageLocationcreateRecordStorageLocation (QualType Type, RecordStorageLocation::FieldToLoc FieldLocs, RecordStorageLocation::SyntheticFieldMap SyntheticFields)
 Creates a RecordStorageLocation for the given type and with the given fields.
StorageLocationgetStableStorageLocation (const ValueDecl &D)
 Returns a stable storage location for D.
StorageLocationgetStableStorageLocation (const Expr &E)
 Returns a stable storage location for E.
PointerValuegetOrCreateNullPointerValue (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 AdornedCFGgetAdornedCFG (const FunctionDecl *F)
 Returns the AdornedCFG registered for F, if any.
const OptionsgetOptions ()
Arenaarena ()
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< QualTypegetSyntheticFields (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

Detailed Description

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.

Constructor & Destructor Documentation

◆ DataflowAnalysisContext() [1/2]

clang::dataflow::DataflowAnalysisContext::DataflowAnalysisContext ( std::unique_ptr< Solver > S,
Options Opts = Options{ std::nullopt, nullptr} )
inline

Constructs a dataflow analysis context.

Requirements:

S must not be null.

Definition at line 79 of file DataflowAnalysisContext.h.

◆ DataflowAnalysisContext() [2/2]

clang::dataflow::DataflowAnalysisContext::DataflowAnalysisContext ( Solver & S,
Options Opts = Options{ std::nullopt, nullptr} )
inline

Constructs a dataflow analysis context.

Requirements:

S must outlive the DataflowAnalysisContext.

Definition at line 90 of file DataflowAnalysisContext.h.

◆ ~DataflowAnalysisContext()

clang::dataflow::DataflowAnalysisContext::~DataflowAnalysisContext ( )
default

Member Function Documentation

◆ addFlowConditionConstraint()

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().

◆ addFlowConditionDeps()

void clang::dataflow::DataflowAnalysisContext::addFlowConditionDeps ( Atom Token,
const llvm::DenseSet< Atom > & Deps )
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.

◆ addInvariant()

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().

◆ arena()

◆ createRecordStorageLocation()

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().

◆ createStorageLocation()

StorageLocation & clang::dataflow::DataflowAnalysisContext::createStorageLocation ( QualType Type)

◆ dumpFlowCondition()

◆ equivalentFormulas()

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().

◆ exportLogicalContext()

SimpleLogicalContext clang::dataflow::DataflowAnalysisContext::exportLogicalContext ( llvm::DenseSet< dataflow::Atom > TargetTokens) const

◆ flowConditionAllows()

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().

◆ flowConditionImplies()

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().

◆ forkFlowCondition()

Atom clang::dataflow::DataflowAnalysisContext::forkFlowCondition ( Atom Token)

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().

◆ getAdornedCFG()

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.

◆ getModeledFields()

FieldSet clang::dataflow::DataflowAnalysisContext::getModeledFields ( QualType Type)

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().

◆ getOptions()

const Options & clang::dataflow::DataflowAnalysisContext::getOptions ( )
inline

Definition at line 197 of file DataflowAnalysisContext.h.

◆ getOrCreateNullPointerValue()

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().

◆ getStableStorageLocation() [1/2]

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().

◆ getStableStorageLocation() [2/2]

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().

◆ getSyntheticFields()

llvm::StringMap< QualType > clang::dataflow::DataflowAnalysisContext::getSyntheticFields ( QualType Type)
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().

◆ initLogicalContext()

void clang::dataflow::DataflowAnalysisContext::initLogicalContext ( SimpleLogicalContext LC)

◆ joinFlowConditions()

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().

◆ querySolver()

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.

◆ setSyntheticFieldCallback()

void clang::dataflow::DataflowAnalysisContext::setSyntheticFieldCallback ( std::function< llvm::StringMap< QualType >(QualType)> CB)
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.

◆ Environment

friend class Environment
friend

Definition at line 240 of file DataflowAnalysisContext.h.

References Environment.

Referenced by Environment.


The documentation for this class was generated from the following files: