clang 10.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:
[legend]
Collaboration diagram for clang::ento::SVal:
[legend]

## Public Types
enum | BaseKind
enum | { BaseBits = 2, BaseMask = 0x3 }

## 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. 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== (const SVal &R) const
bool | operator!= (const 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
bool | hasConjuredSymbol () const
| hasConjuredSymbol - If this SVal wraps a conjured symbol, return true; More...
const FunctionDecl * | getAsFunctionDecl () 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 SymExpr * | getAsSymbolicExpression () const
| getAsSymbolicExpression - If this Sval wraps a symbolic expression then return that expression. More...
const SymExpr * | getAsSymExpr () const
const MemRegion * | getAsRegion () 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

## 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 75 of file SVals.h.

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
BaseBits |
BaseMask |

Definition at line 83 of file SVals.h.

## ◆ BaseKind

enum clang::ento::SVal::BaseKind

Definition at line 77 of file SVals.h.

## Constructor & Destructor Documentation

## ◆ SVal() [1/3]

clang::ento::SVal::SVal | ( | const void * | d,
|  | bool | isLoc,
|  | unsigned | ValKind
| ) |  |
| inline explicit protected

Definition at line 92 of file SVals.h.

## ◆ SVal() [2/3]

clang::ento::SVal::SVal | ( | BaseKind | k,
|  | const void * | D = `nullptr`
| ) |  |
| inline explicit protected

Definition at line 95 of file SVals.h.

## ◆ SVal() [3/3]

clang::ento::SVal::SVal | ( |  | ) |
| explicit default

## Member Function Documentation

## ◆ castAs()

template<typename T >

T clang::ento::SVal::castAs | ( |  | ) | const
| inline

Convert to the specified SVal type, asserting that this SVal is of the desired type.

Definition at line 103 of file SVals.h.

Referenced by clang::ento::SimpleConstraintManager::assume(), clang::ento::ProgramState::assume(), clang::ento::ProgramState::assumeInBound(), clang::ento::SimpleConstraintManager::assumeInclusiveRange(), clang::ento::ProgramState::assumeInclusiveRange(), clang::ento::ProgramState::bindDefaultInitial(), clang::ento::ProgramState::bindDefaultZero(), clang::ento::ExprEngine::bindReturnValue(), clang::ento::StoreManager::CastRetrievedVal(), clang::ento::SValBuilder::convertToArrayIndex(), clang::ento::createSimpleSValBuilder(), clang::ento::ExprEngine::evalBind(), clang::ento::SValBuilder::evalBinOp(), clang::ento::ExprEngine::evalBinOp(), clang::ento::SValBuilder::evalCast(), clang::ento::ExprEngine::evalComplement(), clang::ento::SValBuilder::evalEQ(), clang::ento::SValBuilder::evalIntegralCast(), clang::ento::ExprEngine::evalLoad(), clang::ento::ExprEngine::evalMinus(), clang::ento::ExprEngine::getInitialState(), clang::ento::nonloc::LocAsInteger::getLoc(), clang::ento::nonloc::LocAsInteger::getPersistentLoc(), clang::ento::ExprEngine::ProcessAutomaticObjDtor(), clang::ento::ExprEngine::processBranch(), clang::ento::ExprEngine::processCallExit(), clang::ento::ExprEngine::processSwitch(), clang::ento::ExprEngine::VisitCallExpr(), clang::ento::ExprEngine::VisitCommonDeclRefExpr(), clang::ento::ExprEngine::VisitCXXNewAllocatorCall(), clang::ento::ExprEngine::VisitIncrementDecrementOperator(), clang::ento::ExprEngine::VisitObjCMessage(), and clang::ento::ExprEngine::VisitUnaryOperator().

## ◆ dump()

LLVM_DUMP_METHOD void SVal::dump | ( |  | ) | const

Definition at line 285 of file SVals.cpp.

References dumpToStream().

## ◆ dumpToStream()

void SVal::dumpToStream | ( | raw_ostream & | OS | ) | const

Definition at line 296 of file SVals.cpp.

References getBaseKind().

Referenced by dump(), clang::ento::operator<<(), and printJson().

## ◆ getAs()

template<typename T >

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

Convert to the specified SVal type, returning None if this SVal is not of the desired type.

Definition at line 111 of file SVals.h.

Referenced by clang::ento::iterator::advancePosition(), clang::ento::SimpleConstraintManager::assume(), clang::ento::ProgramState::assumeInclusiveRange(), clang::ento::ProgramState::bindLoc(), clang::ento::SMTConstraintManager::canReasonAbout(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::SValBuilder::convertToArrayIndex(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), clang::ento::CreateRangeConstraintManager(), clang::ento::createSimpleSValBuilder(), dereference(), DereferenceInfo::DereferenceInfo(), clang::ento::ExprEngine::evalBind(), clang::ento::SValBuilder::evalBinOp(), evalBinOpFieldRegionFieldRegion(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), clang::ento::SValBuilder::evalCast(), clang::ento::ExprEngine::evalEagerlyAssumeBinOpBifurcation(), clang::ento::ExprEngine::evalLoad(), clang::ento::FindUninitializedFields::FindUninitializedFields(), clang::ento::ElementRegion::getAsArrayOffset(), clang::ento::MemRegion::getDescriptiveName(), clang::ento::ExprEngine::getInitialState(), clang::ento::iterator::getIteratorPosition(), clang::ento::ProgramState::getLValue(), clang::ento::StoreManager::getLValueElement(), clang::ento::StackHintGeneratorForSymbol::getMessage(), clang::ento::ProgramState::getSValAsScalarOrLoc(), clang::ento::ProgramState::killBinding(), clang::ento::SValBuilder::makeSymExprValNN(), clang::ento::ExprEngine::processIndirectGoto(), clang::ento::ExprEngine::ProcessInitializer(), clang::ento::ExprEngine::processSwitch(), clang::ento::ScanReachableSymbols::scan(), clang::ento::iterator::setIteratorPosition(), updateOutParameters(), clang::ento::ExprEngine::VisitCast(), clang::ento::ExprEngine::VisitCXXConstructExpr(), clang::ento::ExprEngine::VisitCXXNewExpr(), clang::ento::SValExplainer::VisitElementRegion(), and clang::ento::ExprEngine::VisitGCCAsmStmt().

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

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

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

## ◆ 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

  IncludeBaseRegions | The 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 85 of file SVals.cpp.

References clang::ento::MemRegion::getSymbolicBase(), clang::ento::MemRegion::StripCasts(), and X.

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

## ◆ getAsRegion()

const MemRegion * SVal::getAsRegion | ( |  | ) | const

Definition at line 151 of file SVals.cpp.

References X.

Referenced by clang::ento::StoreManager::attemptDownCast(), clang::ento::ExprEngine::bindReturnValue(), clang::ento::StoreManager::CastRetrievedVal(), clang::ento::retaincountchecker::RetainCountChecker::checkBind(), clang::ento::mpi::MPIChecker::checkMissingWaits(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), dereference(), clang::ento::ExprEngine::evalCall(), clang::ento::SValBuilder::evalCast(), clang::ento::StoreManager::evalDerivedToBase(), clang::BlockCall::getBlockRegion(), getConstructedRegion(), clang::ento::ExprEngine::getInitialState(), clang::ento::PathSensitiveBugReport::getInterestingnessKind(), clang::ento::iterator::getIteratorPosition(), clang::ento::CallEvent::invalidateRegions(), clang::ento::ExprEngine::ProcessAutomaticObjDtor(), clang::ento::ExprEngine::ProcessBaseDtor(), clang::ento::ExprEngine::ProcessDeleteDtor(), clang::ento::ExprEngine::ProcessInitializer(), clang::ento::ExprEngine::ProcessTemporaryDtor(), clang::ento::ProgramStateManager::removeDeadBindingsFromEnvironmentAndStore(), clang::ento::iterator::setIteratorPosition(), updateOutParameters(), clang::ento::ExprEngine::VisitBlockExpr(), clang::ento::ExprEngine::VisitCXXConstructExpr(), and clang::ento::ExprEngine::VisitCXXNewExpr().

## ◆ 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

  IncludeBaseRegions | The boolean that controls whether the search should continue to the base regions if the region is not symbolic.

Definition at line 127 of file SVals.cpp.

References getAsLocSymbol(), and X.

Referenced by clang::ento::SimpleConstraintManager::assumeInclusiveRange(), clang::ento::StoreManager::CastRetrievedVal(), clang::ento::retaincountchecker::RetainCountChecker::checkPostStmt(), clang::ento::retaincountchecker::RetainCountChecker::checkSummary(), clang::ento::SValBuilder::evalCast(), getAsSymbolicExpression(), getAsSymExpr(), clang::ento::PathSensitiveBugReport::getInterestingnessKind(), clang::ento::iterator::getIteratorPosition(), clang::ento::ProgramState::getSValAsScalarOrLoc(), clang::ento::ProgramState::isNull(), clang::ento::retaincountchecker::RetainCountChecker::processObjCLiterals(), clang::ento::retaincountchecker::RetainCountChecker::processSummaryOfInlined(), clang::ento::ScanReachableSymbols::scan(), and clang::ento::iterator::setIteratorPosition().

## ◆ getAsSymbolicExpression()

const SymExpr * SVal::getAsSymbolicExpression | ( |  | ) | const

getAsSymbolicExpression - If this Sval wraps a symbolic expression then return that expression.

Otherwise return NULL.

Definition at line 137 of file SVals.cpp.

References getAsSymbol(), and X.

Referenced by clang::ento::SValBuilder::evalIntegralCast(), getAsSymExpr(), and clang::ento::ScanReachableSymbols::scan().

## ◆ getAsSymExpr()

const SymExpr * SVal::getAsSymExpr | ( |  | ) | const

Definition at line 144 of file SVals.cpp.

References getAsSymbol(), and getAsSymbolicExpression().

Referenced by clang::ento::SimpleConstraintManager::assume(), clang::ento::SimpleConstraintManager::assumeInclusiveRange(), and clang::ento::SValBuilder::makeSymExprValNN().

## ◆ getBaseKind()

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

Definition at line 118 of file SVals.h.

Referenced by dumpToStream(), and clang::ento::SValVisitor< SValExplainer, std::string >::Visit().

## ◆ getLocSymbolInBase()

SymbolRef SVal::getLocSymbolInBase | ( |  | ) | const

Get the symbol in the SVal or its base region.

Definition at line 101 of file SVals.cpp.

References X.

## ◆ getRawKind()

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

Definition at line 117 of file SVals.h.

Referenced by operator==().

## ◆ getSubKind()

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

Definition at line 119 of file SVals.h.

Referenced by clang::ento::SimpleConstraintManager::assume(), clang::ento::SimpleConstraintManager::assumeInclusiveRange(), clang::ento::StoreManager::CastRetrievedVal(), clang::ento::NonLoc::dumpToStream(), clang::ento::Loc::dumpToStream(), and clang::ento::SValVisitor< SValExplainer, std::string >::Visit().

## ◆ hasConjuredSymbol()

bool SVal::hasConjuredSymbol | ( |  | ) | const

hasConjuredSymbol - If this SVal wraps a conjured symbol, return true;

Definition at line 44 of file SVals.cpp.

## ◆ isConstant() [1/2]

bool SVal::isConstant | ( |  | ) | const

Definition at line 222 of file SVals.cpp.

Referenced by clang::ento::SValBuilder::evalCast(), clang::ento::ProgramState::isNull(), isZeroConstant(), and clang::ento::ExprEngine::VisitCast().

## ◆ isConstant() [2/2]

bool SVal::isConstant | ( | int | I | ) | const

Definition at line 226 of file SVals.cpp.

## ◆ isUndef()

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

Definition at line 140 of file SVals.h.

Referenced by DereferenceInfo::DereferenceInfo(), clang::ento::SValBuilder::evalBinOp(), clang::ento::ExprEngine::evalLoad(), clang::ento::ExprEngine::evalStore(), clang::ento::FindUninitializedFields::FindUninitializedFields(), clang::ento::ExprEngine::processSwitch(), clang::ento::ExprEngine::VisitCast(), and clang::ento::ExprEngine::VisitObjCMessage().

## ◆ isUnknown()

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

Definition at line 136 of file SVals.h.

Referenced by clang::ento::ProgramState::assume(), clang::ento::ProgramState::assumeInBound(), clang::ento::ProgramState::assumeInclusiveRange(), clang::ento::EnvironmentManager::bindExpr(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), DereferenceInfo::DereferenceInfo(), clang::ento::SValBuilder::evalBinOp(), clang::ento::retaincountchecker::RetainCountChecker::evalCall(), clang::ento::ExprEngine::evalLoad(), clang::ento::ExprEngine::getInitialState(), clang::ento::ExprEngine::handleLValueBitCast(), clang::ento::ExprEngine::processBranch(), clang::ento::ExprEngine::VisitBinaryOperator(), clang::ento::ExprEngine::VisitCast(), clang::ento::ExprEngine::VisitCXXNewExpr(), and clang::ento::ExprEngine::VisitDeclStmt().

## ◆ isUnknownOrUndef()

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

Definition at line 144 of file SVals.h.

Referenced by clang::ento::ProgramState::assumeInBound(), clang::ento::StoreManager::CastRetrievedVal(), clang::ento::SValBuilder::convertToArrayIndex(), clang::ento::ExprEngine::CreateCXXTemporaryObject(), clang::ento::SValBuilder::evalCast(), clang::ento::StoreManager::getLValueElement(), clang::ento::ExprEngine::processBranch(), clang::ento::ExprEngine::ProcessInitializer(), and clang::ento::ExprEngine::VisitUnaryOperator().

## ◆ isValid()

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

Definition at line 148 of file SVals.h.

References dump(), and clang::ento::OS.

Referenced by clang::ento::ExprEngine::evalBinOp(), clang::ento::ExprEngine::evalComplement(), clang::ento::ExprEngine::evalLoad(), and clang::ento::ExprEngine::evalMinus().

## ◆ isZeroConstant()

bool SVal::isZeroConstant | ( |  | ) | const

Definition at line 234 of file SVals.cpp.

References isConstant().

Referenced by clang::ento::SValBuilder::evalCast(), clang::ento::FieldRegion::getExtent(), clang::ento::ProgramState::isNull(), and clang::ento::ExprEngine::VisitCast().

## ◆ operator!=()

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

Definition at line 132 of file SVals.h.

## ◆ operator==()

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

Definition at line 128 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 287 of file SVals.cpp.

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

## ◆ Profile()

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

Definition at line 123 of file SVals.h.

Referenced by clang::ento::BasicValueFactory::getPersistentSValPair(), clang::ento::BasicValueFactory::getPersistentSValWithData(), and clang::ento::SymbolicRegion::Profile().

## ◆ symbol_begin()

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

Definition at line 199 of file SVals.h.

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

## ◆ symbol_end()

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

Definition at line 207 of file SVals.h.

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

## Member Data Documentation

## ◆ Data

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

Definition at line 86 of file SVals.h.

Referenced by clang::ento::nonloc::LazyCompoundVal::getRegion(), clang::ento::nonloc::LazyCompoundVal::getStore(), and operator==().

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

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

- include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
- lib/StaticAnalyzer/Core/SVals.cpp