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/None.h"
24 #include "llvm/ADT/Optional.h"
25 #include "llvm/ADT/PointerUnion.h"
26 #include "llvm/Support/Casting.h"
37 class CXXBaseSpecifier;
43 class BasicValueFactory;
44 class CompoundValData;
45 class LazyCompoundValData;
47 class PointerToMemberData;
49 class TypedValueRegion;
55 #define NONLOC_SVAL(Id, Parent) Id ## Kind,
56 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
65 #define LOC_SVAL(Id, Parent) Id ## Kind,
66 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
78 #define BASIC_SVAL(Id, Parent) Id ## Kind,
79 #define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind,
80 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
85 const void *
Data =
nullptr;
91 explicit SVal(
const void *d,
bool isLoc,
unsigned ValKind)
97 explicit SVal() =
default;
101 template <
typename T> T
castAs()
const {
return llvm::cast<T>(*
this); }
106 return llvm::dyn_cast<T>(*
this);
175 void printJson(raw_ostream &Out,
bool AddQuotes)
const;
228 :
SVal(d, isLoc, ValKind) {}
264 explicit NonLoc(
unsigned SubKind,
const void *d)
280 explicit Loc(
unsigned SubKind,
const void *D)
309 LLVM_ATTRIBUTE_RETURNS_NONNULL
319 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == SymbolValKind;
335 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == ConcreteIntKind;
344 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
345 :
NonLoc(LocAsIntegerKind, &data) {
348 assert(data.first.getBaseKind() == LocKind &&
349 (data.first.getSubKind() == loc::MemRegionValKind ||
350 data.first.getSubKind() == loc::GotoLabelKind));
355 const std::pair<SVal, uintptr_t> *D =
356 static_cast<const std::pair<SVal, uintptr_t> *
>(
Data);
361 const std::pair<SVal, uintptr_t> *D =
362 static_cast<const std::pair<SVal, uintptr_t> *
>(
Data);
367 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == LocAsIntegerKind;
381 LLVM_ATTRIBUTE_RETURNS_NONNULL
386 using iterator = llvm::ImmutableList<SVal>::iterator;
392 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == CompoundValKind;
402 :
NonLoc(LazyCompoundValKind, D) {
407 LLVM_ATTRIBUTE_RETURNS_NONNULL
415 LLVM_ATTRIBUTE_RETURNS_NONNULL
419 return V.getBaseKind() == NonLocKind &&
420 V.getSubKind() == LazyCompoundValKind;
424 return V.getSubKind() == LazyCompoundValKind;
443 llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;
446 return PTMDataType::getFromOpaqueValue(
const_cast<void *
>(
Data));
453 template<
typename AdjustedDecl>
455 return dyn_cast_or_null<AdjustedDecl>(
getDecl());
458 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
464 return V.getBaseKind() == NonLocKind &&
465 V.getSubKind() == PointerToMemberKind;
469 return V.getSubKind() == PointerToMemberKind;
474 :
NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
496 return V.getBaseKind() == LocKind &&
V.getSubKind() == GotoLabelKind;
516 template <
typename REGION>
530 return V.getBaseKind() == LocKind &&
V.getSubKind() == MemRegionValKind;
533 static bool classof(
Loc V) {
return V.getSubKind() == MemRegionValKind; }
545 return V.getBaseKind() == LocKind &&
V.getSubKind() == ConcreteIntKind;
548 static bool classof(
Loc V) {
return V.getSubKind() == ConcreteIntKind; }
556 template <
typename To,
typename From>
559 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>
561 using Self = CastInfo<
563 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>;
569 return *
static_cast<const To *
>(cast<::clang::ento::SVal>(&f));
572 if (!Self::isPossible(f))
573 return Self::castFailed();
579 #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
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type.
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
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 Optional< To > castFailed()
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)
static bool classof(SVal V)
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
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 Optional< To > doCastIfPossible(const From &f)
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.