clang  16.0.0git
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::ento::SVal Class Reference

SVal - This represents a symbolic expression, which can be either an L-value or an R-value. More...

#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"

Inheritance diagram for clang::ento::SVal:
Inheritance graph
[legend]
Collaboration diagram for clang::ento::SVal:
Collaboration graph
[legend]

Public Types

enum  BaseKind
 
enum  { BaseBits = 2, BaseMask = 0b11 }
 

Public Member Functions

 SVal ()=default
 
template<typename T >
castAs () const
 Convert to the specified SVal type, asserting that this SVal is of the desired type. More...
 
template<typename T >
Optional< T > getAs () const
 Convert to the specified SVal type, returning None if this SVal is not of the desired type. More...
 
unsigned getRawKind () const
 
BaseKind getBaseKind () const
 
unsigned getSubKind () const
 
void Profile (llvm::FoldingSetNodeID &ID) const
 
bool operator== (SVal R) const
 
bool operator!= (SVal R) const
 
bool isUnknown () const
 
bool isUndef () const
 
bool isUnknownOrUndef () const
 
bool isValid () const
 
bool isConstant () const
 
bool isConstant (int I) const
 
bool isZeroConstant () const
 
const FunctionDeclgetAsFunctionDecl () const
 getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl, return that FunctionDecl. More...
 
SymbolRef getAsLocSymbol (bool IncludeBaseRegions=false) const
 If this SVal is a location and wraps a symbol, return that SymbolRef. More...
 
SymbolRef getLocSymbolInBase () const
 Get the symbol in the SVal or its base region. More...
 
SymbolRef getAsSymbol (bool IncludeBaseRegions=false) const
 If this SVal wraps a symbol return that SymbolRef. More...
 
const llvm::APSIntgetAsInteger () const
 If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in it. More...
 
const MemRegiongetAsRegion () const
 
void printJson (raw_ostream &Out, bool AddQuotes) const
 printJson - Pretty-prints in JSON format. More...
 
void dumpToStream (raw_ostream &OS) const
 
void dump () const
 
SymExpr::symbol_iterator symbol_begin () const
 
SymExpr::symbol_iterator symbol_end () const
 
QualType getType (const ASTContext &) const
 Try to get a reasonable type for the given value. More...
 

Protected Member Functions

 SVal (const void *d, bool isLoc, unsigned ValKind)
 
 SVal (BaseKind k, const void *D=nullptr)
 

Protected Attributes

const void * Data = nullptr
 
unsigned Kind = 0
 The lowest 2 bits are a BaseKind (0 – 3). More...
 

Detailed Description

SVal - This represents a symbolic expression, which can be either an L-value or an R-value.

Definition at line 73 of file SVals.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
BaseBits 
BaseMask 

Definition at line 81 of file SVals.h.

◆ BaseKind

Definition at line 75 of file SVals.h.

Constructor & Destructor Documentation

◆ SVal() [1/3]

clang::ento::SVal::SVal ( const void *  d,
bool  isLoc,
unsigned  ValKind 
)
inlineexplicitprotected

Definition at line 90 of file SVals.h.

◆ SVal() [2/3]

clang::ento::SVal::SVal ( BaseKind  k,
const void *  D = nullptr 
)
inlineexplicitprotected

Definition at line 93 of file SVals.h.

◆ SVal() [3/3]

clang::ento::SVal::SVal ( )
explicitdefault

Member Function Documentation

◆ castAs()

template<typename T >
T clang::ento::SVal::castAs ( ) const
inline

◆ dump()

LLVM_DUMP_METHOD void SVal::dump ( ) const

Definition at line 269 of file SVals.cpp.

◆ dumpToStream()

void SVal::dumpToStream ( raw_ostream &  OS) const

Definition at line 280 of file SVals.cpp.

◆ getAs()

template<typename T >
Optional<T> clang::ento::SVal::getAs ( ) const
inline

◆ getAsFunctionDecl()

const FunctionDecl * SVal::getAsFunctionDecl ( ) const

getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl, return that FunctionDecl.

Otherwise return 0.

Definition at line 46 of file SVals.cpp.

References clang::ento::MemRegion::getAs(), and clang::tooling::X().

Referenced by clang::ento::CheckerContext::getCalleeDecl(), clang::ento::SimpleFunctionCall::getDecl(), and clang::ento::CXXInstanceCall::getDecl().

◆ getAsInteger()

const llvm::APSInt * SVal::getAsInteger ( ) const

If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in it.

Otherwise, return nullptr.

Definition at line 112 of file SVals.cpp.

Referenced by clang::ento::ExprEngine::ProcessAutomaticObjDtor(), clang::ento::ExprEngine::ProcessDeleteDtor(), and clang::ento::ExprEngine::ProcessMemberDtor().

◆ getAsLocSymbol()

SymbolRef SVal::getAsLocSymbol ( bool  IncludeBaseRegions = false) const

If this SVal is a location and wraps a symbol, return that SymbolRef.

If this SVal is a location (subclasses Loc) and wraps a symbol, return that SymbolRef.

Otherwise return 0.

Casts are ignored during lookup.

Parameters
IncludeBaseRegionsThe boolean that controls whether the search should continue to the base regions if the region is not symbolic.

