clang  16.0.0git
Classes | Public Member Functions | List of all members
clang::dataflow::Environment Class Reference

Holds the state of the program (store and heap) at a given program point. More...

#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"

Classes

class  ValueModel
 Supplements Environment with non-standard comparison and join operations. More...
 

Public Member Functions

 Environment (DataflowAnalysisContext &DACtx)
 Creates an environment that uses DACtx to store objects that encompass the state of a program. More...
 
 Environment (const Environment &Other)
 
Environmentoperator= (const Environment &Other)
 
 Environment (Environment &&Other)=default
 
Environmentoperator= (Environment &&Other)=default
 
 Environment (DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx)
 Creates an environment that uses DACtx to store objects that encompass the state of a program. More...
 
Environment pushCall (const CallExpr *Call) const
 Creates and returns an environment to use for an inline analysis of the callee. More...
 
Environment pushCall (const CXXConstructExpr *Call) const
 
void popCall (const Environment &CalleeEnv)
 Moves gathered information back into this from a CalleeEnv created via pushCall. More...
 
bool equivalentTo (const Environment &Other, Environment::ValueModel &Model) const
 Returns true if and only if the environment is equivalent to Other, i.e the two environments: More...
 
LatticeJoinEffect join (const Environment &Other, Environment::ValueModel &Model)
 Joins the environment with Other by taking the intersection of storage locations and values that are stored in them. More...
 
StorageLocationcreateStorageLocation (QualType Type)
 Creates a storage location appropriate for Type. More...
 
StorageLocationcreateStorageLocation (const VarDecl &D)
 Creates a storage location for D. More...
 
StorageLocationcreateStorageLocation (const Expr &E)
 Creates a storage location for E. More...
 
void setStorageLocation (const ValueDecl &D, StorageLocation &Loc)
 Assigns Loc as the storage location of D in the environment. More...
 
StorageLocationgetStorageLocation (const ValueDecl &D, SkipPast SP) const
 Returns the storage location assigned to D in the environment, applying the SP policy for skipping past indirections, or null if D isn't assigned a storage location in the environment. More...
 
void setStorageLocation (const Expr &E, StorageLocation &Loc)
 Assigns Loc as the storage location of E in the environment. More...
 
StorageLocationgetStorageLocation (const Expr &E, SkipPast SP) const
 Returns the storage location assigned to E in the environment, applying the SP policy for skipping past indirections, or null if E isn't assigned a storage location in the environment. More...
 
StorageLocationgetThisPointeeStorageLocation () const
 Returns the storage location assigned to the this pointee in the environment or null if the this pointee has no assigned storage location in the environment. More...
 
StorageLocationgetReturnStorageLocation () const
 Returns the storage location of the return value or null, if unset. More...
 
PointerValuegetOrCreateNullPointerValue (QualType PointeeType)
 Returns a pointer value that represents a null pointer. More...
 
ValuecreateValue (QualType Type)
 Creates a value appropriate for Type, if Type is supported, otherwise return null. More...
 
void setValue (const StorageLocation &Loc, Value &Val)
 Assigns Val as the value of Loc in the environment. More...
 
ValuegetValue (const StorageLocation &Loc) const
 Returns the value assigned to Loc in the environment or null if Loc isn't assigned a value in the environment. More...
 
ValuegetValue (const ValueDecl &D, SkipPast SP) const
 Equivalent to getValue(getStorageLocation(D, SP), SkipPast::None) if D is assigned a storage location in the environment, otherwise returns null. More...
 
ValuegetValue (const Expr &E, SkipPast SP) const
 Equivalent to getValue(getStorageLocation(E, SP), SkipPast::None) if E is assigned a storage location in the environment, otherwise returns null. More...
 
template<typename T >
std::enable_if< std::is_base_of< StorageLocation, T >::value, T & >::type takeOwnership (std::unique_ptr< T > Loc)
 Transfers ownership of Loc to the analysis context and returns a reference to it. More...
 
