14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
22#include "llvm/ADT/APSInt.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/ImmutableList.h"
25#include "llvm/ADT/PointerUnion.h"
26#include "llvm/ADT/STLForwardCompat.h"
27#include "llvm/ADT/iterator_range.h"
28#include "llvm/Support/Casting.h"
40class CXXBaseSpecifier;
47class LazyCompoundValData;
49class PointerToMemberData;
51class TypedValueRegion;
59#define BASIC_SVAL(Id, Parent) Id##Kind,
60#define LOC_SVAL(Id, Parent) Loc##Id##Kind,
61#define NONLOC_SVAL(Id, Parent) NonLoc##Id##Kind,
62#define SVAL_RANGE(Id, First, Last) \
63 BEGIN_##Id = Id##First##Kind, END_##Id = Id##Last##Kind,
64#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
68 const void *
Data =
nullptr;
75 return static_cast<const T *
>(
Data);
83 template <
typename T>
T castAs()
const {
return llvm::cast<T>(*
this); }
87 template <
typename T> std::optional<T>
getAs()
const {
88 return llvm::dyn_cast<T>(*
this);
99 ID.AddInteger(llvm::to_underlying(
getKind()));
151 void printJson(raw_ostream &Out,
bool AddQuotes)
const;
156 llvm::iterator_range<SymExpr::symbol_iterator>
symbols()
const {
158 return SE->symbols();
160 return llvm::make_range(end, end);
184#define NONLOC_SVAL(Id, Parent) \
185 inline constexpr auto Id##Kind = SVal::SValKind::NonLoc##Id##Kind;
186#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
191#define LOC_SVAL(Id, Parent) \
192 inline constexpr auto Id##Kind = SVal::SValKind::Loc##Id##Kind;
193#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
251 return BEGIN_NonLoc <=
V.getKind() &&
V.getKind() <= END_NonLoc;
268 return BEGIN_Loc <=
V.getKind() &&
V.getKind() <= END_Loc;
287 LLVM_ATTRIBUTE_RETURNS_NONNULL
315 explicit LocAsInteger(
const std::pair<SVal, uintptr_t> &data)
316 :
NonLoc(LocAsIntegerKind, &data) {
320 assert(K == loc::MemRegionValKind || K == loc::GotoLabelKind);
325 return castDataAs<std::pair<SVal, uintptr_t>>()->first.
castAs<
Loc>();
329 return castDataAs<std::pair<SVal, uintptr_t>>()->second;
347 LLVM_ATTRIBUTE_RETURNS_NONNULL
349 return castDataAs<CompoundValData>();
352 using iterator = llvm::ImmutableList<SVal>::iterator;
393 :
NonLoc(LazyCompoundValKind,
D) {
398 LLVM_ATTRIBUTE_RETURNS_NONNULL
400 return castDataAs<LazyCompoundValData>();
418 LLVM_ATTRIBUTE_RETURNS_NONNULL
439 llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;
442 return PTMDataType::getFromOpaqueValue(
const_cast<void *
>(
Data));
449 template<
typename AdjustedDecl>
451 return dyn_cast_or_null<AdjustedDecl>(
getDecl());
454 using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
463 :
NonLoc(PointerToMemberKind,
D.getOpaqueValue()) {}
492 LLVM_ATTRIBUTE_RETURNS_NONNULL
496 LLVM_ATTRIBUTE_RETURNS_NONNULL
499 template <
typename REGION>
532template <
typename To,
typename From>
535 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>
539 std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>;
543 static std::optional<To>
castFailed() {
return std::optional<To>{}; }
545 return *
static_cast<const To *
>(cast<::clang::ento::SVal>(&f));
548 if (!Self::isPossible(f))
549 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
A safe wrapper around APSInt objects allocated and owned by BasicValueFactory.
static APSIntPtr unsafeConstructor(const APSInt *Ptr)
You should not use this API.
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)
StringRef getKindStr() const
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)
static bool classof(SVal V)
APSIntPtr 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.
APSIntPtr 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()