Otherwise return 0.

Implicit casts (ex: void* -> char*) can turn Symbolic region into Element region. If that is the case, gets the underlining region. When IncludeBaseRegions is set to true and the SubRegion is non-symbolic, the first symbolic parent region is returned.

Definition at line 68 of file SVals.cpp.

References getAsRegion(), and clang::ento::MemRegion::getSymbolicBase().

Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkPostCall(), getAsSymbol(), clang::ento::StackHintGeneratorForSymbol::getMessage(), clang::ento::StoreManager::FindUniqueBinding::HandleBinding(), VarBindingsCollector::HandleBinding(), and updateOutParameters().

◆ getAsRegion()

const MemRegion * SVal::getAsRegion ( ) const

◆ getAsSymbol()

SymbolRef SVal::getAsSymbol ( bool  IncludeBaseRegions = false) const

If this SVal wraps a symbol return that SymbolRef.

Otherwise, return 0.

Casts are ignored during lookup.

Parameters
IncludeBaseRegionsThe boolean that controls whether the search should continue to the base regions if the region is not symbolic.

Definition at line 104 of file SVals.cpp.

References getAsLocSymbol(), and clang::tooling::X().

Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), clang::ento::SValBuilder::evalIntegralCast(), GetAllocationSite(), clang::ento::iterator::getIteratorPosition(), clang::ento::SValBuilder::makeSymExprValNN(), clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined(), clang::ento::ScanReachableSymbols::scan(), clang::ento::iterator::setIteratorPosition(), clang::ento::simplify(), and symbol_begin().

◆ getBaseKind()

BaseKind clang::ento::SVal::getBaseKind ( ) const
inline

Definition at line 109 of file SVals.h.

References BaseMask, and Kind.

◆ getLocSymbolInBase()

SymbolRef SVal::getLocSymbolInBase ( ) const

Get the symbol in the SVal or its base region.

Definition at line 80 of file SVals.cpp.

References clang::tooling::X().

◆ getRawKind()

unsigned clang::ento::SVal::getRawKind ( ) const
inline

Definition at line 108 of file SVals.h.

References Kind.

Referenced by isUndef(), isUnknown(), isUnknownOrUndef(), isValid(), operator==(), and Profile().

◆ getSubKind()

unsigned clang::ento::SVal::getSubKind ( ) const
inline

Definition at line 110 of file SVals.h.

References BaseBits, and Kind.

◆ getType()

QualType SVal::getType ( const ASTContext Context) const

Try to get a reasonable type for the given value.

Returns
The best approximation of the value type or Null. In theory, all symbolic values should be typed, but this function is still a WIP and might have a few blind spots.
Note
This function should not be used when the user has access to the bound expression AST node as well, since AST always has exact types.
Loc values are interpreted as pointer rvalues for the purposes of this method.

Definition at line 184 of file SVals.cpp.

Referenced by clang::ento::iterator::advancePosition(), and clang::ento::ExprEngine::processCallExit().

◆ isConstant() [1/2]

bool SVal::isConstant ( ) const

◆ isConstant() [2/2]

bool SVal::isConstant ( int  I) const

Definition at line 253 of file SVals.cpp.

◆ isUndef()

bool clang::ento::SVal::isUndef ( ) const
inline

◆ isUnknown()

bool clang::ento::SVal::isUnknown ( ) const
inline

◆ isUnknownOrUndef()

bool clang::ento::SVal::isUnknownOrUndef ( ) const
inline

◆ isValid()

bool clang::ento::SVal::isValid ( ) const
inline

◆ isZeroConstant()

bool SVal::isZeroConstant ( ) const

◆ operator!=()

bool clang::ento::SVal::operator!= ( SVal  R) const
inline

Definition at line 123 of file SVals.h.

◆ operator==()

bool clang::ento::SVal::operator== ( SVal  R) const
inline

Definition at line 119 of file SVals.h.

References Data, and getRawKind().

◆ printJson()

void SVal::printJson ( raw_ostream &  Out,
bool  AddQuotes 
) const

printJson - Pretty-prints in JSON format.

Definition at line 271 of file SVals.cpp.

◆ Profile()

void clang::ento::SVal::Profile ( llvm::FoldingSetNodeID &  ID) const
inline

Definition at line 114 of file SVals.h.

References Data, and getRawKind().

Referenced by clang::ento::BasicValueFactory::getPersistentSValPair().

◆ symbol_begin()

SymExpr::symbol_iterator clang::ento::SVal::symbol_begin ( ) const
inline

Definition at line 184 of file SVals.h.

References getAsSymbol(), and clang::ento::SymExpr::symbol_begin().

◆ symbol_end()

SymExpr::symbol_iterator clang::ento::SVal::symbol_end ( ) const
inline

Definition at line 192 of file SVals.h.

References clang::ento::SymExpr::symbol_end().

Member Data Documentation

◆ Data

const void* clang::ento::SVal::Data = nullptr
protected

◆ Kind

unsigned clang::ento::SVal::Kind = 0
protected

The lowest 2 bits are a BaseKind (0 – 3).

The higher bits are an unsigned "kind" value.

Definition at line 88 of file SVals.h.

Referenced by getBaseKind(), getRawKind(), and getSubKind().


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