template<typename T >
std::enable_if< std::is_base_of< Value, T >::value, T & >::type takeOwnership (std::unique_ptr< T > Val)
 Transfers ownership of Val to the analysis context and returns a reference to it. More...
 
AtomicBoolValuegetBoolLiteralValue (bool Value) const
 Returns a symbolic boolean value that models a boolean literal equal to Value More...
 
BoolValuemakeAtomicBoolValue () const
 Returns an atomic boolean value. More...
 
BoolValuemakeAnd (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value that represents the conjunction of LHS and RHS. More...
 
BoolValuemakeOr (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value that represents the disjunction of LHS and RHS. More...
 
BoolValuemakeNot (BoolValue &Val) const
 Returns a boolean value that represents the negation of Val. More...
 
BoolValuemakeImplication (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value represents LHS => RHS. More...
 
BoolValuemakeIff (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value represents LHS <=> RHS. More...
 
AtomicBoolValuegetFlowConditionToken () const
 Returns the token that identifies the flow condition of the environment. More...
 
BoolValuebuildAndSubstituteFlowCondition (AtomicBoolValue &Token, llvm::DenseMap< AtomicBoolValue *, BoolValue * > Substitutions)
 Builds and returns the logical formula defining the flow condition identified by Token. More...
 
void addToFlowCondition (BoolValue &Val)
 Adds Val to the set of clauses that constitute the flow condition. More...
 
bool flowConditionImplies (BoolValue &Val) const
 Returns true if and only if the clauses that constitute the flow condition imply that Val is true. More...
 
const DeclContextgetDeclCtx () const
 Returns the DeclContext of the block being analysed, if any. More...
 
bool canDescend (unsigned MaxDepth, const DeclContext *Callee) const
 Returns whether this Environment can be extended to analyze the given Callee (i.e. More...
 
const ControlFlowContextgetControlFlowContext (const FunctionDecl *F)
 Returns the ControlFlowContext registered for F, if any. More...
 
LLVM_DUMP_METHOD void dump () const
 

Detailed Description

Holds the state of the program (store and heap) at a given program point.

WARNING: Symbolic values that are created by the environment for static local and global variables are not currently invalidated on function calls. This is unsound and should be taken into account when designing dataflow analyses.

Definition at line 57 of file DataflowEnvironment.h.

Constructor & Destructor Documentation

◆ Environment() [1/4]

clang::dataflow::Environment::Environment ( DataflowAnalysisContext DACtx)
explicit

Creates an environment that uses DACtx to store objects that encompass the state of a program.

Definition at line 151 of file DataflowEnvironment.cpp.

◆ Environment() [2/4]

clang::dataflow::Environment::Environment ( const Environment Other)

Definition at line 154 of file DataflowEnvironment.cpp.

◆ Environment() [3/4]

clang::dataflow::Environment::Environment ( Environment &&  Other)
default

◆ Environment() [4/4]

clang::dataflow::Environment::Environment ( DataflowAnalysisContext DACtx,
const DeclContext DeclCtx 
)

Creates an environment that uses DACtx to store objects that encompass the state of a program.

If DeclCtx is a function, initializes the environment with symbolic representations of the function parameters.

If DeclCtx is a non-static member function, initializes the environment with a symbolic representation of the this pointee.

Definition at line 168 of file DataflowEnvironment.cpp.

References createStorageLocation(), createValue(), clang::dataflow::initGlobalVars(), clang::Type::isUnionType(), Parent, setStorageLocation(), and setValue().

Member Function Documentation

◆ addToFlowCondition()

void clang::dataflow::Environment::addToFlowCondition ( BoolValue Val)

◆ buildAndSubstituteFlowCondition()

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

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.

Definition at line 335 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::buildAndSubstituteFlowCondition().

◆ canDescend()

bool clang::dataflow::Environment::canDescend ( unsigned  MaxDepth,
const DeclContext Callee 
) const

Returns whether this Environment can be extended to analyze the given Callee (i.e.

if pushCall can be used), with recursion disallowed and a given MaxDepth.

Definition at line 206 of file DataflowEnvironment.cpp.

◆ createStorageLocation() [1/3]

StorageLocation & clang::dataflow::Environment::createStorageLocation ( const Expr E)

Creates a storage location for E.

Does not assign the returned storage location to E in the environment. Does not assign a value to the returned storage location in the environment.

Definition at line 399 of file DataflowEnvironment.cpp.

References clang::dataflow::DataflowAnalysisContext::getStableStorageLocation().

◆ createStorageLocation() [2/3]

StorageLocation & clang::dataflow::Environment::createStorageLocation ( const VarDecl D)

Creates a storage location for D.

Does not assign the returned storage location to D in the environment. Does not assign a value to the returned storage location in the environment.

Definition at line 392 of file DataflowEnvironment.cpp.

References clang::dataflow::DataflowAnalysisContext::getStableStorageLocation().

◆ createStorageLocation() [3/3]

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

Creates a storage location appropriate for Type.

Does not assign a value to the returned storage location in the environment.

Requirements:

Type must not be null.

Definition at line 388 of file DataflowEnvironment.cpp.

References clang::dataflow::DataflowAnalysisContext::createStorageLocation().

Referenced by Environment(), and clang::dataflow::initGlobalVar().

◆ createValue()

Value * clang::dataflow::Environment::createValue ( QualType  Type)

Creates a value appropriate for Type, if Type is supported, otherwise return null.

If Type is a pointer or reference type, creates all the necessary storage locations and values for indirections until it finds a non-pointer/non-reference type.

Requirements:

Type must not be null.

Definition at line 494 of file DataflowEnvironment.cpp.

References clang::dataflow::MaxCompositeValueSize.

Referenced by Environment(), clang::dataflow::initGlobalVar(), and clang::dataflow::mergeDistinctValues().

◆ dump()

void clang::dataflow::Environment::dump ( ) const

◆ equivalentTo()

bool clang::dataflow::Environment::equivalentTo ( const Environment Other,
Environment::ValueModel Model 
) const

Returns true if and only if the environment is equivalent to Other, i.e the two environments:

  • have the same mappings from declarations to storage locations,
  • have the same mappings from expressions to storage locations,
  • have the same or equivalent (according to Model) values assigned to the same storage locations.

Requirements:

Other and this must use the same DataflowAnalysisContext.

Definition at line 291 of file DataflowEnvironment.cpp.

References clang::dataflow::equivalentValues(), and clang::dataflow::StorageLocation::getType().

◆ flowConditionImplies()

bool clang::dataflow::Environment::flowConditionImplies ( BoolValue Val) const

Returns true if and only if the clauses that constitute the flow condition imply that Val is true.

Definition at line 614 of file DataflowEnvironment.cpp.

References clang::dataflow::DataflowAnalysisContext::flowConditionImplies().

◆ getBoolLiteralValue()

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

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

Definition at line 282 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getBoolLiteralValue().

Referenced by clang::dataflow::ChromiumCheckModel::transfer().

◆ getControlFlowContext()

const ControlFlowContext* clang::dataflow::Environment::getControlFlowContext ( const FunctionDecl F)
inline

Returns the ControlFlowContext registered for F, if any.

Otherwise, returns null.

Definition at line 360 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getControlFlowContext().

◆ getDeclCtx()

const DeclContext* clang::dataflow::Environment::getDeclCtx ( ) const
inline

Returns the DeclContext of the block being analysed, if any.

Otherwise, returns null.

Definition at line 351 of file DataflowEnvironment.h.

◆ getFlowConditionToken()

AtomicBoolValue& clang::dataflow::Environment::getFlowConditionToken ( ) const
inline

Returns the token that identifies the flow condition of the environment.

Definition at line 330 of file DataflowEnvironment.h.

Referenced by clang::dataflow::mergeDistinctValues().

◆ getOrCreateNullPointerValue()

PointerValue & clang::dataflow::Environment::getOrCreateNullPointerValue ( QualType  PointeeType)

Returns a pointer value that represents a null pointer.

Calls with PointeeType that are canonically equivalent will return the same result.

Definition at line 438 of file DataflowEnvironment.cpp.

References clang::dataflow::DataflowAnalysisContext::getOrCreateNullPointerValue().

◆ getReturnStorageLocation()

StorageLocation * clang::dataflow::Environment::getReturnStorageLocation ( ) const

Returns the storage location of the return value or null, if unset.

Definition at line 434 of file DataflowEnvironment.cpp.

◆ getStorageLocation() [1/2]

StorageLocation * clang::dataflow::Environment::getStorageLocation ( const Expr E,
SkipPast  SP 
) const

Returns the storage location assigned to E in the environment, applying the SP policy for skipping past indirections, or null if E isn't assigned a storage location in the environment.

Definition at line 423 of file DataflowEnvironment.cpp.

References clang::dataflow::ignoreCFGOmittedNodes().

◆ getStorageLocation() [2/2]

StorageLocation * clang::dataflow::Environment::getStorageLocation ( const ValueDecl D,
SkipPast  SP 
) const

Returns the storage location assigned to D in the environment, applying the SP policy for skipping past indirections, or null if D isn't assigned a storage location in the environment.

Definition at line 411 of file DataflowEnvironment.cpp.

Referenced by getValue(), clang::dataflow::initGlobalVar(), and pushCall().

◆ getThisPointeeStorageLocation()

StorageLocation * clang::dataflow::Environment::getThisPointeeStorageLocation ( ) const

Returns the storage location assigned to the this pointee in the environment or null if the this pointee has no assigned storage location in the environment.

Definition at line 430 of file DataflowEnvironment.cpp.

◆ getValue() [1/3]

Value * clang::dataflow::Environment::getValue ( const Expr E,
SkipPast  SP 
) const

Equivalent to getValue(getStorageLocation(E, SP), SkipPast::None) if E is assigned a storage location in the environment, otherwise returns null.

Definition at line 487 of file DataflowEnvironment.cpp.

References getStorageLocation(), and getValue().

◆ getValue() [2/3]

Value * clang::dataflow::Environment::getValue ( const StorageLocation Loc) const

Returns the value assigned to Loc in the environment or null if Loc isn't assigned a value in the environment.

Definition at line 475 of file DataflowEnvironment.cpp.

Referenced by clang::dataflow::evaluateBooleanEquality(), and getValue().

◆ getValue() [3/3]

Value * clang::dataflow::Environment::getValue ( const ValueDecl D,
SkipPast  SP 
) const

Equivalent to getValue(getStorageLocation(D, SP), SkipPast::None) if D is assigned a storage location in the environment, otherwise returns null.

Definition at line 480 of file DataflowEnvironment.cpp.

References getStorageLocation(), and getValue().

◆ join()

LatticeJoinEffect clang::dataflow::Environment::join ( const Environment Other,
Environment::ValueModel Model 
)

Joins the environment with Other by taking the intersection of storage locations and values that are stored in them.

Distinct values that are assigned to the same storage locations in the environment and Other are merged using Model.

Requirements:

Other and this must use the same DataflowAnalysisContext.

Definition at line 327 of file DataflowEnvironment.cpp.

References clang::dataflow::Changed, clang::dataflow::StorageLocation::getType(), clang::dataflow::intersectDenseMaps(), clang::dataflow::DataflowAnalysisContext::joinFlowConditions(), clang::dataflow::mergeDistinctValues(), and clang::dataflow::Unchanged.

◆ makeAnd()

BoolValue& clang::dataflow::Environment::makeAnd ( BoolValue LHS,
BoolValue RHS 
) const
inline

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 295 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getOrCreateConjunction().

Referenced by clang::dataflow::mergeDistinctValues().

◆ makeAtomicBoolValue()

BoolValue& clang::dataflow::Environment::makeAtomicBoolValue ( ) const
inline

◆ makeIff()

BoolValue& clang::dataflow::Environment::makeIff ( BoolValue LHS,
BoolValue RHS 
) const
inline

Returns a boolean value 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 325 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getOrCreateIff().

Referenced by clang::dataflow::evaluateBooleanEquality(), and clang::dataflow::mergeDistinctValues().

◆ makeImplication()

BoolValue& clang::dataflow::Environment::makeImplication ( BoolValue LHS,
BoolValue RHS 
) const
inline

Returns a boolean value 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 317 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getOrCreateImplication().

◆ makeNot()

BoolValue& clang::dataflow::Environment::makeNot ( BoolValue Val) const
inline

Returns a boolean value that represents the negation of Val.

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

Definition at line 309 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getOrCreateNegation().

Referenced by clang::dataflow::UncheckedOptionalAccessModel::merge().

◆ makeOr()

BoolValue& clang::dataflow::Environment::makeOr ( BoolValue LHS,
BoolValue RHS 
) const
inline

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 303 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::getOrCreateDisjunction().

Referenced by clang::dataflow::mergeDistinctValues().

◆ operator=() [1/2]

Environment & clang::dataflow::Environment::operator= ( const Environment Other)

Definition at line 162 of file DataflowEnvironment.cpp.

◆ operator=() [2/2]

Environment& clang::dataflow::Environment::operator= ( Environment &&  Other)
default

◆ popCall()

void clang::dataflow::Environment::popCall ( const Environment CalleeEnv)

Moves gathered information back into this from a CalleeEnv created via pushCall.

Definition at line 278 of file DataflowEnvironment.cpp.

◆ pushCall() [1/2]

Environment clang::dataflow::Environment::pushCall ( const CallExpr Call) const

Creates and returns an environment to use for an inline analysis of the callee.

Uses the storage location from each argument in the Call as the storage location for the corresponding parameter in the callee.

Requirements:

The callee of Call must be a FunctionDecl.

The body of the callee must not reference globals.

The arguments of Call must map 1:1 to the callee's parameters.

Definition at line 211 of file DataflowEnvironment.cpp.

References getStorageLocation(), and clang::dataflow::Reference.

◆ pushCall() [2/2]

Environment clang::dataflow::Environment::pushCall ( const CXXConstructExpr Call) const

Definition at line 229 of file DataflowEnvironment.cpp.

References getStorageLocation(), and clang::dataflow::Reference.

◆ setStorageLocation() [1/2]

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

Assigns Loc as the storage location of E in the environment.

Requirements:

E must not be assigned a storage location in the environment.

Definition at line 417 of file DataflowEnvironment.cpp.

References clang::dataflow::ignoreCFGOmittedNodes().

◆ setStorageLocation() [2/2]

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

Assigns Loc as the storage location of D in the environment.

Requirements:

D must not be assigned a storage location in the environment.

Definition at line 406 of file DataflowEnvironment.cpp.

Referenced by Environment(), and clang::dataflow::initGlobalVar().

◆ setValue()

void clang::dataflow::Environment::setValue ( const StorageLocation Loc,
Value Val 
)

◆ takeOwnership() [1/2]

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

Transfers ownership of Loc to the analysis context and returns a reference to it.

Requirements:

Loc must not be null.

Definition at line 264 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::takeOwnership().

◆ takeOwnership() [2/2]

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

Transfers ownership of Val to the analysis context and returns a reference to it.

Requirements:

Val must not be null.

Definition at line 276 of file DataflowEnvironment.h.

References clang::dataflow::DataflowAnalysisContext::takeOwnership().


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