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;
44 class BasicValueFactory;
45 class CompoundValData;
46 class LazyCompoundValData;
48 class PointerToMemberData;
50 class TypedValueRegion;
56 #define NONLOC_SVAL(Id, Parent) Id ## Kind, 57 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 66 #define LOC_SVAL(Id, Parent) Id ## Kind, 67 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 79 #define BASIC_SVAL(Id, Parent) Id ## Kind, 80 #define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind, 81 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 83 enum { BaseBits = 2, BaseMask = 0x3 };
86 const void *Data =
nullptr;
92 explicit SVal(
const void *
d,
bool isLoc,
unsigned ValKind)
93 : Data(d), Kind((isLoc ? LocKind : NonLocKind) | (ValKind << BaseBits)) {}
95 explicit SVal(
BaseKind k,
const void *D =
nullptr) : Data(D), Kind(k) {}
98 explicit SVal() =
default;
104 assert(T::isKind(*
this));
105 return *
static_cast<const T *
>(
this);
112 if (!T::isKind(*
this))
114 return *
static_cast<const T *
>(
this);
119 unsigned getSubKind()
const {
return (Kind & ~BaseMask) >> BaseBits; }
124 ID.AddInteger((
unsigned) getRawKind());
133 return !(*
this == R);
137 return getRawKind() == UnknownValKind;
141 return getRawKind() == UndefinedValKind;
145 return getRawKind() <= UnknownValKind;
149 return getRawKind() > UnknownValKind;
152 bool isConstant()
const;
154 bool isConstant(
int I)
const;
156 bool isZeroConstant()
const;
159 bool hasConjuredSymbol()
const;
172 SymbolRef getAsLocSymbol(
bool IncludeBaseRegions =
false)
const;
183 SymbolRef getAsSymbol(
bool IncludeBaseRegions =
false)
const;
187 const SymExpr *getAsSymbolicExpression()
const;
189 const SymExpr *getAsSymExpr()
const;
194 void printJson(raw_ostream &Out,
bool AddQuotes)
const;
196 void dumpToStream(raw_ostream &
OS)
const;
200 const SymExpr *SE = getAsSymbol(
true);
224 static bool isKind(
const SVal&
V) {
233 bool isUndef()
const =
delete;
234 bool isValid()
const =
delete;
239 :
SVal(d, isLoc, ValKind) {}
245 static bool isKind(
const SVal&
V) {
257 static bool isKind(
const SVal &
V) {
266 bool isUnknown()
const =
delete;
267 bool isUnknownOrUndef()
const =
delete;
268 bool isValid()
const =
delete;
278 static bool isKind(
const SVal&
V) {
289 static bool isKind(
const SVal &
V) {
301 explicit NonLoc(
unsigned SubKind,
const void *
d)
305 void dumpToStream(raw_ostream &Out)
const;
315 static bool isKind(
const SVal&
V) {
323 explicit Loc(
unsigned SubKind,
const void *D)
327 void dumpToStream(raw_ostream &Out)
const;
337 static bool isKind(
const SVal&
V) {
362 return !isa<SymbolData>(getSymbol());
368 static bool isKind(
const SVal&
V) {
373 static bool isKind(
const NonLoc& V) {
384 return *
static_cast<const llvm::APSInt *
>(Data);
400 static bool isKind(
const SVal& V) {
405 static bool isKind(
const NonLoc& V) {
413 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
414 :
NonLoc(LocAsIntegerKind, &data) {
417 assert(data.first.getBaseKind() == LocKind &&
418 (data.first.getSubKind() == loc::MemRegionValKind ||
419 data.first.getSubKind() == loc::GotoLabelKind));
424 const std::pair<SVal, uintptr_t> *D =
425 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
430 const std::pair<SVal, uintptr_t> *D =
431 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
432 const SVal& V = D->first;
437 const std::pair<SVal, uintptr_t> *D =
438 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
447 static bool isKind(
const SVal& V) {
452 static bool isKind(
const NonLoc& V) {
467 using iterator = llvm::ImmutableList<SVal>::iterator;
477 static bool isKind(
const SVal& V) {
481 static bool isKind(
const NonLoc& V) {
490 :
NonLoc(LazyCompoundValKind, D) {}
497 const void *getStore()
const;
505 static bool isKind(
const SVal& V) {
510 static bool isKind(
const NonLoc& V) {
529 llvm::PointerUnion<const DeclaratorDecl *, const PointerToMemberData *>;
532 return PTMDataType::getFromOpaqueValue(const_cast<void *>(Data));
535 bool isNullMemberPointer()
const;
539 template<
typename AdjustedDecl>
541 return dyn_cast_or_null<AdjustedDecl>(getDecl());
544 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
554 :
NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
556 static bool isKind(
const SVal& V) {
561 static bool isKind(
const NonLoc& V) {
581 return static_cast<const LabelDecl *
>(Data);
589 static bool isKind(
const SVal& V) {
593 static bool isKind(
const Loc& V) {
606 return static_cast<const MemRegion *
>(Data);
612 template <
typename REGION>
614 return dyn_cast<
REGION>(getRegion());
630 static bool isKind(
const SVal& V) {
635 static bool isKind(
const Loc& V) {
645 return *
static_cast<const llvm::APSInt *
>(Data);
657 static bool isKind(
const SVal& V) {
662 static bool isKind(
const Loc& V) {
673 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
KnownSVal(const UndefinedVal &V)
Represents a function declaration or definition.
TypedValueRegion - An abstract class representing regions having a typed value.
bool operator!=(const MemRegionVal &R) const
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
bool isBlockPointerType() const
SVal(BaseKind k, const void *D=nullptr)
DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind)
const REGION * getRegionAs() const
C Language Family Type Representation.
bool isRecordType() const
SVal(const void *d, bool isLoc, unsigned ValKind)
llvm::ImmutableList< const CXXBaseSpecifier * >::iterator iterator
Loc(unsigned SubKind, const void *D)
Value representing integer constant.
GotoLabel(const LabelDecl *Label)
static const Expr * stripCasts(ASTContext &C, const Expr *Ex)
Kind
Sub-kinds for NonLoc values.
const PTMDataType getPTMData() const
void dumpToStream(raw_ostream &OS) const
Value representing pointer-to-member.
llvm::ImmutableList< SVal >::iterator iterator
unsigned getNumBits() const
ConcreteInt(const llvm::APSInt &V)
bool isReferenceType() const
symbol_iterator symbol_begin() const
const LabelDecl * getLabel() const
static bool isCompoundType(QualType T)
static bool isLocType(QualType T)
unsigned getRawKind() const
bool operator==(const MemRegionVal &R) const
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const LazyCompoundValData * getCVData() const
SymExpr::symbol_iterator symbol_end() const
#define REGION(Id, Parent)
bool isExpression() const
KnownSVal(const DefinedSVal &V)
virtual QualType getType() const =0
Represents a ValueDecl that came out of a declarator.
unsigned getSubKind() const
bool isNullPtrType() const
bool isAnyComplexType() const
MemRegionVal(const MemRegion *r)
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
const MemRegion * getRegion() const
Get the underlining region.
void Profile(llvm::FoldingSetNodeID &ID) const
bool operator==(const SVal &R) const
NonLoc(unsigned SubKind, const void *d)
Represents the declaration of a label.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
bool isAnyPointerType() const
bool isVectorType() const
DefinedOrUnknownSVal(BaseKind k, void *D=nullptr)
BaseKind getBaseKind() const
Dataflow Directional Tag Classes.
Kind
Sub-kinds for Loc values.
raw_ostream & operator<<(raw_ostream &Out, const CheckerBase &Checker)
Dump checker name to stream.
static symbol_iterator symbol_end()
DefinedSVal(const void *d, bool isLoc, unsigned ValKind)
Represents symbolic expression that isn't a location.
const llvm::APSInt & getValue() const
Loc getPersistentLoc() const
Represents an SVal that is guaranteed to not be UnknownVal.
Indicates that the tracking object is a descendant of a referenced-counted OSObject, used in the Darwin kernel.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
SymbolRef getSymbol() const
bool operator!=(const SVal &R) const
llvm::PointerUnion< const DeclaratorDecl *, const PointerToMemberData * > PTMDataType
SymExpr::symbol_iterator symbol_begin() const
const llvm::APSInt & getValue() const
const CompoundValData * getValue() const
ConcreteInt(const llvm::APSInt &V)
const AdjustedDecl * getDeclAs() const
bool isUnknownOrUndef() const
Iterator over symbols that the current symbol depends on.