clang 22.0.0git
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:
[legend]

Public Types

enum  SValKind : unsigned char

Public Member Functions

 SVal ()=default
template<typename T>
T castAs () const
 Convert to the specified SVal type, asserting that this SVal is of the desired type.
template<typename T>
std::optional< TgetAs () const
 Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
SValKind getKind () const
StringRef getKindStr () 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.
SymbolRef getAsLocSymbol (bool IncludeBaseRegions=false) const
 If this SVal is a location and wraps a symbol, return that SymbolRef.
SymbolRef getLocSymbolInBase () const
 Get the symbol in the SVal or its base region.
SymbolRef getAsSymbol (bool IncludeBaseRegions=false) const
 If this SVal wraps a symbol return that SymbolRef.
const llvm::APSInt * getAsInteger () const
 If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in it.
const MemRegiongetAsRegion () const
void printJson (raw_ostream &Out, bool AddQuotes) const
 printJson - Pretty-prints in JSON format.
void dumpToStream (raw_ostream &OS) const
void dump () const
llvm::iterator_range< SymExpr::symbol_iteratorsymbols () const
QualType getType (const ASTContext &) const
 Try to get a reasonable type for the given value.

Protected Member Functions

 SVal (SValKind Kind, const void *Data=nullptr)
template<typename T>
const TcastDataAs () const

Protected Attributes

const void * Data = nullptr
SValKind Kind = UndefinedValKind

Detailed Description

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

Definition at line 56 of file SVals.h.

Member Enumeration Documentation

◆ SValKind

Definition at line 58 of file SVals.h.

Constructor & Destructor Documentation

◆ SVal() [1/2]

clang::ento::SVal::SVal ( SValKind Kind,
const void * Data = nullptr )
inlineexplicitprotected

◆ SVal() [2/2]

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

Member Function Documentation

◆ castAs()

◆ castDataAs()

◆ dump()

LLVM_DUMP_METHOD void SVal::dump ( ) const

Definition at line 282 of file SVals.cpp.

References dumpToStream().

◆ dumpToStream()

void SVal::dumpToStream ( raw_ostream & OS) const

Definition at line 293 of file SVals.cpp.

References castAs(), clang::ento::Loc::classof(), clang::ento::NonLoc::classof(), isUndef(), and isUnknown().

Referenced by dump(), and printJson().

◆ getAs()

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

Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.

Definition at line 87 of file SVals.h.

Referenced by clang::ento::iterator::advancePosition(), assumeCollectionNonEmpty(), clang::ento::iterator::assumeNoOverflow(), clang::ento::ProgramState::bindLoc(), calculateOffset(), checkCollectionNonNil(), checkValueAtLValForInvariantViolation(), collectSubRegionBindings(), compareValueToThreshold(), computeOffset(), clang::ento::SValBuilder::convertToArrayIndex(), clang::ento::CoreEngine::dispatchWorkItem(), clang::ento::SValBuilder::evalBinOp(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), clang::ento::SValBuilder::evalIntegralCast(), clang::ento::SValBuilder::evalUnaryOp(), getAsFunctionDecl(), getAsInteger(), getAsPointeeSymbol(), getAsRegion(), getAsSymbol(), getConcreteValue(), clang::ento::MemRegion::getDescriptiveName(), getFuchsiaHandleSymbols(), clang::ento::ExprEngine::getInitialState(), clang::ento::iterator::getIteratorPosition(), getLocSymbolInBase(), clang::ento::ProgramState::getLValue(), clang::ento::StackHintGeneratorForSymbol::getMessage(), getReceiverNullability(), getSimplifiedOffsets(), hasVisibleUpdate(), isConstant(), isConstant(), clang::ento::SValBuilder::makeSymExprValNN(), parameterTypeFromSVal(), populateObjCForDestinationSet(), clang::ento::ExprEngine::processSwitch(), REGISTER_MAP_WITH_PROGRAMSTATE(), clang::ento::ScanReachableSymbols::scan(), clang::ento::iterator::setIteratorPosition(), showBRDefaultDiagnostics(), showBRDiagnostics(), showBRParamDiagnostics(), timeTraceMetadata(), updateOutParameters(), clang::ento::ExprEngine::VisitCXXNewExpr(), and clang::ento::SValExplainer::VisitElementRegion().

◆ 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 45 of file SVals.cpp.

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

Referenced by clang::ento::CheckerContext::getCalleeDecl(), clang::ento::CXXInstanceCall::getDecl(), and clang::ento::SimpleFunctionCall::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 111 of file SVals.cpp.

References getAs().

◆ 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 67 of file SVals.cpp.

References getAsRegion().

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

◆ getAsRegion()

◆ getAsSymbol()

◆ getKind()

SValKind clang::ento::SVal::getKind ( ) const
inline

◆ getKindStr()

StringRef SVal::getKindStr ( ) const

Definition at line 265 of file SVals.cpp.

References getKind().

◆ getLocSymbolInBase()

SymbolRef SVal::getLocSymbolInBase ( ) const

Get the symbol in the SVal or its base region.

Definition at line 79 of file SVals.cpp.

References getAs(), and X.

◆ 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 180 of file SVals.cpp.

Referenced by clang::ento::iterator::advancePosition(), assertEqualBitWidths(), castArgToParamTypeIfNeeded(), checkParamsForPreconditionViolation(), checkSelfIvarsForInvariantViolation(), clang::ento::CXXInstanceCall::getCXXThisVal(), and clang::ento::ExprEngine::processCallExit().

◆ isConstant() [1/2]

bool SVal::isConstant ( ) const

◆ isConstant() [2/2]

bool SVal::isConstant ( int I) const

Definition at line 249 of file SVals.cpp.

References getAs().

◆ isUndef()

◆ isUnknown()

◆ isUnknownOrUndef()

◆ 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 103 of file SVals.h.

References SVal().

◆ operator==()

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

Definition at line 102 of file SVals.h.

References Data, Kind, and SVal().

◆ printJson()

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

printJson - Pretty-prints in JSON format.

Definition at line 284 of file SVals.cpp.

References dumpToStream(), and clang::JsonFormat().

◆ Profile()

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

Definition at line 97 of file SVals.h.

References Data, and getKind().

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

◆ symbols()

llvm::iterator_range< SymExpr::symbol_iterator > clang::ento::SVal::symbols ( ) const
inline

Definition at line 156 of file SVals.h.

References getAsSymbol().

Referenced by clang::ento::SymbolReaper::markElementIndicesLive().

Member Data Documentation

◆ Data

◆ Kind


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