clang 18.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 ()
 
StorageLocationcreateStorageLocation (QualType Type)
 Returns a new storage location appropriate for Type.
 
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 ControlFlowContextgetControlFlowContext (const FunctionDecl *F)
 Returns the ControlFlowContext 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.
 

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

Constructor & Destructor Documentation

◆ DataflowAnalysisContext()

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

Constructs a dataflow analysis context.

Requirements:

S must not be null.

Definition at line 307 of file DataflowAnalysisContext.cpp.

References DataflowLog(), clang::dataflow::DataflowAnalysisContext::Options::Log, clang::dataflow::makeLoggerFromCommandLine(), and clang::dataflow::Logger::null().

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

References arena(), and clang::dataflow::Arena::makeAnd().

Referenced by clang::dataflow::Environment::assume(), forkFlowCondition(), and joinFlowConditions().

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

References arena(), and clang::dataflow::Arena::makeAnd().

◆ arena()

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

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

References arena(), clang::dataflow::Arena::create(), createStorageLocation(), getModeledFields(), and clang::Type::isRecordType().

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

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

References arena().

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

References arena().

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

References arena().

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

References addFlowConditionConstraint(), arena(), and clang::dataflow::Arena::makeFlowConditionToken().

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

◆ getControlFlowContext()

const ControlFlowContext * clang::dataflow::DataflowAnalysisContext::getControlFlowContext ( const FunctionDecl F)

Returns the ControlFlowContext registered for F, if any.

Otherwise, returns null.

Definition at line 259 of file DataflowAnalysisContext.cpp.

References clang::dataflow::ControlFlowContext::build(), CFCtx, clang::FunctionDecl::getDefinition(), clang::FunctionDecl::hasBody(), 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 44 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 156 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 97 of file DataflowAnalysisContext.cpp.

References arena(), clang::dataflow::Arena::create(), createStorageLocation(), 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 86 of file DataflowAnalysisContext.cpp.

References createStorageLocation(), clang::Expr::getType(), and clang::dataflow::ignoreCFGOmittedNodes().

◆ getStableStorageLocation() [2/2]

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

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

Friends And Related Function Documentation

◆ Environment

friend class Environment
friend

Definition at line 173 of file DataflowAnalysisContext.h.


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