clang 17.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})
 Constructs a dataflow analysis context.
 
template<typename T >
std::enable_if_t< std::is_base_of< StorageLocation, T >::value, T & > takeOwnership (std::unique_ptr< T > Loc)
 Takes ownership of Loc and returns a reference to it.
 
template<typename T >
std::enable_if_t< std::is_base_of< Value, T >::value, T & > takeOwnership (std::unique_ptr< T > Val)
 Takes ownership of Val and returns a reference to it.
 
StorageLocationcreateStorageLocation (QualType Type)
 Returns a new storage location appropriate for Type.
 
StorageLocationgetStableStorageLocation (const VarDecl &D)
 Returns a stable storage location for D.
 
StorageLocationgetStableStorageLocation (const Expr &E)
 Returns a stable storage location for E.
 
void setStorageLocation (const ValueDecl &D, StorageLocation &Loc)
 Assigns Loc as the storage location of D.
 
StorageLocationgetStorageLocation (const ValueDecl &D) const
 Returns the storage location assigned to D or null if D has no assigned storage location.
 
void setStorageLocation (const Expr &E, StorageLocation &Loc)
 Assigns Loc as the storage location of E.
 
StorageLocationgetStorageLocation (const Expr &E) const
 Returns the storage location assigned to E or null if E has no assigned storage location.
 
PointerValuegetOrCreateNullPointerValue (QualType PointeeType)
 Returns a pointer value that represents a null pointer.
 
AtomicBoolValuegetBoolLiteralValue (bool Value) const
 Returns a symbolic boolean value that models a boolean literal equal to Value.
 
AtomicBoolValuecreateAtomicBoolValue ()
 Creates an atomic boolean value.
 
TopBoolValuecreateTopBoolValue ()
 Creates a Top value for booleans.
 
BoolValuegetOrCreateConjunction (BoolValue &LHS, BoolValue &RHS)
 Returns a boolean value that represents the conjunction of LHS and RHS.
 
BoolValuegetOrCreateDisjunction (BoolValue &LHS, BoolValue &RHS)
 Returns a boolean value that represents the disjunction of LHS and RHS.
 
BoolValuegetOrCreateNegation (BoolValue &Val)
 Returns a boolean value that represents the negation of Val.
 
BoolValuegetOrCreateImplication (BoolValue &LHS, BoolValue &RHS)
 Returns a boolean value that represents LHS => RHS.
 
BoolValuegetOrCreateIff (BoolValue &LHS, BoolValue &RHS)
 Returns a boolean value that represents LHS <=> RHS.
 
AtomicBoolValuemakeFlowConditionToken ()
 Creates a fresh flow condition and returns a token that identifies it.
 
void addFlowConditionConstraint (AtomicBoolValue &Token, BoolValue &Constraint)
 Adds Constraint to the flow condition identified by Token.
 
AtomicBoolValueforkFlowCondition (AtomicBoolValue &Token)
 Creates a new flow condition with the same constraints as the flow condition identified by Token and returns its token.
 
AtomicBoolValuejoinFlowConditions (AtomicBoolValue &FirstToken, AtomicBoolValue &SecondToken)
 Creates a new flow condition that represents the disjunction of the flow conditions identified by FirstToken and SecondToken, and returns its token.
 
BoolValuebuildAndSubstituteFlowCondition (AtomicBoolValue &Token, llvm::DenseMap< AtomicBoolValue *, BoolValue * > Substitutions)
 Builds and returns the logical formula defining the flow condition identified by Token.
 
bool flowConditionImplies (AtomicBoolValue &Token, BoolValue &Val)
 Returns true if and only if the constraints of the flow condition identified by Token imply that Val is true.
 
bool flowConditionIsTautology (AtomicBoolValue &Token)
 Returns true if and only if the constraints of the flow condition identified by Token are always true.
 
bool equivalentBoolValues (BoolValue &Val1, BoolValue &Val2)
 Returns true if Val1 is equivalent to Val2.
 
LLVM_DUMP_METHOD void dumpFlowCondition (AtomicBoolValue &Token)
 
const ControlFlowContextgetControlFlowContext (const FunctionDecl *F)
 Returns the ControlFlowContext registered for F, if any.
 
const OptionsgetOptions ()
 

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

Constructor & Destructor Documentation

◆ DataflowAnalysisContext()

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

Constructs a dataflow analysis context.

Requirements:

S must not be null.

Definition at line 77 of file DataflowAnalysisContext.h.

Member Function Documentation

◆ addFlowConditionConstraint()

void clang::dataflow::DataflowAnalysisContext::addFlowConditionConstraint ( AtomicBoolValue Token,
BoolValue Constraint 
)

Adds Constraint to the flow condition identified by Token.

