clang 24.0.0git
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 Types

enum  ExprJoinBehavior { DiscardExprState , KeepExprState }
 How to treat expression state (ExprToLoc and ExprToVal) in a join. More...

Public Member Functions

 Environment (DataflowAnalysisContext &DACtx, Atom FlowConditionToken)
 Creates an environment that uses DACtx to store objects that encompass the state of a program.
 Environment (DataflowAnalysisContext &DACtx)
 Creates an environment that uses DACtx to store objects that encompass the state of a program.
 Environment (DataflowAnalysisContext &DACtx, Stmt &S)
 Creates an environment that uses DACtx to store objects that encompass the state of a program, with S as the statement to analyze.
 Environment (DataflowAnalysisContext &DACtx, const FunctionDecl &FD)
 Creates an environment that uses DACtx to store objects that encompass the state of a program, with FD as the function to analyze.
Environmentoperator= (const Environment &Other)=delete
 Environment (Environment &&Other)=default
Environmentoperator= (Environment &&Other)=default
void initialize ()
 Assigns storage locations and values to all parameters, captures, global variables, fields and functions referenced in the Stmt or FunctionDecl passed to the constructor.
Environment fork () const
 Returns a new environment that is a copy of this one.
Environment pushCall (const CallExpr *Call) const
 Creates and returns an environment to use for an inline analysis of the callee.
Environment pushCall (const CXXConstructExpr *Call) const
void popCall (const CallExpr *Call, const Environment &CalleeEnv)
 Moves gathered information back into this from a CalleeEnv created via pushCall.
void popCall (const CXXConstructExpr *Call, const Environment &CalleeEnv)
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:
LatticeEffect widen (const Environment &PrevEnv, Environment::ValueModel &Model)
 Widens the environment point-wise, using PrevEnv as needed to inform the approximation.
StorageLocationcreateStorageLocation (QualType Type)
 Creates a storage location appropriate for Type.
StorageLocationcreateStorageLocation (const ValueDecl &D)
 Creates a storage location for D.
StorageLocationcreateStorageLocation (const Expr &E)
 Creates a storage location for E.
void setStorageLocation (const ValueDecl &D, StorageLocation &Loc)
 Assigns Loc as the storage location of D in the environment.
StorageLocationgetStorageLocation (const ValueDecl &D) const
 Returns the storage location assigned to D in the environment, or null if D isn't assigned a storage location in the environment.
void removeDecl (const ValueDecl &D)
 Removes the location assigned to D in the environment (if any).
void setStorageLocation (const Expr &E, StorageLocation &Loc)
 Assigns Loc as the storage location of the glvalue E in the environment.
StorageLocationgetStorageLocation (const Expr &E) const
 Returns the storage location assigned to the glvalue E in the environment, or null if E isn't assigned a storage location in the environment.
template<typename T>
std::enable_if_t< std::is_base_of_v< StorageLocation, T >, T * > get (const ValueDecl &D) const
 Returns the result of casting getStorageLocation(...) to a subclass of StorageLocation (using cast_or_null<T>).
template<typename T>
std::enable_if_t< std::is_base_of_v< StorageLocation, T >, T * > get (const Expr &E) const
RecordStorageLocationgetThisPointeeStorageLocation () 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.
RecordStorageLocationgetThisPointeeStorageLocation (const CXXThisExpr &ThisExpr) const
 Returns the storage location assigned to the this pointee in the environment given a specific CXXThisExpr.
void setThisPointeeStorageLocation (RecordStorageLocation &Loc)
 Sets the storage location assigned to the this pointee in the environment.
RecordStorageLocationgetResultObjectLocation (const Expr &RecordPRValue) const
 Returns the location of the result object for a record-type prvalue.
ValuegetReturnValue () const
 Returns the return value of the function currently being analyzed.
StorageLocationgetReturnStorageLocation () const
 Returns the storage location for the reference returned by the function currently being analyzed.
void setReturnValue (Value *Val)
 Sets the return value of the function currently being analyzed.
void setReturnStorageLocation (StorageLocation *Loc)
 Sets the storage location for the reference returned by the function currently being analyzed.
