15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H 16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H 22 #include "llvm/ADT/FoldingSet.h" 23 #include "llvm/ADT/ImmutableList.h" 24 #include "llvm/ADT/None.h" 25 #include "llvm/ADT/Optional.h" 26 #include "llvm/ADT/PointerUnion.h" 27 #include "llvm/Support/Casting.h" 38 class CXXBaseSpecifier;
45 class BasicValueFactory;
46 class CompoundValData;
47 class LazyCompoundValData;
49 class PointerToMemberData;
51 class TypedValueRegion;
57 #define NONLOC_SVAL(Id, Parent) Id ## Kind, 58 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 67 #define LOC_SVAL(Id, Parent) Id ## Kind, 68 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 80 #define BASIC_SVAL(Id, Parent) Id ## Kind, 81 #define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind, 82 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 84 enum { BaseBits = 2, BaseMask = 0x3 };
87 const void *Data =
nullptr;
93 explicit SVal(
const void *d,
bool isLoc,
unsigned ValKind)
94 : Data(d), Kind((isLoc ? LocKind : NonLocKind) | (ValKind << BaseBits)) {}
96 explicit SVal(
BaseKind k,
const void *D =
nullptr) : Data(D), Kind(k) {}
99 explicit SVal() =
default;
105 assert(T::isKind(*
this));
106 return *
static_cast<const T *
>(
this);
113 if (!T::isKind(*
this))
115 return *
static_cast<const T *
>(
this);
120 unsigned getSubKind()
const {
return (Kind & ~BaseMask) >> BaseBits; }
125 ID.AddInteger((
unsigned) getRawKind());
134 return !(*
this == R);
138 return getRawKind() == UnknownValKind;
142 return getRawKind() == UndefinedValKind;
146 return getRawKind() <= UnknownValKind;
150 return getRawKind() > UnknownValKind;
153 bool isConstant()
const;
155 bool isConstant(
int I)
const;
157 bool isZeroConstant()
const;
160 bool hasConjuredSymbol()
const;
173 SymbolRef getAsLocSymbol(
bool IncludeBaseRegions =
false)
const;
184 SymbolRef getAsSymbol(
bool IncludeBaseRegions =
false)
const;
188 const SymExpr *getAsSymbolicExpression()
const;
190 const SymExpr *getAsSymExpr()
const;
194 void dumpToStream(raw_ostream &OS)
const;
198 const SymExpr *SE = getAsSymbol(
true);
222 static bool isKind(
const SVal& V) {
231 bool isUndef()
const =
delete;
232 bool isValid()
const =
delete;
237 :
SVal(d, isLoc, ValKind) {}
243 static bool isKind(
const SVal& V) {
255 static bool isKind(
const SVal &V) {
264 bool isUnknown()
const =
delete;
265 bool isUnknownOrUndef()
const =
delete;
266 bool isValid()
const =
delete;
276 static bool isKind(
const SVal& V) {
287 static bool isKind(
const SVal &V) {
299 explicit NonLoc(
unsigned SubKind,
const void *d)
303 void dumpToStream(raw_ostream &Out)
const;
313 static bool isKind(
const SVal& V) {
321 explicit Loc(
unsigned SubKind,
const void *D)
325 void dumpToStream(raw_ostream &Out)
const;
335 static bool isKind(
const SVal& V) {
360 return !isa<SymbolData>(getSymbol());
366 static bool isKind(
const SVal& V) {
371 static bool isKind(
const NonLoc& V) {
382 return *
static_cast<const llvm::APSInt *
>(Data);
398 static bool isKind(
const SVal& V) {
403 static bool isKind(
const NonLoc& V) {
411 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
412 :
NonLoc(LocAsIntegerKind, &data) {
415 assert(data.first.getBaseKind() == LocKind &&
416 (data.first.getSubKind() == loc::MemRegionValKind ||
417 data.first.getSubKind() == loc::GotoLabelKind));
422 const std::pair<SVal, uintptr_t> *D =
423 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
428 const std::pair<SVal, uintptr_t> *D =
429 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
430 const SVal& V = D->first;
435 const std::pair<SVal, uintptr_t> *D =
436 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
445 static bool isKind(
const SVal& V) {
450 static bool isKind(
const NonLoc& V) {
465 using iterator = llvm::ImmutableList<SVal>::iterator;
475 static bool isKind(
const SVal& V) {
479 static bool isKind(
const NonLoc& V) {
488 :
NonLoc(LazyCompoundValKind, D) {}
495 const void *getStore()
const;
503 static bool isKind(
const SVal& V) {
508 static bool isKind(
const NonLoc& V) {
527 llvm::PointerUnion<const DeclaratorDecl *, const PointerToMemberData *>;
530 return PTMDataType::getFromOpaqueValue(const_cast<void *>(Data));
534 return getPTMData().isNull();
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) {
675 template <
typename T>
struct isPodLike;
677 static const bool value =
true;
682 #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)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
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()
bool isNullMemberPointer() const
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.
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.