clang 17.0.0git
Public Member Functions | Static Public Member Functions | List of all members
clang::dataflow::UncheckedOptionalAccessModel Class Reference

Dataflow analysis that models whether optionals hold values or not. More...

#include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h"

Inheritance diagram for clang::dataflow::UncheckedOptionalAccessModel:
Inheritance graph
[legend]
Collaboration diagram for clang::dataflow::UncheckedOptionalAccessModel:
Collaboration graph
[legend]

Public Member Functions

 UncheckedOptionalAccessModel (ASTContext &Ctx)
 
void transfer (const CFGElement &Elt, NoopLattice &L, Environment &Env)
 
ComparisonResult compare (QualType Type, const Value &Val1, const Environment &Env1, const Value &Val2, const Environment &Env2) override
 Returns: Same: Val1 is equivalent to Val2, according to the model.
 
bool merge (QualType Type, const Value &Val1, const Environment &Env1, const Value &Val2, const Environment &Env2, Value &MergedVal, Environment &MergedEnv) override
 Modifies MergedVal to approximate both Val1 and Val2.
 
Valuewiden (QualType Type, Value &Prev, const Environment &PrevEnv, Value &Current, Environment &CurrentEnv) override
 This function may widen the current value – replace it with an approximation that can reach a fixed point more quickly than iterated application of the transfer function alone.
 
- Public Member Functions inherited from clang::dataflow::DataflowAnalysis< UncheckedOptionalAccessModel, NoopLattice >
 DataflowAnalysis (ASTContext &Context)
 
 DataflowAnalysis (ASTContext &Context, bool ApplyBuiltinTransfer)
 Deprecated. Use the DataflowAnalysisOptions constructor instead.
 
 DataflowAnalysis (ASTContext &Context, DataflowAnalysisOptions Options)
 
ASTContextgetASTContext () final
 Returns the ASTContext that is used by the analysis.
 
TypeErasedLattice typeErasedInitialElement () final
 Returns a type-erased lattice element that models the initial state of a basic block.
 
LatticeJoinEffect joinTypeErased (TypeErasedLattice &E1, const TypeErasedLattice &E2) final
 Joins two type-erased lattice elements by computing their least upper bound.
 
LatticeJoinEffect widenTypeErased (TypeErasedLattice &Current, const TypeErasedLattice &Previous) final
 Chooses a lattice element that approximates the current element at a program point, given the previous element at that point.
 
bool isEqualTypeErased (const TypeErasedLattice &E1, const TypeErasedLattice &E2) final
 Returns true if and only if the two given type-erased lattice elements are equal.
 
void transferTypeErased (const CFGElement &Element, TypeErasedLattice &E, Environment &Env) final
 Applies the analysis transfer function for a given control flow graph element and type-erased lattice element.
 
void transferBranchTypeErased (bool Branch, const Stmt *Stmt, TypeErasedLattice &E, Environment &Env) final
 Applies the analysis transfer function for a given edge from a CFG block of a conditional statement.
 
- Public Member Functions inherited from clang::dataflow::TypeErasedDataflowAnalysis
 TypeErasedDataflowAnalysis ()
 
 TypeErasedDataflowAnalysis (DataflowAnalysisOptions Options)
 
virtual ~TypeErasedDataflowAnalysis ()
 
virtual ASTContextgetASTContext ()=0
 Returns the ASTContext that is used by the analysis.
 
virtual TypeErasedLattice typeErasedInitialElement ()=0
 Returns a type-erased lattice element that models the initial state of a basic block.
 
virtual LatticeJoinEffect joinTypeErased (TypeErasedLattice &, const TypeErasedLattice &)=0
 Joins two type-erased lattice elements by computing their least upper bound.
 
virtual LatticeJoinEffect widenTypeErased (TypeErasedLattice &Current, const TypeErasedLattice &Previous)=0
 Chooses a lattice element that approximates the current element at a program point, given the previous element at that point.
 
virtual bool isEqualTypeErased (const TypeErasedLattice &, const TypeErasedLattice &)=0
 Returns true if and only if the two given type-erased lattice elements are equal.
 
virtual void transferTypeErased (const CFGElement &, TypeErasedLattice &, Environment &)=0
 Applies the analysis transfer function for a given control flow graph element and type-erased lattice element.
 
virtual void transferBranchTypeErased (bool Branch, const Stmt *, TypeErasedLattice &, Environment &)=0
 Applies the analysis transfer function for a given edge from a CFG block of a conditional statement.
 
const std::optional< DataflowAnalysisContext::Options > & builtinOptions () const
 If the built-in model is enabled, returns the options to be passed to them.
 
- Public Member Functions inherited from clang::dataflow::Environment::ValueModel
virtual ~ValueModel ()=default
 
virtual ComparisonResult compare (QualType Type, const Value &Val1, const Environment &Env1, const Value &Val2, const Environment &Env2)
 Returns: Same: Val1 is equivalent to Val2, according to the model.
 
virtual bool merge (QualType Type, const Value &Val1, const Environment &Env1, const Value &Val2, const Environment &Env2, Value &MergedVal, Environment &MergedEnv)
 Modifies MergedVal to approximate both Val1 and Val2.
 