PointerValuegetOrCreateNullPointerValue (QualType PointeeType)
 Returns a pointer value that represents a null pointer.
ValuecreateValue (QualType Type)
 Creates a value appropriate for Type, if Type is supported, otherwise returns null.
StorageLocationcreateObject (QualType Ty, const Expr *InitExpr=nullptr)
 Creates an object (i.e.
StorageLocationcreateObject (const VarDecl &D)
 Creates an object for the variable declaration D.
StorageLocationcreateObject (const ValueDecl &D, const Expr *InitExpr)
 Creates an object for the variable declaration D.
void initializeFieldsWithValues (RecordStorageLocation &Loc, QualType Type)
 Initializes the fields (including synthetic fields) of Loc with values, unless values of the field type are not supported or we hit one of the limits at which we stop producing values.
void initializeFieldsWithValues (RecordStorageLocation &Loc)
void setValue (const StorageLocation &Loc, Value &Val)
 Assigns Val as the value of Loc in the environment.
void clearValue (const StorageLocation &Loc)
 Clears any association between Loc and a value in the environment.
void setValue (const Expr &E, Value &Val)
 Assigns Val as the value of the prvalue E in the environment.
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.
ValuegetValue (const ValueDecl &D) const
 Equivalent to getValue(getStorageLocation(D)) if D is assigned a storage location in the environment, otherwise returns null.
ValuegetValue (const Expr &E) const
 Equivalent to getValue(getStorageLocation(E, SP)) if E is assigned a storage location in the environment, otherwise returns null.
template<typename T>
std::enable_if_t< std::is_base_of_v< Value, T >, T * > get (const StorageLocation &Loc) const
 Returns the result of casting getValue(...) to a subclass of Value (using cast_or_null<T>).
template<typename T>
std::enable_if_t< std::is_base_of_v< Value, T >, T * > get (const ValueDecl &D) const
template<typename T>
std::enable_if_t< std::is_base_of_v< Value, T >, T * > get (const Expr &E) const
template<typename T, typename... Args>
std::enable_if_t< std::is_base_of< Value, T >::value, T & > create (Args &&...args)
 Creates a T (some subclass of Value), forwarding args to the constructor, and returns a reference to it.
IntegerValuegetIntLiteralValue (llvm::APInt Value) const
 Returns a symbolic integer value that models an integer literal equal to Value
BoolValuegetBoolLiteralValue (bool Value) const
 Returns a symbolic boolean value that models a boolean literal equal to Value
BoolValuemakeAtomicBoolValue () const
 Returns an atomic boolean value.
BoolValuemakeTopBoolValue () const
 Returns a unique instance of boolean Top.
BoolValuemakeAnd (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value that represents the conjunction of LHS and RHS.
BoolValuemakeOr (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value that represents the disjunction of LHS and RHS.
BoolValuemakeNot (BoolValue &Val) const
 Returns a boolean value that represents the negation of Val.
BoolValuemakeImplication (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value represents LHS => RHS.
BoolValuemakeIff (BoolValue &LHS, BoolValue &RHS) const
 Returns a boolean value represents LHS <=> RHS.
Atom getFlowConditionToken () const
 Returns a boolean variable that identifies the flow condition (FC).
void assume (const Formula &)
 Record a fact that must be true if this point in the program is reached.
bool proves (const Formula &) const
 Returns true if the formula is always true when this point is reached.
bool allows (const Formula &) const
 Returns true if the formula may be true when this point is reached.
const FunctionDeclgetCurrentFunc () const
 Returns the function currently being analyzed, or null if the code being analyzed isn't part of a function.
size_t callStackSize () const
 Returns the size of the call stack, not counting the initial analysis target.
bool canDescend (unsigned MaxDepth, const FunctionDecl *Callee) const
 Returns whether this Environment can be extended to analyze the given Callee (i.e.
DataflowAnalysisContextgetDataflowAnalysisContext () const
 Returns the DataflowAnalysisContext used by the environment.
Arenaarena () const
LLVM_DUMP_METHOD void dump () const
LLVM_DUMP_METHOD void dump (raw_ostream &OS) const

Static Public Member Functions

static Environment join (const Environment &EnvA, const Environment &EnvB, Environment::ValueModel &Model, ExprJoinBehavior ExprBehavior)
 Joins two environments by taking the intersection of storage locations and values that are stored in them.
static ValuejoinValues (QualType Ty, Value *Val1, const Environment &Env1, Value *Val2, const Environment &Env2, Environment &JoinedEnv, Environment::ValueModel &Model)
 Returns a value that approximates both Val1 and Val2, or null if no such value can be produced.

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

Member Enumeration Documentation

◆ ExprJoinBehavior

How to treat expression state (ExprToLoc and ExprToVal) in a join.

If the join happens within a full expression, expression state should be kept; otherwise, we can discard it.

Enumerator
DiscardExprState 
KeepExprState 

Definition at line 251 of file DataflowEnvironment.h.

Constructor & Destructor Documentation

◆ Environment() [1/5]

clang::dataflow::Environment::Environment ( DataflowAnalysisContext & DACtx,
Atom FlowConditionToken )
inline

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

FlowConditionToken sets the flow condition associated with the environment. Generally, new environments should be initialized with a fresh token, by using one of the other constructors. This constructor is for specialized use, including deserialization and delegation from other constructors.

Definition at line 166 of file DataflowEnvironment.h.

Referenced by clang::dataflow::Environment::ValueModel::compare(), Environment(), Environment(), Environment(), Environment(), equivalentTo(), fork(), join(), clang::dataflow::Environment::ValueModel::join(), joinValues(), operator=(), operator=(), popCall(), popCall(), pushCall(), pushCall(), clang::dataflow::Environment::ValueModel::widen(), and widen().

◆ Environment() [2/5]

clang::dataflow::Environment::Environment ( DataflowAnalysisContext & DACtx)
inlineexplicit

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

Populates a fresh atom as flow condition token.

Definition at line 171 of file DataflowEnvironment.h.

References arena(), and Environment().

◆ Environment() [3/5]

clang::dataflow::Environment::Environment ( DataflowAnalysisContext & DACtx,
Stmt & S )
inline

Creates an environment that uses DACtx to store objects that encompass the state of a program, with S as the statement to analyze.

Definition at line 176 of file DataflowEnvironment.h.

References Environment().

◆ Environment() [4/5]

clang::dataflow::Environment::Environment ( DataflowAnalysisContext & DACtx,
const FunctionDecl & FD )
inline

Creates an environment that uses DACtx to store objects that encompass the state of a program, with FD as the function to analyze.

Requirements:

The function must have a body, i.e. FunctionDecl::doesThisDecalarationHaveABody() must be true.

Definition at line 187 of file DataflowEnvironment.h.

References clang::FunctionDecl::doesThisDeclarationHaveABody(), and Environment().

◆ Environment() [5/5]

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

References Environment(), and clang::Other.

Member Function Documentation

◆ allows()

bool clang::dataflow::Environment::allows ( const Formula & F) const

Returns true if the formula may be true when this point is reached.

Returns false if the formula is always false when this point is reached (or the flow condition is overly constraining) or if the solver times out.

Definition at line 1260 of file DataflowEnvironment.cpp.

◆ arena()

◆ assume()

◆ callStackSize()

size_t clang::dataflow::Environment::callStackSize ( ) const
inline

Returns the size of the call stack, not counting the initial analysis target.

Definition at line 701 of file DataflowEnvironment.h.

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

◆ canDescend()

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

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

if pushCall can be used). Recursion is not allowed. MaxDepth is the maximum size of the call stack (i.e. the maximum value that callStackSize() may assume after the call).

Definition at line 709 of file DataflowEnvironment.cpp.

◆ clearValue()

void clang::dataflow::Environment::clearValue ( const StorageLocation & Loc)
inline

Clears any association between Loc and a value in the environment.

Definition at line 531 of file DataflowEnvironment.h.

Referenced by clang::dataflow::copyField(), and clang::dataflow::copySyntheticField().

◆ create()

template<typename T, typename... Args>
std::enable_if_t< std::is_base_of< Value, T >::value, T & > clang::dataflow::Environment::create ( Args &&... args)
inline

Creates a T (some subclass of Value), forwarding args to the constructor, and returns a reference to it.

The analysis context takes ownership of the created object. The object will be destroyed when the analysis context is destroyed.

Definition at line 590 of file DataflowEnvironment.h.

References arena(), clang::dataflow::Arena::create(), and clang::T.

◆ createObject() [1/3]

StorageLocation & clang::dataflow::Environment::createObject ( const ValueDecl & D,
const Expr * InitExpr )
inline

Creates an object for the variable declaration D.

If InitExpr is non-null and has a value associated with it, initializes the object with this value. Otherwise, initializes the object with a value created using createValue(). Uses the storage location returned by DataflowAnalysisContext::getStableStorageLocation(D).

Definition at line 507 of file DataflowEnvironment.h.

References clang::ValueDecl::getType().

◆ createObject() [2/3]

StorageLocation & clang::dataflow::Environment::createObject ( const VarDecl & D)
inline

Creates an object for the variable declaration D.

If D has an initializer and this initializer is associated with a value, initializes the object with this value. Otherwise, initializes the object with a value created using createValue(). Uses the storage location returned by DataflowAnalysisContext::getStableStorageLocation(D).

Definition at line 498 of file DataflowEnvironment.h.

References clang::VarDecl::getInit(), and clang::ValueDecl::getType().

◆ createObject() [3/3]

StorageLocation & clang::dataflow::Environment::createObject ( QualType Ty,
const Expr * InitExpr = nullptr )
inline

Creates an object (i.e.

a storage location with an associated value) of type Ty. If InitExpr is non-null and has a value associated with it, initializes the object with this value. Otherwise, initializes the object with a value created using createValue().

Definition at line 489 of file DataflowEnvironment.h.

Referenced by initialize().

◆ 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 958 of file DataflowEnvironment.cpp.

◆ createStorageLocation() [2/3]

StorageLocation & clang::dataflow::Environment::createStorageLocation ( const ValueDecl & 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 951 of file DataflowEnvironment.cpp.

◆ 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 947 of file DataflowEnvironment.cpp.

Referenced by clang::dataflow::CachedConstAccessorsLattice< Base >::getOrCreateConstMethodReturnStorageLocation(), initialize(), and setStorageLocation().

◆ createValue()

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

Creates a value appropriate for Type, if Type is supported, otherwise returns 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.

If Type is one of the following types, this function will always return a non-null pointer:

  • bool
  • Any integer type

Requirements:

  • Type must not be null.
  • Type must not be a reference type or record type.

Definition at line 1081 of file DataflowEnvironment.cpp.

References clang::dataflow::MaxCompositeValueSize.

Referenced by clang::dataflow::CachedConstAccessorsLattice< Base >::getOrCreateConstMethodReturnValue(), and clang::dataflow::joinDistinctValues().

◆ dump() [1/2]

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

Definition at line 1317 of file DataflowEnvironment.cpp.

References dump().

Referenced by dump(), and clang::dataflow::runTypeErasedDataflowAnalysis().

◆ dump() [2/2]

void clang::dataflow::Environment::dump ( raw_ostream & OS) const

Definition at line 1264 of file DataflowEnvironment.cpp.

References clang::Func, getCurrentFunc(), clang::isa(), and V.

◆ 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 805 of file DataflowEnvironment.cpp.

References clang::dataflow::compareKeyToValueMaps(), Environment(), and clang::Other.

◆ fork()

Environment clang::dataflow::Environment::fork ( ) const

Returns a new environment that is a copy of this one.

The state of the program is initially the same, but can be mutated without affecting the original.

However the original should not be further mutated, as this may interfere with the fork. (In practice, values are stored independently, but the forked flow condition references the original).

Definition at line 703 of file DataflowEnvironment.cpp.

References clang::Copy, and Environment().

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

◆ get() [1/5]

template<typename T>
std::enable_if_t< std::is_base_of_v< StorageLocation, T >, T * > clang::dataflow::Environment::get ( const Expr & E) const
inline

Definition at line 356 of file DataflowEnvironment.h.

References getStorageLocation().

◆ get() [2/5]

template<typename T>
std::enable_if_t< std::is_base_of_v< Value, T >, T * > clang::dataflow::Environment::get ( const Expr & E) const
inline

Definition at line 577 of file DataflowEnvironment.h.

References getValue(), and clang::T.

◆ get() [3/5]

template<typename T>
std::enable_if_t< std::is_base_of_v< Value, T >, T * > clang::dataflow::Environment::get ( const StorageLocation & Loc) const
inline

Returns the result of casting getValue(...) to a subclass of Value (using cast_or_null<T>).

This assert-fails if the result of getValue(...) is not of type T *; if the value is not guaranteed to have type T *, consider using dyn_cast_or_null<T>(getValue(...)) instead.

Definition at line 568 of file DataflowEnvironment.h.

References getValue().

◆ get() [4/5]

template<typename T>
std::enable_if_t< std::is_base_of_v< StorageLocation, T >, T * > clang::dataflow::Environment::get ( const ValueDecl & D) const
inline

Returns the result of casting getStorageLocation(...) to a subclass of StorageLocation (using cast_or_null<T>).

This assert-fails if the result of getStorageLocation(...) is not of type T *; if the storage location is not guaranteed to have type T *, consider using dyn_cast_or_null<T>(getStorageLocation(...)) instead.

Definition at line 351 of file DataflowEnvironment.h.

References getStorageLocation().

Referenced by clang::dataflow::statusor_model::buildDiagnoseMatchSwitch(), clang::dataflow::statusor_model::evaluateEquality(), clang::dataflow::getBaseObjectLocation(), clang::dataflow::getImplicitObjectLocation(), clang::dataflow::statusor_model::getPointeeLocation(), clang::dataflow::statusor_model::isSafeUnwrap(), and clang::dataflow::statusor_model::valForOk().

◆ get() [5/5]

template<typename T>
std::enable_if_t< std::is_base_of_v< Value, T >, T * > clang::dataflow::Environment::get ( const ValueDecl & D) const
inline

Definition at line 573 of file DataflowEnvironment.h.

References getValue().

◆ getBoolLiteralValue()

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

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

Definition at line 602 of file DataflowEnvironment.h.

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

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

◆ getCurrentFunc()

const FunctionDecl * clang::dataflow::Environment::getCurrentFunc ( ) const
inline

Returns the function currently being analyzed, or null if the code being analyzed isn't part of a function.

Definition at line 695 of file DataflowEnvironment.h.

Referenced by dump(), getReturnStorageLocation(), getReturnValue(), join(), setReturnStorageLocation(), and setReturnValue().

◆ getDataflowAnalysisContext()

DataflowAnalysisContext & clang::dataflow::Environment::getDataflowAnalysisContext ( ) const
inline

◆ getFlowConditionToken()

Atom clang::dataflow::Environment::getFlowConditionToken ( ) const
inline

Returns a boolean variable that identifies the flow condition (FC).

The flow condition is a set of facts that are necessarily true when the program reaches the current point, expressed as boolean formulas. The flow condition token is equivalent to the AND of these facts.

These may e.g. constrain the value of certain variables. A pointer variable may have a consistent modeled PointerValue throughout, but at a given point the Environment may tell us that the value must be non-null.

The FC is necessary but not sufficient for this point to be reachable. In particular, where the FC token appears in flow conditions of successor environments, it means "point X may have been reached", not "point X was reached".

Definition at line 672 of file DataflowEnvironment.h.

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

◆ getIntLiteralValue()

IntegerValue & clang::dataflow::Environment::getIntLiteralValue ( llvm::APInt Value) const
inline

Returns a symbolic integer value that models an integer literal equal to Value

Definition at line 596 of file DataflowEnvironment.h.

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

◆ 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 1023 of file DataflowEnvironment.cpp.

◆ getResultObjectLocation()

RecordStorageLocation & clang::dataflow::Environment::getResultObjectLocation ( const Expr & RecordPRValue) const

Returns the location of the result object for a record-type prvalue.

In C++, prvalues of record type serve only a limited purpose: They can only be used to initialize a result object (e.g. a variable or a temporary). This function returns the location of that result object.

When creating a prvalue of record type, we already need the storage location of the result object to pass in this, even though prvalues are otherwise not associated with storage locations.

Requirements: E must be a prvalue of record type.

Definition at line 1008 of file DataflowEnvironment.cpp.

References clang::cast(), clang::Expr::getType(), clang::Expr::isPRValue(), and clang::Type::isRecordType().

Referenced by pushCall(), and pushCall().

◆ getReturnStorageLocation()

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

Returns the storage location for the reference returned by the function currently being analyzed.

This can be null if the function doesn't return a single consistent reference.

Requirements: The current analysis target must be a function and must have a reference return type.

Definition at line 434 of file DataflowEnvironment.h.

References getCurrentFunc().

◆ getReturnValue()

Value * clang::dataflow::Environment::getReturnValue ( ) const
inline

Returns the return value of the function currently being analyzed.

This can be null if:

  • The function has a void return type
  • No return value could be determined for the function, for example because it calls a function without a body.

Requirements: The current analysis target must be a function and must have a non-reference return type.

Definition at line 421 of file DataflowEnvironment.h.

References getCurrentFunc().

◆ getStorageLocation() [1/2]

StorageLocation * clang::dataflow::Environment::getStorageLocation ( const Expr & E) const

Returns the storage location assigned to the glvalue E in the environment, or null if E isn't assigned a storage location in the environment.

Requirements: E must be a glvalue or a BuiltinType::BuiltinFn

Definition at line 999 of file DataflowEnvironment.cpp.

References clang::Expr::getType(), clang::dataflow::ignoreCFGOmittedNodes(), clang::Expr::isGLValue(), clang::Type::isSpecificBuiltinType(), and clang::nullptr.

◆ getStorageLocation() [2/2]

StorageLocation * clang::dataflow::Environment::getStorageLocation ( const ValueDecl & D) const

Returns the storage location assigned to D in the environment, or null if D isn't assigned a storage location in the environment.

Definition at line 976 of file DataflowEnvironment.cpp.

Referenced by get(), get(), clang::dataflow::getImplicitObjectLocation(), clang::dataflow::statusor_model::getSmartPtrLikeStorageLocation(), getValue(), clang::dataflow::maybeUnpackLValueExpr(), clang::dataflow::propagateStorageLocation(), and pushCall().

◆ getThisPointeeStorageLocation() [1/2]

RecordStorageLocation * clang::dataflow::Environment::getThisPointeeStorageLocation ( ) const
inline

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.

If you want to look up the storage location for a specific CXXThisExpr, use the overload that takes a CXXThisExpr.

Definition at line 365 of file DataflowEnvironment.h.

Referenced by clang::dataflow::builtinTransferInitializer(), and initialize().

◆ getThisPointeeStorageLocation() [2/2]

RecordStorageLocation * clang::dataflow::Environment::getThisPointeeStorageLocation ( const CXXThisExpr & ThisExpr) const
inline

Returns the storage location assigned to the this pointee in the environment given a specific CXXThisExpr.

Returns null if the this pointee has no assigned storage location in the environment. Note that this can be used in a non-member context, e.g.:

struct S {
int x;
int y = this->x;
};
int foo() {
return S{10}.y; // will have a `this` for initializing `S::y`.
}

Definition at line 384 of file DataflowEnvironment.h.

◆ getValue() [1/3]

Value * clang::dataflow::Environment::getValue ( const Expr & E) const

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

Definition at line 1066 of file DataflowEnvironment.cpp.

References clang::Expr::getType(), getValue(), clang::dataflow::ignoreCFGOmittedNodes(), clang::Expr::isPRValue(), clang::Type::isRecordType(), and clang::nullptr.

◆ getValue() [2/3]

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

◆ getValue() [3/3]

Value * clang::dataflow::Environment::getValue ( const ValueDecl & D) const

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

Requirements:

D must not have record type.

Definition at line 1059 of file DataflowEnvironment.cpp.

References getStorageLocation(), and getValue().

◆ initialize()

void clang::dataflow::Environment::initialize ( )

Assigns storage locations and values to all parameters, captures, global variables, fields and functions referenced in the Stmt or FunctionDecl passed to the constructor.

If no Stmt or FunctionDecl was supplied, this function does nothing.

Definition at line 590 of file DataflowEnvironment.cpp.

References clang::cast(), createObject(), createStorageLocation(), clang::Decl::getASTContext(), clang::ASTContext::getCanonicalTagType(), clang::DeclContext::getParent(), clang::dataflow::getReferencedDecls(), getThisPointeeStorageLocation(), initializeFieldsWithValues(), clang::isa(), setStorageLocation(), setThisPointeeStorageLocation(), and clang::T.

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

◆ initializeFieldsWithValues() [1/2]

void clang::dataflow::Environment::initializeFieldsWithValues ( RecordStorageLocation & Loc)
inline

◆ initializeFieldsWithValues() [2/2]

void clang::dataflow::Environment::initializeFieldsWithValues ( RecordStorageLocation & Loc,
QualType Type )

Initializes the fields (including synthetic fields) of Loc with values, unless values of the field type are not supported or we hit one of the limits at which we stop producing values.

If a field already has a value, that value is preserved. If Type is provided, initializes only those fields that are modeled for Type; this is intended for use in cases where Loc is a derived type and we only want to initialize the fields of a base type.

Definition at line 1027 of file DataflowEnvironment.cpp.

References initializeFieldsWithValues(), and clang::dataflow::MaxCompositeValueSize.

Referenced by initialize(), initializeFieldsWithValues(), and initializeFieldsWithValues().

◆ join()

Environment clang::dataflow::Environment::join ( const Environment & EnvA,
const Environment & EnvB,
Environment::ValueModel & Model,
ExprJoinBehavior ExprBehavior )
static

Joins two environments 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 EnvA and EnvB are merged using Model.

Requirements:

EnvA and EnvB must use the same DataflowAnalysisContext.

Definition at line 875 of file DataflowEnvironment.cpp.

References Environment(), clang::Func, getCurrentFunc(), clang::dataflow::intersectDeclToLoc(), clang::dataflow::joinExprMaps(), clang::dataflow::DataflowAnalysisContext::joinFlowConditions(), clang::dataflow::joinLocToVal(), joinValues(), and KeepExprState.

◆ joinValues()

Value * clang::dataflow::Environment::joinValues ( QualType Ty,
Value * Val1,
const Environment & Env1,
Value * Val2,
const Environment & Env2,
Environment & JoinedEnv,
Environment::ValueModel & Model )
static

Returns a value that approximates both Val1 and Val2, or null if no such value can be produced.

Env1 and Env2 can be used to query child values and path condition implications of Val1 and Val2 respectively. The joined value will be produced in JoinedEnv.

Requirements:

Val1 and Val2 must model values of type Type.

Definition at line 929 of file DataflowEnvironment.cpp.

References clang::dataflow::areEquivalentValues(), Environment(), and clang::dataflow::joinDistinctValues().

Referenced by join(), and clang::dataflow::joinLocToVal().

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

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

Referenced by makeAnd().

◆ makeAtomicBoolValue()

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

References arena(), clang::dataflow::BoolValue::formula(), and clang::dataflow::Arena::makeBoolValue().

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

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

References arena(), clang::dataflow::BoolValue::formula(), and clang::dataflow::Arena::makeBoolValue().

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

References arena(), clang::dataflow::BoolValue::formula(), clang::dataflow::Arena::makeBoolValue(), and makeNot().

Referenced by makeNot().

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

References arena(), clang::dataflow::BoolValue::formula(), clang::dataflow::Arena::makeBoolValue(), and makeOr().

Referenced by makeOr().

◆ makeTopBoolValue()

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

Returns a unique instance of boolean Top.

Definition at line 612 of file DataflowEnvironment.h.

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

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

◆ operator=() [1/2]

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

References Environment(), and clang::Other.

◆ operator=() [2/2]

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

◆ popCall() [1/2]

void clang::dataflow::Environment::popCall ( const CallExpr * Call,
const Environment & CalleeEnv )

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

Definition at line 778 of file DataflowEnvironment.cpp.

References clang::Call, Environment(), setStorageLocation(), and setValue().

◆ popCall() [2/2]

void clang::dataflow::Environment::popCall ( const CXXConstructExpr * Call,
const Environment & CalleeEnv )

Definition at line 798 of file DataflowEnvironment.cpp.

References clang::Call, and Environment().

◆ proves()

bool clang::dataflow::Environment::proves ( const Formula & F) const

Returns true if the formula is always true when this point is reached.

Returns false if the formula may be false (or the flow condition isn't sufficiently precise to prove that it is true) or if the solver times out.

Note that there is an asymmetry between this function and allows() in that they both return false if the solver times out. The assumption is that if proves() or allows() returns true, this will result in a diagnostic, and we want to bias towards false negatives in the case where the solver times out.

Definition at line 1256 of file DataflowEnvironment.cpp.

Referenced by clang::dataflow::statusor_model::isSafeUnwrap(), and clang::dataflow::widenDistinctValues().

◆ 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 714 of file DataflowEnvironment.cpp.

References clang::Call, clang::cast(), Environment(), getResultObjectLocation(), getStorageLocation(), and clang::isa().

◆ pushCall() [2/2]

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

Definition at line 736 of file DataflowEnvironment.cpp.

References clang::Call, Environment(), and getResultObjectLocation().

◆ removeDecl()

void clang::dataflow::Environment::removeDecl ( const ValueDecl & D)

Removes the location assigned to D in the environment (if any).

Definition at line 986 of file DataflowEnvironment.cpp.

◆ setReturnStorageLocation()

void clang::dataflow::Environment::setReturnStorageLocation ( StorageLocation * Loc)
inline

Sets the storage location for the reference returned by the function currently being analyzed.

Requirements: The current analysis target must be a function and must have a reference return type.

Definition at line 457 of file DataflowEnvironment.h.

References getCurrentFunc().

◆ setReturnValue()

void clang::dataflow::Environment::setReturnValue ( Value * Val)
inline

Sets the return value of the function currently being analyzed.

Requirements: The current analysis target must be a function and must have a non-reference return type.

Definition at line 445 of file DataflowEnvironment.h.

References getCurrentFunc().

◆ setStorageLocation() [1/2]

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

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

Requirements:

E must not be assigned a storage location in the environment. E must be a glvalue or a BuiltinType::BuiltinFn

Definition at line 988 of file DataflowEnvironment.cpp.

References clang::Expr::getType(), clang::dataflow::ignoreCFGOmittedNodes(), clang::Expr::isGLValue(), and clang::Type::isSpecificBuiltinType().

◆ 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 already have a storage location in the environment.

Definition at line 965 of file DataflowEnvironment.cpp.

References createStorageLocation(), clang::ValueDecl::getType(), clang::isa(), and clang::Type::isReferenceType().

Referenced by initialize(), popCall(), and clang::dataflow::propagateStorageLocation().

◆ setThisPointeeStorageLocation()

void clang::dataflow::Environment::setThisPointeeStorageLocation ( RecordStorageLocation & Loc)
inline

Sets the storage location assigned to the this pointee in the environment.

Definition at line 393 of file DataflowEnvironment.h.

Referenced by initialize().

◆ setValue() [1/2]

void clang::dataflow::Environment::setValue ( const Expr & E,
Value & Val )

Assigns Val as the value of the prvalue E in the environment.

Requirements:

  • E must be a prvalue.
  • E must not have record type.

Definition at line 1044 of file DataflowEnvironment.cpp.

References clang::Expr::getType(), clang::dataflow::ignoreCFGOmittedNodes(), clang::Expr::isPRValue(), and clang::Type::isRecordType().

◆ setValue() [2/2]

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

◆ widen()

LatticeEffect clang::dataflow::Environment::widen ( const Environment & PrevEnv,
Environment::ValueModel & Model )

Widens the environment point-wise, using PrevEnv as needed to inform the approximation.

Requirements:

PrevEnv must be the immediate previous version of the environment. PrevEnv and this must use the same DataflowAnalysisContext.

Definition at line 836 of file DataflowEnvironment.cpp.

References clang::dataflow::Changed, Environment(), clang::dataflow::Unchanged, and clang::dataflow::widenKeyToValueMap().

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


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