class Environment

Declaration

class Environment { /* full declaration omitted */ };

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:56

Member Variables

private clang::dataflow::DataflowAnalysisContext* DACtx
private llvm::DenseMap<const ValueDecl*, StorageLocation*> DeclToLoc
private llvm::DenseMap<const Expr*, StorageLocation*> ExprToLoc
private llvm::DenseMap<const StorageLocation*, Value*> LocToVal
private llvm::DenseMap< const StorageLocation*, std::pair<StructValue*, const ValueDecl*>> MemberLocToStruct
private clang::dataflow::AtomicBoolValue* FlowConditionToken

Method Overview

  • public Environment(const clang::dataflow::Environment & Other)
  • public Environment(clang::dataflow::Environment && Other)
  • public Environment(clang::dataflow::DataflowAnalysisContext & DACtx, const clang::DeclContext & DeclCtx)
  • public Environment(clang::dataflow::DataflowAnalysisContext & DACtx)
  • public void addToFlowCondition(clang::dataflow::BoolValue & Val)
  • public clang::dataflow::BoolValue & buildAndSubstituteFlowCondition(clang::dataflow::AtomicBoolValue & Token, llvm::DenseMap<AtomicBoolValue *, BoolValue *> Substitutions)
  • public clang::dataflow::StorageLocation & createStorageLocation(clang::QualType Type)
  • public clang::dataflow::StorageLocation & createStorageLocation(const clang::VarDecl & D)
  • public clang::dataflow::StorageLocation & createStorageLocation(const clang::Expr & E)
  • public clang::dataflow::Value * createValue(clang::QualType Type)
  • private clang::dataflow::Value * createValueUnlessSelfReferential(clang::QualType Type, llvm::DenseSet<QualType> & Visited, int Depth, int & CreatedValuesCount)
  • public void dump() const
  • public bool equivalentTo(const clang::dataflow::Environment & Other, Environment::ValueModel & Model) const
  • public bool flowConditionImplies(clang::dataflow::BoolValue & Val) const
  • public clang::dataflow::AtomicBoolValue & getBoolLiteralValue(bool Value) const
  • public clang::dataflow::AtomicBoolValue & getFlowConditionToken() const
  • public clang::dataflow::PointerValue & getOrCreateNullPointerValue(clang::QualType PointeeType)
  • public clang::dataflow::StorageLocation * getStorageLocation(const clang::Expr & E, clang::dataflow::SkipPast SP) const
  • public clang::dataflow::StorageLocation * getStorageLocation(const clang::ValueDecl & D, clang::dataflow::SkipPast SP) const
  • public clang::dataflow::StorageLocation * getThisPointeeStorageLocation() const
  • public clang::dataflow::Value * getValue(const clang::ValueDecl & D, clang::dataflow::SkipPast SP) const
  • public clang::dataflow::Value * getValue(const clang::dataflow::StorageLocation & Loc) const
  • public clang::dataflow::Value * getValue(const clang::Expr & E, clang::dataflow::SkipPast SP) const
  • public clang::dataflow::LatticeJoinEffect join(const clang::dataflow::Environment & Other, Environment::ValueModel & Model)
  • public clang::dataflow::BoolValue & makeAnd(clang::dataflow::BoolValue & LHS, clang::dataflow::BoolValue & RHS) const
  • public clang::dataflow::BoolValue & makeAtomicBoolValue() const
  • public clang::dataflow::BoolValue & makeIff(clang::dataflow::BoolValue & LHS, clang::dataflow::BoolValue & RHS) const
  • public clang::dataflow::BoolValue & makeImplication(clang::dataflow::BoolValue & LHS, clang::dataflow::BoolValue & RHS) const
  • public clang::dataflow::BoolValue & makeNot(clang::dataflow::BoolValue & Val) const
  • public clang::dataflow::BoolValue & makeOr(clang::dataflow::BoolValue & LHS, clang::dataflow::BoolValue & RHS) const
  • public clang::dataflow::Environment pushCall(const clang::CallExpr * Call) const
  • public void setStorageLocation(const clang::Expr & E, clang::dataflow::StorageLocation & Loc)
  • public void setStorageLocation(const clang::ValueDecl & D, clang::dataflow::StorageLocation & Loc)
  • public void setValue(const clang::dataflow::StorageLocation & Loc, clang::dataflow::Value & Val)
  • private clang::dataflow::StorageLocation & skip(clang::dataflow::StorageLocation & Loc, clang::dataflow::SkipPast SP) const
  • private const clang::dataflow::StorageLocation & skip(const clang::dataflow::StorageLocation & Loc, clang::dataflow::SkipPast SP) const
  • public template <typename T>typename std::enable_if<std::is_base_of<StorageLocation, T>::value, T &>::type takeOwnership(std::unique_ptr<T> Loc)
  • public template <typename T>typename std::enable_if<std::is_base_of<Value, T>::value, T &>::type takeOwnership(std::unique_ptr<T> Val)

Methods

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:115

