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/PointerUnion.h"
24#include "llvm/Support/Casting.h"
36class CXXBaseSpecifier;
43class LazyCompoundValData;
45class PointerToMemberData;
47class TypedValueRegion;
53#define NONLOC_SVAL(Id, Parent) Id ## Kind,
54#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
63#define LOC_SVAL(Id, Parent) Id ## Kind,
64#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
76#define BASIC_SVAL(Id, Parent) Id ## Kind,
77#define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind,
78#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
83 const void *
Data =
nullptr;
89 explicit SVal(
const void *d,
bool isLoc,
unsigned ValKind)
99 template <
typename T> T
castAs()
const {
return llvm::cast<T>(*
this); }
103 template <
typename T> std::optional<T>
getAs()
const {
104 return llvm::dyn_cast<T>(*
this);
113 void Profile(llvm::FoldingSetNodeID &ID)
const {
178 void printJson(raw_ostream &Out,
bool AddQuotes)
const;
231 :
SVal(d, isLoc, ValKind) {}
267 explicit NonLoc(
unsigned SubKind,
const void *d)
283 explicit Loc(
unsigned SubKind,
const void *D)
312 LLVM_ATTRIBUTE_RETURNS_NONNULL
322 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == SymbolValKind;
334 return *
static_cast<const llvm::APSInt *
>(
Data);
338 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == ConcreteIntKind;
347 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
348 :
NonLoc(LocAsIntegerKind, &data) {
351 assert(data.first.getBaseKind() == LocKind &&
352 (data.first.getSubKind() == loc::MemRegionValKind ||
353 data.first.getSubKind() == loc::GotoLabelKind));
358 const std::pair<SVal, uintptr_t> *D =
359 static_cast<const std::pair<SVal, uintptr_t> *
>(
Data);
364 const std::pair<SVal, uintptr_t> *D =
365 static_cast<const std::pair<SVal, uintptr_t> *
>(
Data);
370 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == LocAsIntegerKind;
384 LLVM_ATTRIBUTE_RETURNS_NONNULL
389 using iterator = llvm::ImmutableList<SVal>::iterator;
395 return V.getBaseKind() == NonLocKind &&
V.getSubKind() == CompoundValKind;
405 :
NonLoc(LazyCompoundValKind, D) {
410 LLVM_ATTRIBUTE_RETURNS_NONNULL
418 LLVM_ATTRIBUTE_RETURNS_NONNULL
422 return V.getBaseKind() == NonLocKind &&
423 V.getSubKind() == LazyCompoundValKind;
427 return V.getSubKind() == LazyCompoundValKind;
446 llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;
449 return PTMDataType::getFromOpaqueValue(
const_cast<void *
>(
Data));
456 template<
typename AdjustedDecl>
458 return dyn_cast_or_null<AdjustedDecl>(
getDecl());
461 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
467 return V.getBaseKind() == NonLocKind &&
468 V.getSubKind() == PointerToMemberKind;
472 return V.getSubKind() == PointerToMemberKind;
477 :
NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
499 return V.getBaseKind() == LocKind &&
V.getSubKind() == GotoLabelKind;
519 template <
typename REGION>
533 return V.getBaseKind() == LocKind &&
V.getSubKind() == MemRegionValKind;
536 static bool classof(
Loc V) {
return V.getSubKind() == MemRegionValKind; }
544 return *
static_cast<const llvm::APSInt *
>(
Data);
548 return V.getBaseKind() == LocKind &&
V.getSubKind() == ConcreteIntKind;
551 static bool classof(
Loc V) {
return V.getSubKind() == ConcreteIntKind; }
559template <
typename To,
typename From>
562 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>
566 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>;
570 static std::optional<To>
castFailed() {
return std::optional<To>{}; }
572 return *
static_cast<const To *
>(cast<::clang::ento::SVal>(&f));
575 if (!Self::isPossible(f))
576 return Self::castFailed();
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
#define REGION(Id, Parent)
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a function declaration or definition.
Represents the declaration of a label.
This represents a decl that may have a name.
A (possibly-)qualified type.
bool isBlockPointerType() const
bool isReferenceType() const
bool isAnyComplexType() const
bool isVectorType() const
bool isAnyPointerType() const
bool isNullPtrType() const
bool isRecordType() const
bool isUndef() const =delete
static bool classof(SVal V)
DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind)
bool isValid() const =delete
DefinedOrUnknownSVal(BaseKind k, void *D=nullptr)
static bool classof(SVal V)
bool isUnknown() const =delete
DefinedSVal(const void *d, bool isLoc, unsigned ValKind)
bool isUnknownOrUndef() const =delete
bool isValid() const =delete
Represents an SVal that is guaranteed to not be UnknownVal.
KnownSVal(const UndefinedVal &V)
KnownSVal(const DefinedSVal &V)
static bool classof(SVal V)
void dumpToStream(raw_ostream &Out) const
Loc(unsigned SubKind, const void *D)
static bool classof(SVal V)
static bool isLocType(QualType T)
MemRegion - The root abstract class for all memory regions.
static bool isCompoundType(QualType T)
static bool classof(SVal V)
void dumpToStream(raw_ostream &Out) const
NonLoc(unsigned SubKind, const void *d)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
bool operator!=(SVal R) const
bool isZeroConstant() const
unsigned getSubKind() const
bool isUnknownOrUndef() const
void dumpToStream(raw_ostream &OS) const
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
const FunctionDecl * getAsFunctionDecl() const
getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl...
SymExpr::symbol_iterator symbol_begin() const
void printJson(raw_ostream &Out, bool AddQuotes) const
printJson - Pretty-prints in JSON format.
SymExpr::symbol_iterator symbol_end() const
void Profile(llvm::FoldingSetNodeID &ID) const
unsigned getRawKind() const
unsigned Kind
The lowest 2 bits are a BaseKind (0 – 3).
SVal(BaseKind k, const void *D=nullptr)
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
QualType getType(const ASTContext &) const
Try to get a reasonable type for the given value.
const llvm::APSInt * getAsInteger() const
If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in ...
bool operator==(SVal R) const
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
const MemRegion * getAsRegion() const
BaseKind getBaseKind() const
SymbolRef getLocSymbolInBase() const
Get the symbol in the SVal or its base region.
SVal(const void *d, bool isLoc, unsigned ValKind)
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Iterator over symbols that the current symbol depends on.
static symbol_iterator symbol_end()
virtual QualType getType() const =0
symbol_iterator symbol_begin() const
TypedValueRegion - An abstract class representing regions having a typed value.
static bool classof(SVal V)
static bool classof(SVal V)
ConcreteInt(const llvm::APSInt &V)
static bool classof(SVal V)
static bool classof(Loc V)
const llvm::APSInt & getValue() const
const LabelDecl * getLabel() const
static bool classof(Loc V)
GotoLabel(const LabelDecl *Label)
static bool classof(SVal V)
const MemRegion * getRegion() const
Get the underlining region.
const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
const REGION * getRegionAs() const
MemRegionVal(const MemRegion *r)
bool operator!=(const MemRegionVal &R) const
bool operator==(const MemRegionVal &R) const
static bool classof(Loc V)
static bool classof(SVal V)
static bool classof(NonLoc V)
LLVM_ATTRIBUTE_RETURNS_NONNULL const CompoundValData * getValue() const
static bool classof(SVal V)
llvm::ImmutableList< SVal >::iterator iterator
Value representing integer constant.
ConcreteInt(const llvm::APSInt &V)
const llvm::APSInt & getValue() const
static bool classof(NonLoc V)
static bool classof(SVal V)
LLVM_ATTRIBUTE_RETURNS_NONNULL const LazyCompoundValData * getCVData() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
const void * getStore() const
It might return null.
static bool classof(NonLoc V)
static bool classof(SVal V)
static bool classof(SVal V)
unsigned getNumBits() const
static bool classof(NonLoc V)
Value representing pointer-to-member.
bool isNullMemberPointer() const
llvm::PointerUnion< const NamedDecl *, const PointerToMemberData * > PTMDataType
llvm::ImmutableList< const CXXBaseSpecifier * >::iterator iterator
const AdjustedDecl * getDeclAs() const
static bool classof(NonLoc V)
const PTMDataType getPTMData() const
const NamedDecl * getDecl() const
static bool classof(SVal V)
Represents symbolic expression that isn't a location.
LLVM_ATTRIBUTE_RETURNS_NONNULL SymbolRef getSymbol() const
static bool classof(SVal V)
static bool classof(NonLoc V)
bool isExpression() const
Kind
Sub-kinds for Loc values.
Kind
Sub-kinds for NonLoc values.
raw_ostream & operator<<(raw_ostream &Out, const CheckerBase &Checker)
Dump checker name to stream.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
YAML serialization mapping.
static To doCast(const From &f)
static std::optional< To > doCastIfPossible(const From &f)
static bool isPossible(const From &V)
static std::optional< To > castFailed()