clang 20.0.0git
Classes | Public Member Functions | Friends | List of all members
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.
 
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.
 

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 47 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 67 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 78 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 143 of file DataflowAnalysisContext.cpp.

Referenced by clang::dataflow::Environment::assume().

◆ 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 136 of file DataflowAnalysisContext.cpp.

References clang::Invariant.

◆ arena()

Arena & clang::dataflow::DataflowAnalysisContext::arena ( )
inline

◆ 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 92 of file DataflowAnalysisContext.cpp.

References clang::dataflow::containsSameFields(), clang::dataflow::getKeys(), and clang::Type::isRecordType().

Referenced by createStorageLocation().

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

◆ dumpFlowCondition()

void clang::dataflow::DataflowAnalysisContext::dumpFlowCondition ( Atom  Token,
llvm::raw_ostream &  OS = llvm::dbgs() 
)

◆ 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 205 of file DataflowAnalysisContext.cpp.

◆ 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 193 of file DataflowAnalysisContext.cpp.

References clang::dataflow::Formula::isLiteral().

Referenced by clang::dataflow::Environment::allows().

◆ 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 176 of file DataflowAnalysisContext.cpp.

References clang::dataflow::Formula::isLiteral().

Referenced by clang::dataflow::Environment::proves().

◆ 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 152 of file DataflowAnalysisContext.cpp.

Referenced by clang::dataflow::Environment::fork().

◆ getAdornedCFG()

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.

◆ 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 45 of file DataflowAnalysisContext.cpp.

References clang::dataflow::DataflowAnalysisContext::Options::ContextSensitiveOpts, and clang::dataflow::getObjectFields().

Referenced by createStorageLocation().

◆ getOptions()

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

Definition at line 176 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 125 of file DataflowAnalysisContext.cpp.

References clang::QualType::getCanonicalType(), and clang::QualType::isNull().

Referenced by clang::dataflow::Environment::getOrCreateNullPointerValue().

◆ getStableStorageLocation() [1/2]

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.

◆ getStableStorageLocation() [2/2]

StorageLocation & clang::dataflow::DataflowAnalysisContext::getStableStorageLocation ( const ValueDecl D)

Returns a stable storage location for D.

Definition at line 105 of file DataflowAnalysisContext.cpp.

References D, and Loc.

Referenced by clang::dataflow::Environment::createStorageLocation(), and clang::dataflow::Environment::getResultObjectLocation().

◆ 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 194 of file DataflowAnalysisContext.h.

References clang::Type::isRecordType(), and clang::Result.

Referenced by createStorageLocation().

◆ 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 160 of file DataflowAnalysisContext.cpp.

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 171 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 96 of file DataflowAnalysisContext.h.

Friends And Related Function Documentation

◆ Environment

friend class Environment
friend

Definition at line 211 of file DataflowAnalysisContext.h.


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