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;
193 void dumpToStream(raw_ostream &
OS)
const;
197 const SymExpr *SE = getAsSymbol(
true);
221 static bool isKind(
const SVal& V) {
230 bool isUndef()
const =
delete;
231 bool isValid()
const =
delete;
236 :
SVal(d, isLoc, ValKind) {}
242 static bool isKind(
const SVal& V) {
254 static bool isKind(
const SVal &V) {
263 bool isUnknown()
const =
delete;
264 bool isUnknownOrUndef()
const =
delete;
265 bool isValid()
const =
delete;
275 static bool isKind(
const SVal& V) {
286 static bool isKind(
const SVal &V) {
298 explicit NonLoc(
unsigned SubKind,
const void *d)
302 void dumpToStream(raw_ostream &Out)
const;
312 static bool isKind(
const SVal& V) {
320 explicit Loc(
unsigned SubKind,
const void *D)
324 void dumpToStream(raw_ostream &Out)
const;
334 static bool isKind(
const SVal& V) {
359 return !isa<SymbolData>(getSymbol());
365 static bool isKind(
const SVal& V) {
370 static bool isKind(
const NonLoc& V) {
381 return *
static_cast<const llvm::APSInt *
>(Data);
397 static bool isKind(
const SVal& V) {
402 static bool isKind(
const NonLoc& V) {
410 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
411 :
NonLoc(LocAsIntegerKind, &data) {
414 assert(data.first.getBaseKind() == LocKind &&
415 (data.first.getSubKind() == loc::MemRegionValKind ||
416 data.first.getSubKind() == loc::GotoLabelKind));
421 const std::pair<SVal, uintptr_t> *D =
422 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
427 const std::pair<SVal, uintptr_t> *D =
428 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
429 const SVal& V = D->first;
434 const std::pair<SVal, uintptr_t> *D =
435 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
444 static bool isKind(
const SVal& V) {
449 static bool isKind(
const NonLoc& V) {
464 using iterator = llvm::ImmutableList<SVal>::iterator;
474 static bool isKind(
const SVal& V) {
478 static bool isKind(
const NonLoc& V) {
487 :
NonLoc(LazyCompoundValKind, D) {}
494 const void *getStore()
const;
502 static bool isKind(
const SVal& V) {
507 static bool isKind(
const NonLoc& V) {
526 llvm::PointerUnion<const DeclaratorDecl *, const PointerToMemberData *>;
529 return PTMDataType::getFromOpaqueValue(const_cast<void *>(Data));
532 bool isNullMemberPointer()
const;
536 template<
typename AdjustedDecl>
538 return dyn_cast_or_null<AdjustedDecl>(getDecl());
541 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
551 :
NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
553 static bool isKind(
const SVal& V) {
558 static bool isKind(
const NonLoc& V) {
578 return static_cast<const LabelDecl *
>(Data);
586 static bool isKind(
const SVal& V) {
590 static bool isKind(
const Loc& V) {
603 return static_cast<const MemRegion *
>(Data);
609 template <
typename REGION>
611 return dyn_cast<
REGION>(getRegion());
627 static bool isKind(
const SVal& V) {
632 static bool isKind(
const Loc& V) {
642 return *
static_cast<const llvm::APSInt *
>(Data);
654 static bool isKind(
const SVal& V) {
659 static bool isKind(
const Loc& V) {
670 #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
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Represents a ValueDecl that came out of a declarator.
unsigned getSubKind() const
bool isNullPtrType() 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.