virtual Valuewiden (QualType Type, Value &Prev, const Environment &PrevEnv, Value &Current, Environment &CurrentEnv)
 This function may widen the current value – replace it with an approximation that can reach a fixed point more quickly than iterated application of the transfer function alone.
 

Static Public Member Functions

static ast_matchers::DeclarationMatcher optionalClassDecl ()
 Returns a matcher for the optional classes covered by this model.
 
static NoopLattice initialElement ()
 

Additional Inherited Members

- Public Types inherited from clang::dataflow::DataflowAnalysis< UncheckedOptionalAccessModel, NoopLattice >
using Lattice = NoopLattice
 Bounded join-semilattice that is used in the analysis.
 

Detailed Description

Dataflow analysis that models whether optionals hold values or not.

Models the std::optional, absl::optional, and base::Optional types.

Definition at line 45 of file UncheckedOptionalAccessModel.h.

Constructor & Destructor Documentation

◆ UncheckedOptionalAccessModel()

clang::dataflow::UncheckedOptionalAccessModel::UncheckedOptionalAccessModel ( ASTContext Ctx)

Definition at line 831 of file UncheckedOptionalAccessModel.cpp.

Member Function Documentation

◆ compare()

ComparisonResult clang::dataflow::UncheckedOptionalAccessModel::compare ( QualType  Type,
const Value Val1,
const Environment Env1,
const Value Val2,
const Environment Env2 
)
overridevirtual

Returns: Same: Val1 is equivalent to Val2, according to the model.

Different: Val1 is distinct from Val2, according to the model. Unknown: The model can't determine a relationship between Val1 and Val2.

Requirements:

Val1 and Val2 must be distinct.

Val1 and Val2 must model values of type Type.

Val1 and Val2 must be assigned to the same storage location in Env1 and Env2 respectively.

Reimplemented from clang::dataflow::Environment::ValueModel.

Definition at line 841 of file UncheckedOptionalAccessModel.cpp.

References clang::dataflow::Different, clang::dataflow::Same, and clang::dataflow::Unknown.

Referenced by widen().

◆ initialElement()

static NoopLattice clang::dataflow::UncheckedOptionalAccessModel::initialElement ( )
inlinestatic

Definition at line 53 of file UncheckedOptionalAccessModel.h.

◆ merge()

bool clang::dataflow::UncheckedOptionalAccessModel::merge ( QualType  Type,
const Value Val1,
const Environment Env1,
const Value Val2,
const Environment Env2,
Value MergedVal,
Environment MergedEnv 
)
overridevirtual

Modifies MergedVal to approximate both Val1 and Val2.

This could be a strict lattice join or a more general widening operation.

If this function returns true, MergedVal will be assigned to a storage location of type Type in MergedEnv.

Env1 and Env2 can be used to query child values and path condition implications of Val1 and Val2 respectively.

Requirements:

Val1 and Val2 must be distinct.

Val1, Val2, and MergedVal must model values of type Type.

Val1 and Val2 must be assigned to the same storage location in Env1 and Env2 respectively.

Reimplemented from clang::dataflow::Environment::ValueModel.

Definition at line 858 of file UncheckedOptionalAccessModel.cpp.

References clang::dataflow::Environment::addToFlowCondition(), clang::dataflow::Environment::makeAtomicBoolValue(), and clang::dataflow::Environment::makeNot().

◆ optionalClassDecl()

ast_matchers::DeclarationMatcher clang::dataflow::UncheckedOptionalAccessModel::optionalClassDecl ( )
static

Returns a matcher for the optional classes covered by this model.

Definition at line 827 of file UncheckedOptionalAccessModel.cpp.

◆ transfer()

void clang::dataflow::UncheckedOptionalAccessModel::transfer ( const CFGElement Elt,
NoopLattice L,
Environment Env 
)

◆ widen()

Value * clang::dataflow::UncheckedOptionalAccessModel::widen ( QualType  Type,
Value Prev,
const Environment PrevEnv,
Value Current,
Environment CurrentEnv 
)
overridevirtual

This function may widen the current value – replace it with an approximation that can reach a fixed point more quickly than iterated application of the transfer function alone.

The previous value is provided to inform the choice of widened value. The function must also serve as a comparison operation, by indicating whether the widened value is equivalent to the previous value.

Returns either:

nullptr, if this value is not of interest to the model, or

&Prev, if the widened value is equivalent to Prev, or

A non-null value that approximates Current. Prev is available to inform the chosen approximation.

PrevEnv and CurrentEnv can be used to query child values and path condition implications of Prev and Current, respectively.

Requirements:

Prev and Current must model values of type Type.

Prev and Current must be assigned to the same storage location in PrevEnv and CurrentEnv, respectively.

Reimplemented from clang::dataflow::Environment::ValueModel.

Definition at line 883 of file UncheckedOptionalAccessModel.cpp.

References compare(), clang::dataflow::Different, clang::dataflow::Value::getProperty(), clang::dataflow::Environment::makeTopBoolValue(), clang::dataflow::Same, and clang::dataflow::Unknown.


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