Parameters

const clang::dataflow::Environment& Other

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:118

Parameters

clang::dataflow::Environment&& Other

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:129

Parameters

clang::dataflow::DataflowAnalysisContext& DACtx
const clang::DeclContext& DeclCtx

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:113

Parameters

clang::dataflow::DataflowAnalysisContext& DACtx

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

Description

Adds `Val` to the set of clauses that constitute the flow condition.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:336

Parameters

clang::dataflow::BoolValue& Val

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:328

Parameters

clang::dataflow::AtomicBoolValue& Token
llvm::DenseMap<AtomicBoolValue*, BoolValue*> Substitutions

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:179

Parameters

clang::QualType Type

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:184

Parameters

const clang::VarDecl& D

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:189

Parameters

const clang::Expr& E

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:232

Parameters

clang::QualType Type

clang::dataflow::Value*
createValueUnlessSelfReferential(
    clang::QualType Type,
    llvm::DenseSet<QualType>& Visited,
    int Depth,
    int& CreatedValuesCount)

Description

Creates a value appropriate for `Type`, if `Type` is supported, otherwise return null. Recursively initializes storage locations and values until it sees a self-referential pointer or reference type. `Visited` is used to track which types appeared in the reference/pointer chain in order to avoid creating a cyclic dependency with self-referential pointers/references. Requirements: `Type` must not be null.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:356

Parameters

clang::QualType Type
llvm::DenseSet<QualType>& Visited
int Depth
int& CreatedValuesCount

void dump() const

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:342

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

Description

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`.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:156

Parameters

const clang::dataflow::Environment& Other
Environment::ValueModel& Model

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:340

Parameters

clang::dataflow::BoolValue& Val

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:275

Parameters

bool Value

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:323

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

Description

Returns a pointer value that represents a null pointer. Calls with `PointeeType` that are canonically equivalent will return the same result.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:222

Parameters

clang::QualType PointeeType

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:213

Parameters

const clang::Expr& E
clang::dataflow::SkipPast SP

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:201

Parameters

const clang::ValueDecl& D
clang::dataflow::SkipPast SP

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:218

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:243

Parameters

const clang::ValueDecl& D
clang::dataflow::SkipPast SP

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:239

Parameters

const clang::dataflow::StorageLocation& Loc

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

Description

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

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:247

Parameters

const clang::Expr& E
clang::dataflow::SkipPast SP

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

Description

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`.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:167

Parameters

const clang::dataflow::Environment& Other
Environment::ValueModel& Model

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:288

Parameters

clang::dataflow::BoolValue& LHS
clang::dataflow::BoolValue& RHS

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

Description

Returns an atomic boolean value.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:280

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:318

Parameters

clang::dataflow::BoolValue& LHS
clang::dataflow::BoolValue& RHS

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:310

Parameters

clang::dataflow::BoolValue& LHS
clang::dataflow::BoolValue& RHS

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

Description

Returns a boolean value that represents the negation of `Val`. Subsequent calls with the same argument will return the same result.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:302

Parameters

clang::dataflow::BoolValue& Val

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

Description

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.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:296

Parameters

clang::dataflow::BoolValue& LHS
clang::dataflow::BoolValue& RHS

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

Description

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` with a body. The body of the callee must not reference globals. The arguments of `Call` must map 1:1 to the callee's parameters. Each argument of `Call` must already have a `StorageLocation`.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:144

Parameters

const clang::CallExpr* Call

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

Description

Assigns `Loc` as the storage location of `E` in the environment. Requirements: `E` must not be assigned a storage location in the environment.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:208

Parameters

const clang::Expr& E
clang::dataflow::StorageLocation& Loc

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

Description

Assigns `Loc` as the storage location of `D` in the environment. Requirements: `D` must not be assigned a storage location in the environment.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:196

Parameters

const clang::ValueDecl& D
clang::dataflow::StorageLocation& Loc

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

Description

Assigns `Val` as the value of `Loc` in the environment.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:235

Parameters

const clang::dataflow::StorageLocation& Loc
clang::dataflow::Value& Val

clang::dataflow::StorageLocation& skip(
    clang::dataflow::StorageLocation& Loc,
    clang::dataflow::SkipPast SP) const

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:360

Parameters

clang::dataflow::StorageLocation& Loc
clang::dataflow::SkipPast SP

const clang::dataflow::StorageLocation& skip(
    const clang::dataflow::StorageLocation& Loc,
    clang::dataflow::SkipPast SP) const

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:361

Parameters

const clang::dataflow::StorageLocation& Loc
clang::dataflow::SkipPast SP

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

Description

Transfers ownership of `Loc` to the analysis context and returns a reference to it. Requirements: `Loc` must not be null.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:257

Templates

T

Parameters

std::unique_ptr<T> Loc

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

Description

Transfers ownership of `Val` to the analysis context and returns a reference to it. Requirements: `Val` must not be null.

Declared at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:269

Templates

T

Parameters

std::unique_ptr<T> Val