Definition at line 162 of file DataflowAnalysisContext.cpp.

References getOrCreateConjunction().

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

◆ buildAndSubstituteFlowCondition()

BoolValue & clang::dataflow::DataflowAnalysisContext::buildAndSubstituteFlowCondition ( AtomicBoolValue Token,
llvm::DenseMap< AtomicBoolValue *, BoolValue * >  Substitutions 
)

Builds and returns the logical formula defining the flow condition identified by Token.

If a value in the formula is present as a key in Substitutions, it will be substituted with the value it maps to. As an example, say we have flow condition tokens FC1, FC2, FC3 and FlowConditionConstraints: { FC1: C1, FC2: C2, FC3: (FC1 v FC2) ^ C3 } buildAndSubstituteFlowCondition(FC3, {{C1 -> C1'}}) will return a value corresponding to (C1' v C2) ^ C3.

Definition at line 316 of file DataflowAnalysisContext.cpp.

References getBoolLiteralValue().

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

◆ createAtomicBoolValue()

AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::createAtomicBoolValue ( )
inline

Creates an atomic boolean value.

Definition at line 169 of file DataflowAnalysisContext.h.

References takeOwnership().

Referenced by clang::dataflow::Environment::makeAtomicBoolValue(), and makeFlowConditionToken().

◆ createStorageLocation()

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

◆ createTopBoolValue()

TopBoolValue & clang::dataflow::DataflowAnalysisContext::createTopBoolValue ( )
inline

Creates a Top value for booleans.

Each instance is unique and can be assigned a distinct truth value during solving.

FIXME: Top iff Top is true when both Tops are identical (by pointer equality), but not when they are distinct values. We should improve the implementation so that Top iff Top has a consistent meaning, regardless of the identity of Top. Moreover, I think the meaning should be false.

Definition at line 181 of file DataflowAnalysisContext.h.

References takeOwnership().

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

◆ dumpFlowCondition()

void clang::dataflow::DataflowAnalysisContext::dumpFlowCondition ( AtomicBoolValue Token)

◆ equivalentBoolValues()

bool clang::dataflow::DataflowAnalysisContext::equivalentBoolValues ( BoolValue Val1,
BoolValue 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 218 of file DataflowAnalysisContext.cpp.

References getOrCreateIff(), and getOrCreateNegation().

◆ flowConditionImplies()

bool clang::dataflow::DataflowAnalysisContext::flowConditionImplies ( AtomicBoolValue Token,
BoolValue Val 
)

Returns true if and only if the constraints of the flow condition identified by Token imply that Val is true.

Definition at line 196 of file DataflowAnalysisContext.cpp.

References getOrCreateNegation().

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

◆ flowConditionIsTautology()

bool clang::dataflow::DataflowAnalysisContext::flowConditionIsTautology ( AtomicBoolValue Token)

Returns true if and only if the constraints of the flow condition identified by Token are always true.

Definition at line 209 of file DataflowAnalysisContext.cpp.

References getOrCreateNegation().

◆ forkFlowCondition()

AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::forkFlowCondition ( AtomicBoolValue Token)

Creates a new flow condition with the same constraints as the flow condition identified by Token and returns its token.

Definition at line 171 of file DataflowAnalysisContext.cpp.

References addFlowConditionConstraint(), and makeFlowConditionToken().

◆ getBoolLiteralValue()

AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::getBoolLiteralValue ( bool  Value) const
inline

Returns a symbolic boolean value that models a boolean literal equal to Value.

Definition at line 164 of file DataflowAnalysisContext.h.

Referenced by buildAndSubstituteFlowCondition(), dumpFlowCondition(), clang::dataflow::Environment::getBoolLiteralValue(), getOrCreateIff(), and getOrCreateImplication().

◆ getControlFlowContext()

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

◆ getOptions()

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

◆ getOrCreateConjunction()

BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateConjunction ( BoolValue LHS,
BoolValue RHS 
)

Returns a boolean value that represents the conjunction of LHS and RHS.

Subsequent calls with the same arguments, regardless of their order, will return the same result. If the given boolean values represent the same value, the result will be the value itself.

Definition at line 100 of file DataflowAnalysisContext.cpp.

References clang::dataflow::makeCanonicalBoolValuePair(), and takeOwnership().

Referenced by addFlowConditionConstraint(), and clang::dataflow::Environment::makeAnd().

◆ getOrCreateDisjunction()

BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateDisjunction ( BoolValue LHS,
BoolValue RHS 
)

Returns a boolean value that represents the disjunction of LHS and RHS.

Subsequent calls with the same arguments, regardless of their order, will return the same result. If the given boolean values represent the same value, the result will be the value itself.

Definition at line 113 of file DataflowAnalysisContext.cpp.

References clang::dataflow::makeCanonicalBoolValuePair(), and takeOwnership().

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

◆ getOrCreateIff()

BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateIff ( BoolValue LHS,
BoolValue RHS 
)

Returns a boolean value that represents LHS <=> RHS.

Subsequent calls with the same arguments, regardless of their order, will return the same result. If the given boolean values represent the same value, the result will be a value that represents the true boolean literal.

Definition at line 145 of file DataflowAnalysisContext.cpp.

References getBoolLiteralValue(), clang::dataflow::makeCanonicalBoolValuePair(), and takeOwnership().

Referenced by equivalentBoolValues(), and clang::dataflow::Environment::makeIff().

◆ getOrCreateImplication()

BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateImplication ( BoolValue LHS,
BoolValue RHS 
)

Returns a boolean value that represents LHS => RHS.

Subsequent calls with the same arguments, will return the same result. If the given boolean values represent the same value, the result will be a value that represents the true boolean literal.

Definition at line 133 of file DataflowAnalysisContext.cpp.

References getBoolLiteralValue(), and takeOwnership().

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

◆ getOrCreateNegation()

BoolValue & clang::dataflow::DataflowAnalysisContext::getOrCreateNegation ( BoolValue Val)

Returns a boolean value that represents the negation of Val.

Subsequent calls with the same argument will return the same result.

Definition at line 126 of file DataflowAnalysisContext.cpp.

References takeOwnership().

Referenced by equivalentBoolValues(), flowConditionImplies(), flowConditionIsTautology(), and clang::dataflow::Environment::makeNot().

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

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

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

References createStorageLocation(), getStorageLocation(), clang::Expr::getType(), and setStorageLocation().

◆ getStableStorageLocation() [2/2]

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

◆ getStorageLocation() [1/2]

StorageLocation * clang::dataflow::DataflowAnalysisContext::getStorageLocation ( const Expr E) const
inline

Returns the storage location assigned to E or null if E has no assigned storage location.

Definition at line 152 of file DataflowAnalysisContext.h.

References clang::dataflow::ignoreCFGOmittedNodes().

◆ getStorageLocation() [2/2]

StorageLocation * clang::dataflow::DataflowAnalysisContext::getStorageLocation ( const ValueDecl D) const
inline

Returns the storage location assigned to D or null if D has no assigned storage location.

Definition at line 134 of file DataflowAnalysisContext.h.

Referenced by getStableStorageLocation().

◆ joinFlowConditions()

AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::joinFlowConditions ( AtomicBoolValue FirstToken,
AtomicBoolValue 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 179 of file DataflowAnalysisContext.cpp.

References addFlowConditionConstraint(), getOrCreateDisjunction(), and makeFlowConditionToken().

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

◆ makeFlowConditionToken()

AtomicBoolValue & clang::dataflow::DataflowAnalysisContext::makeFlowConditionToken ( )

Creates a fresh flow condition and returns a token that identifies it.

The token can be used to perform various operations on the flow condition such as adding constraints to it, forking it, joining it with another flow condition, or checking implications.

Definition at line 158 of file DataflowAnalysisContext.cpp.

References createAtomicBoolValue().

Referenced by forkFlowCondition(), and joinFlowConditions().

◆ setStorageLocation() [1/2]

void clang::dataflow::DataflowAnalysisContext::setStorageLocation ( const Expr E,
StorageLocation Loc 
)
inline

Assigns Loc as the storage location of E.

Requirements:

E must not be assigned a storage location.

Definition at line 144 of file DataflowAnalysisContext.h.

References clang::dataflow::ignoreCFGOmittedNodes().

◆ setStorageLocation() [2/2]

void clang::dataflow::DataflowAnalysisContext::setStorageLocation ( const ValueDecl D,
StorageLocation Loc 
)
inline

Assigns Loc as the storage location of D.

Requirements:

D must not be assigned a storage location.

Definition at line 127 of file DataflowAnalysisContext.h.

Referenced by getStableStorageLocation().

◆ takeOwnership() [1/2]

template<typename T >
std::enable_if_t< std::is_base_of< StorageLocation, T >::value, T & > clang::dataflow::DataflowAnalysisContext::takeOwnership ( std::unique_ptr< T >  Loc)
inline

◆ takeOwnership() [2/2]

template<typename T >
std::enable_if_t< std::is_base_of< Value, T >::value, T & > clang::dataflow::DataflowAnalysisContext::takeOwnership ( std::unique_ptr< T >  Val)
inline

Takes ownership of Val and returns a reference to it.

Requirements:

Val must not be null.

Definition at line 105 of file DataflowAnalysisContext.h.

Friends And Related Function Documentation

◆ Environment

friend class Environment
friend

Definition at line 276 of file DataflowAnalysisContext.h.


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