Go to the documentation of this file.
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
21 #include "llvm/ADT/FoldingSet.h"
22 #include "llvm/ADT/ImmutableList.h"
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/Support/Casting.h"
36 class CXXBaseSpecifier;
42 class CompoundValData;
43 class LazyCompoundValData;
45 class PointerToMemberData;
47 class TypedValueRegion;
53 #define NONLOC_SVAL(Id, Parent) Id ## Kind,
54 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
63 #define LOC_SVAL(Id, Parent) Id ## Kind,
64 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
76 #define BASIC_SVAL(Id, Parent) Id ## Kind,
77 #define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind,
78 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
83 const void *
Data =
nullptr;
89 explicit SVal(
const void *d,
bool isLoc,
unsigned ValKind)
95 explicit SVal() =
default;
99 template <
typename T> T
castAs()
const {
return llvm::cast<T>(*
this); }
103 template <
typename T> std::optional<T>
getAs()
const {
104 return llvm::dyn_cast<T>(*
this);
178 void printJson(raw_ostream &Out,
bool AddQuotes)
const;
231 :
SVal(d, isLoc, ValKind) {}
267 explicit NonLoc(
unsigned SubKind,
const void *d)
283 explicit Loc(
unsigned SubKind,
const void *D)
312 LLVM_ATTRIBUTE_RETURNS_NONNULL
322 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == SymbolValKind;
338 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == ConcreteIntKind;
347 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
348 :
NonLoc(LocAsIntegerKind, &data) {
351 assert(data.first.getBaseKind() == LocKind &&
352 (data.first.getSubKind() == loc::MemRegionValKind ||
353 data.first.getSubKind() == loc::GotoLabelKind));
358 const std::pair<SVal, uintptr_t> *D =
359 static_cast<const std::pair<SVal, uintptr_t> *
>(
Data);
364 const std::pair<SVal, uintptr_t> *D =
365 static_cast<const std::pair<SVal, uintptr_t> *
>(
Data);
370 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == LocAsIntegerKind;
384 LLVM_ATTRIBUTE_RETURNS_NONNULL
389 using iterator = llvm::ImmutableList<SVal>::iterator;
395 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == CompoundValKind;
405 :
NonLoc(LazyCompoundValKind, D) {
410 LLVM_ATTRIBUTE_RETURNS_NONNULL
418 LLVM_ATTRIBUTE_RETURNS_NONNULL
422 return V.getBaseKind() == NonLocKind &&
423 V.getSubKind() == LazyCompoundValKind;
427 return V.getSubKind() == LazyCompoundValKind;
446 llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;
449 return PTMDataType::getFromOpaqueValue(
const_cast<void *
>(
Data));
456 template<
typename AdjustedDecl>
458 return dyn_cast_or_null<AdjustedDecl>(
getDecl());
461 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
467 return V.getBaseKind() == NonLocKind &&
468 V.getSubKind() == PointerToMemberKind;
472 return V.getSubKind() == PointerToMemberKind;
477 :
NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
499 return V.getBaseKind() == LocKind &&
V.getSubKind() == GotoLabelKind;
519 template <
typename REGION>
533 return V.getBaseKind() == LocKind &&
V.getSubKind() == MemRegionValKind;
536 static bool classof(
Loc V) {
return V.getSubKind() == MemRegionValKind; }
548 return V.getBaseKind() == LocKind &&
V.getSubKind() == ConcreteIntKind;
551 static bool classof(
Loc V) {
return V.getSubKind() == ConcreteIntKind; }
559 template <
typename To,
typename From>
562 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>
564 using Self = CastInfo<
566 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>;
570 static std::optional<To>
castFailed() {
return std::optional<To>{}; }
572 return *
static_cast<const To *
>(cast<::clang::ento::SVal>(&f));
575 if (!Self::isPossible(f))
576 return Self::castFailed();
582 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
bool isExpression() const
bool isUnknownOrUndef() const =delete
static bool isLocType(QualType T)
bool isRecordType() const
void dumpToStream(raw_ostream &OS) const
YAML serialization mapping.
bool operator==(SVal R) const
bool isBlockPointerType() const
SVal(const void *d, bool isLoc, unsigned ValKind)
void Profile(llvm::FoldingSetNodeID &ID) const
Iterator over symbols that the current symbol depends on.
static bool classof(Loc V)
const FunctionDecl * getAsFunctionDecl() const
getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl...
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
SymbolRef getLocSymbolInBase() const
Get the symbol in the SVal or its base region.
const MemRegion * getAsRegion() const
This represents a decl that may have a name.
const LabelDecl * getLabel() const
A (possibly-)qualified type.
bool isZeroConstant() const
static bool classof(NonLoc V)
KnownSVal(const DefinedSVal &V)
void printJson(raw_ostream &Out, bool AddQuotes) const
printJson - Pretty-prints in JSON format.
Value representing integer constant.
static bool classof(NonLoc V)
unsigned getNumBits() const
void dumpToStream(raw_ostream &Out) const
bool isNullMemberPointer() const
MemRegion - The root abstract class for all memory regions.
static bool classof(SVal V)
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
bool isReferenceType() const
static bool isCompoundType(QualType T)
static bool classof(SVal V)
virtual QualType getType() const =0
unsigned Kind
The lowest 2 bits are a BaseKind (0 – 3).
bool isNullPtrType() const
static std::optional< To > doCastIfPossible(const From &f)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LLVM_ATTRIBUTE_RETURNS_NONNULL CompoundValData * getValue() const
Kind
Sub-kinds for NonLoc values.
static bool classof(SVal V)
const void * getStore() const
It might return null.
Value representing pointer-to-member.
bool isVectorType() const
Represents the declaration of a label.
const PTMDataType getPTMData() const
const NamedDecl * getDecl() const
DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind)
llvm::ImmutableList< const CXXBaseSpecifier * >::iterator iterator
static bool classof(SVal V)
void dumpToStream(raw_ostream &Out) const
NonLoc(unsigned SubKind, const void *d)
bool isAnyComplexType() const
static bool classof(SVal V)
DefinedOrUnknownSVal(BaseKind k, void *D=nullptr)
static bool classof(SVal V)
Represents an SVal that is guaranteed to not be UnknownVal.
GotoLabel(const LabelDecl *Label)
DefinedSVal(const void *d, bool isLoc, unsigned ValKind)
static bool classof(Loc V)
llvm::PointerUnion< const NamedDecl *, const PointerToMemberData * > PTMDataType
bool isUnknown() const =delete
llvm::ImmutableList< SVal >::iterator iterator
bool isValid() const =delete
static bool classof(SVal V)
const llvm::APSInt * getAsInteger() const
If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in ...
static bool classof(SVal V)
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
static bool classof(SVal V)
const LLVM_ATTRIBUTE_RETURNS_NONNULL TypedValueRegion * getRegion() const
static bool classof(SVal V)
unsigned getSubKind() const
const AdjustedDecl * getDeclAs() const
unsigned getRawKind() const
const llvm::APSInt & getValue() const
ConcreteInt(const llvm::APSInt &V)
static bool classof(NonLoc V)
static bool classof(SVal V)
const LLVM_ATTRIBUTE_RETURNS_NONNULL LazyCompoundValData * getCVData() const
static bool classof(SVal V)
Represents symbolic expression that isn't a location.
raw_ostream & operator<<(raw_ostream &Out, const CheckerBase &Checker)
Dump checker name to stream.
SymExpr::symbol_iterator symbol_begin() const
static bool classof(NonLoc V)
static bool classof(SVal V)
bool isAnyPointerType() const
bool isUnknownOrUndef() const
bool operator!=(const MemRegionVal &R) const
static bool isPossible(const From &V)
ConcreteInt(const llvm::APSInt &V)
static bool classof(Loc V)
symbol_iterator symbol_begin() const
bool operator!=(SVal R) const
BaseKind getBaseKind() const
LLVM_ATTRIBUTE_RETURNS_NONNULL SymbolRef getSymbol() const
const REGION * getRegionAs() const
static bool classof(SVal V)
bool isUndef() const =delete
static std::optional< To > castFailed()
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
#define REGION(Id, Parent)
MemRegionVal(const MemRegion *r)
SymExpr::symbol_iterator symbol_end() const
bool isValid() const =delete
TypedValueRegion - An abstract class representing regions having a typed value.
bool operator==(const MemRegionVal &R) const
SVal(BaseKind k, const void *D=nullptr)
static bool classof(SVal V)
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
static To doCast(const From &f)
Loc(unsigned SubKind, const void *D)
static bool classof(NonLoc V)
KnownSVal(const UndefinedVal &V)
static bool classof(NonLoc V)
Represents a function declaration or definition.
static bool classof(SVal V)
static symbol_iterator symbol_end()
QualType getType(const ASTContext &) const
Try to get a reasonable type for the given value.
const llvm::APSInt & getValue() const
const MemRegion * getRegion() const
Get the underlining region.
Kind
Sub-kinds for Loc values.