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" 33 class CompoundValData;
34 class LazyCompoundValData;
35 class PointerToMemberData;
37 class BasicValueFactory;
39 class TypedValueRegion;
40 class MemRegionManager;
41 class ProgramStateManager;
47 #define NONLOC_SVAL(Id, Parent) Id ## Kind, 48 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 55 #define LOC_SVAL(Id, Parent) Id ## Kind, 56 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 67 #define BASIC_SVAL(Id, Parent) Id ## Kind, 68 #define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind, 69 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def" 71 enum { BaseBits = 2, BaseMask = 0x3 };
80 explicit SVal(
const void *d,
bool isLoc,
unsigned ValKind)
81 : Data(d), Kind((isLoc ? LocKind : NonLocKind) | (ValKind << BaseBits)) {}
87 explicit SVal() : Data(nullptr), Kind(0) {}
93 assert(T::isKind(*
this));
94 return *
static_cast<const T *
>(
this);
101 if (!T::isKind(*
this))
103 return *
static_cast<const T *
>(
this);
108 inline unsigned getSubKind()
const {
return (Kind & ~BaseMask) >> BaseBits; }
113 ID.AddInteger((
unsigned) getRawKind());
122 return !(*
this == R);
126 return getRawKind() == UnknownValKind;
130 return getRawKind() == UndefinedValKind;
134 return getRawKind() <= UnknownValKind;
138 return getRawKind() > UnknownValKind;
141 bool isConstant()
const;
143 bool isConstant(
int I)
const;
145 bool isZeroConstant()
const;
148 bool hasConjuredSymbol()
const;
161 SymbolRef getAsLocSymbol(
bool IncludeBaseRegions =
false)
const;
172 SymbolRef getAsSymbol(
bool IncludeBaseRegions =
false)
const;
176 const SymExpr *getAsSymbolicExpression()
const;
178 const SymExpr* getAsSymExpr()
const;
182 void dumpToStream(raw_ostream &OS)
const;
186 const SymExpr *SE = getAsSymbolicExpression();
209 static bool isKind(
const SVal& V) {
218 bool isUndef()
const =
delete;
219 bool isValid()
const =
delete;
224 :
SVal(d, isLoc, ValKind) {}
231 static bool isKind(
const SVal& V) {
242 static bool isKind(
const SVal &V) {
251 bool isUnknown()
const =
delete;
252 bool isUnknownOrUndef()
const =
delete;
253 bool isValid()
const =
delete;
260 static bool isKind(
const SVal& V) {
270 static bool isKind(
const SVal &V) {
281 explicit NonLoc(
unsigned SubKind,
const void *d)
285 void dumpToStream(raw_ostream &Out)
const;
294 static bool isKind(
const SVal& V) {
302 explicit Loc(
unsigned SubKind,
const void *D)
306 void dumpToStream(raw_ostream &Out)
const;
315 static bool isKind(
const SVal& V) {
337 return !isa<SymbolData>(getSymbol());
342 static bool isKind(
const SVal& V) {
347 static bool isKind(
const NonLoc& V) {
358 return *
static_cast<const llvm::APSInt*
>(Data);
372 static bool isKind(
const SVal& V) {
377 static bool isKind(
const NonLoc& V) {
385 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
386 :
NonLoc(LocAsIntegerKind, &data) {
389 assert(data.first.getBaseKind() == LocKind &&
390 (data.first.getSubKind() == loc::MemRegionValKind ||
391 data.first.getSubKind() == loc::GotoLabelKind));
397 const std::pair<SVal, uintptr_t> *D =
398 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
403 const std::pair<SVal, uintptr_t> *D =
404 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
405 const SVal& V = D->first;
410 const std::pair<SVal, uintptr_t> *D =
411 static_cast<const std::pair<SVal, uintptr_t> *
>(Data);
418 static bool isKind(
const SVal& V) {
423 static bool isKind(
const NonLoc& V) {
439 iterator begin()
const;
440 iterator end()
const;
445 static bool isKind(
const SVal& V) {
449 static bool isKind(
const NonLoc& V) {
458 :
NonLoc(LazyCompoundValKind, D) {}
463 const void *getStore()
const;
469 static bool isKind(
const SVal& V) {
473 static bool isKind(
const NonLoc& V) {
494 return PTMDataType::getFromOpaqueValue(const_cast<void *>(Data));
497 return getPTMData().isNull();
499 const DeclaratorDecl *getDecl()
const;
500 template<
typename AdjustedDecl>
502 return dyn_cast_or_null<AdjustedDecl>(getDecl());
505 iterator begin()
const;
506 iterator end()
const;
510 :
NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
513 static bool isKind(
const SVal& V) {
518 static bool isKind(
const NonLoc& V) {
538 return static_cast<const LabelDecl*
>(Data);
544 static bool isKind(
const SVal& V) {
548 static bool isKind(
const Loc& V) {
562 return static_cast<const MemRegion*
>(Data);
566 const MemRegion* stripCasts(
bool StripBaseCasts =
true)
const;
568 template <
typename REGION>
570 return dyn_cast<
REGION>(getRegion());
584 static bool isKind(
const SVal& V) {
589 static bool isKind(
const Loc& V) {
599 return *
static_cast<const llvm::APSInt*
>(Data);
609 static bool isKind(
const SVal& V) {
614 static bool isKind(
const Loc& V) {
627 template <
typename T>
struct isPodLike;
629 static const bool value =
true;
KnownSVal(const UndefinedVal &V)
An instance of this class is created to represent 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
bool isRecordType() const
SVal(const void *d, bool isLoc, unsigned ValKind)
Loc(unsigned SubKind, const void *D)
Value representing integer constant.
GotoLabel(const LabelDecl *Label)
Kind
Sub-kinds for NonLoc values.
const PTMDataType getPTMData() const
void dumpToStream(raw_ostream &OS) const
Value representing pointer-to-member.
unsigned getNumBits() const
ConcreteInt(const llvm::APSInt &V)
bool isReferenceType() const
symbol_iterator symbol_begin() const
llvm::ImmutableList< const CXXBaseSpecifier * >::iterator iterator
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)
llvm::ImmutableList< SVal >::iterator iterator
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
Represents a ValueDecl that came out of a declarator.
unsigned getSubKind() const
const FunctionProtoType * T
bool isNullPtrType() const
llvm::PointerUnion< const DeclaratorDecl *, const PointerToMemberData * > PTMDataType
MemRegionVal(const MemRegion *r)
unsigned Kind
The lowest 2 bits are a BaseKind (0 – 3).
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)
LabelDecl - 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.
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
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.