14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
21#include "llvm/ADT/APSInt.h"
22#include "llvm/ADT/FoldingSet.h"
23#include "llvm/ADT/ImmutableList.h"
24#include "llvm/ADT/PointerUnion.h"
25#include "llvm/ADT/STLForwardCompat.h"
26#include "llvm/ADT/iterator_range.h"
27#include "llvm/Support/Casting.h"
39class CXXBaseSpecifier;
46class LazyCompoundValData;
48class PointerToMemberData;
50class TypedValueRegion;
58#define BASIC_SVAL(Id, Parent) Id##Kind,
59#define LOC_SVAL(Id, Parent) Loc##Id##Kind,
60#define NONLOC_SVAL(Id, Parent) NonLoc##Id##Kind,
61#define SVAL_RANGE(Id, First, Last) \
62 BEGIN_##Id = Id##First##Kind, END_##Id = Id##Last##Kind,
63#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
67 const void *
Data =
nullptr;
74 return static_cast<const T *
>(
Data);
82 template <
typename T>
T castAs()
const {
return llvm::cast<T>(*
this); }
86 template <
typename T> std::optional<T>
getAs()
const {
87 return llvm::dyn_cast<T>(*
this);
96 ID.AddInteger(llvm::to_underlying(
getKind()));
148 void printJson(raw_ostream &Out,
bool AddQuotes)
const;
153 llvm::iterator_range<SymExpr::symbol_iterator>
symbols()
const {
155 return SE->symbols();
157 return llvm::make_range(end, end);
181#define NONLOC_SVAL(Id, Parent) \
182 inline constexpr auto Id##Kind = SVal::SValKind::NonLoc##Id##Kind;
183#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
188#define LOC_SVAL(Id, Parent) \
189 inline constexpr auto Id##Kind = SVal::SValKind::Loc##Id##Kind;
190#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
248 return BEGIN_NonLoc <=
V.getKind() &&
V.getKind() <= END_NonLoc;
265 return BEGIN_Loc <=
V.getKind() &&
V.getKind() <= END_Loc;
284 LLVM_ATTRIBUTE_RETURNS_NONNULL
301 const llvm::APSInt &
getValue()
const {
return *castDataAs<llvm::APSInt>(); }
309 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
310 :
NonLoc(LocAsIntegerKind, &data) {
314 assert(K == loc::MemRegionValKind || K == loc::GotoLabelKind);
319 return castDataAs<std::pair<SVal, uintptr_t>>()->first.
castAs<
Loc>();
323 return castDataAs<std::pair<SVal, uintptr_t>>()->second;
341 LLVM_ATTRIBUTE_RETURNS_NONNULL
343 return castDataAs<CompoundValData>();
346 using iterator = llvm::ImmutableList<SVal>::iterator;
387 :
NonLoc(LazyCompoundValKind,
D) {
392 LLVM_ATTRIBUTE_RETURNS_NONNULL
394 return castDataAs<LazyCompoundValData>();
412 LLVM_ATTRIBUTE_RETURNS_NONNULL
433 llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;
436 return PTMDataType::getFromOpaqueValue(
const_cast<void *
>(
Data));
443 template<
typename AdjustedDecl>
445 return dyn_cast_or_null<AdjustedDecl>(
getDecl());
448 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
457 :
NonLoc(PointerToMemberKind,
D.getOpaqueValue()) {}
486 LLVM_ATTRIBUTE_RETURNS_NONNULL
490 LLVM_ATTRIBUTE_RETURNS_NONNULL
493 template <
typename REGION>
513 const llvm::APSInt &
getValue()
const {
return *castDataAs<llvm::APSInt>(); }
523template <
typename To,
typename From>
526 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>
530 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>;
534 static std::optional<To>
castFailed() {
return std::optional<To>{}; }
536 return *
static_cast<const To *
>(cast<::clang::ento::SVal>(&f));
539 if (!Self::isPossible(f))
540 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)
bool isValid() const =delete
DefinedOrUnknownSVal(SValKind Kind, const void *Data=nullptr)
static bool classof(SVal V)
DefinedSVal(SValKind Kind, const void *Data)
bool isUnknown() const =delete
bool isUnknownOrUndef() const =delete
bool isValid() const =delete
void dumpToStream(raw_ostream &Out) const
Loc(SValKind Kind, const void *Data)
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)
NonLoc(SValKind Kind, const void *Data)
void dumpToStream(raw_ostream &Out) const
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
bool isUnknownOrUndef() const
void dumpToStream(raw_ostream &OS) const
const T * castDataAs() 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...
void printJson(raw_ostream &Out, bool AddQuotes) const
printJson - Pretty-prints in JSON format.
SVal(SValKind Kind, const void *Data=nullptr)
void Profile(llvm::FoldingSetNodeID &ID) const
llvm::iterator_range< SymExpr::symbol_iterator > symbols() const
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
SymbolRef getLocSymbolInBase() const
Get the symbol in the SVal or its base region.
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.
virtual QualType getType() const =0
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)
const llvm::APSInt & getValue() const
const LabelDecl * getLabel() const
GotoLabel(const LabelDecl *Label)
static bool classof(SVal V)
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
const REGION * getRegionAs() const
MemRegionVal(const MemRegion *r)
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getRegion() const
Get the underlining region.
bool operator!=(const MemRegionVal &R) const
bool operator==(const MemRegionVal &R) const
static bool classof(SVal V)
The simplest example of a concrete compound value is nonloc::CompoundVal, which represents a concrete...
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(SVal V)
While nonloc::CompoundVal covers a few simple use cases, nonloc::LazyCompoundVal is a more performant...
LLVM_ATTRIBUTE_RETURNS_NONNULL const LazyCompoundValData * getCVData() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
This function itself is immaterial.
const void * getStore() const
It might return null.
static bool classof(SVal V)
static bool classof(SVal V)
unsigned getNumBits() const
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
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)
bool isExpression() const
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,...
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
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()