28#include "llvm/Support/Casting.h"
29#include "llvm/Support/Compiler.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/raw_ostream.h"
47 if (std::optional<loc::MemRegionVal>
X = getAs<loc::MemRegionVal>()) {
50 if (
const auto *FD = dyn_cast<FunctionDecl>(CTR->getDecl()))
54 if (
auto X = getAs<nonloc::PointerToMember>()) {
55 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(
X->getDecl()))
73 : dyn_cast<SymbolicRegion>(R->StripCasts()))
74 return SymR->getSymbol();
81 std::optional<loc::MemRegionVal>
X = getAs<loc::MemRegionVal>();
88 while (
const auto *SR = dyn_cast<SubRegion>(R)) {
89 if (
const auto *SymR = dyn_cast<SymbolicRegion>(SR))
90 return SymR->getSymbol();
92 R = SR->getSuperRegion();
106 if (std::optional<nonloc::SymbolVal>
X = getAs<nonloc::SymbolVal>())
107 return X->getSymbol();
113 if (
auto CI = getAs<nonloc::ConcreteInt>())
114 return &CI->getValue();
115 if (
auto CI = getAs<loc::ConcreteInt>())
116 return &CI->getValue();
121 if (std::optional<loc::MemRegionVal>
X = getAs<loc::MemRegionVal>())
122 return X->getRegion();
124 if (std::optional<nonloc::LocAsInteger>
X = getAs<nonloc::LocAsInteger>())
125 return X->getLoc().getAsRegion();
131class TypeRetrievingVisitor
137 TypeRetrievingVisitor(
const ASTContext &Context) : Context(Context) {}
145 template <
class ConcreteInt>
QualType VisitConcreteInt(ConcreteInt CI) {
146 const llvm::APSInt &
Value = CI.getValue();
147 if (1 ==
Value.getBitWidth())
182 TypeRetrievingVisitor TRV{Context};
183 return TRV.Visit(*
this);
199 return getPTMData().isNull();
203 const auto PTMD = this->getPTMData();
221 return getValue()->begin();
225 return getValue()->end();
247 return getAs<nonloc::ConcreteInt>() || getAs<loc::ConcreteInt>();
251 if (std::optional<loc::ConcreteInt> LV = getAs<loc::ConcreteInt>())
252 return LV->getValue() == I;
253 if (std::optional<nonloc::ConcreteInt> NV = getAs<nonloc::ConcreteInt>())
254 return NV->getValue() == I;
259 return isConstant(0);
266LLVM_DUMP_METHOD
void SVal::dump()
const { dumpToStream(llvm::errs()); }
270 llvm::raw_string_ostream TempOut(Buf);
272 dumpToStream(TempOut);
287 castAs<NonLoc>().dumpToStream(os);
291 castAs<Loc>().dumpToStream(os);
294 llvm_unreachable(
"Unhandled SVal kind!");
299 case nonloc::ConcreteIntKind: {
300 const auto &
Value = castAs<nonloc::ConcreteInt>().getValue();
301 os <<
Value <<
' ' << (
Value.isSigned() ?
'S' :
'U') <<
Value.getBitWidth()
305 case nonloc::SymbolValKind:
306 os << castAs<nonloc::SymbolVal>().getSymbol();
309 case nonloc::LocAsIntegerKind: {
311 os <<
C.getLoc() <<
" [as " <<
C.getNumBits() <<
" bit integer]";
314 case nonloc::CompoundValKind: {
316 os <<
"compoundVal{";
318 for (
const auto &I :
C) {
320 os <<
' '; first =
false;
330 case nonloc::LazyCompoundValKind: {
332 os <<
"lazyCompoundVal{" <<
const_cast<void *
>(
C.getStore())
333 <<
',' <<
C.getRegion()
337 case nonloc::PointerToMemberKind: {
338 os <<
"pointerToMember{";
340 castAs<nonloc::PointerToMember>();
344 for (
const auto &I : CastRes) {
346 os <<
' '; first =
false;
358 assert(
false &&
"Pretty-printed not implemented for this NonLoc.");
365 case loc::ConcreteIntKind:
366 os << castAs<loc::ConcreteInt>().getValue().getZExtValue() <<
" (Loc)";
368 case loc::GotoLabelKind:
369 os <<
"&&" << castAs<loc::GotoLabel>().getLabel()->getName();
371 case loc::MemRegionValKind:
372 os << '&' << castAs<loc::MemRegionVal>().getRegion()->getString();
375 llvm_unreachable(
"Pretty-printing not implemented for this Loc.");
Defines the clang::ASTContext interface.
static const MemRegion * getRegion(const CallEvent &Call, const MutexDescriptor &Descriptor, bool IsLock)
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
Represents a function declaration or definition.
This represents a decl that may have a name.
std::string getQualifiedNameAsString() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
AllocaRegion - A region that represents an untyped blob of bytes created by a call to 'alloca'.
FullSValVisitor - a convenient mixed visitor for all three: SVal, SymExpr and MemRegion subclasses.
FunctionCodeRegion - A region that represents code texts of function.
void dumpToStream(raw_ostream &Out) const
static bool classof(SVal V)
MemRegion - The root abstract class for all memory regions.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region.
const RegionTy * getAs() const
static bool classof(SVal V)
void dumpToStream(raw_ostream &Out) const
bool isZeroConstant() 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...
void printJson(raw_ostream &Out, bool AddQuotes) const
printJson - Pretty-prints in JSON format.
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 ...
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.
virtual QualType getType() const =0
SymbolicRegion - A special, "non-concrete" region.
SymbolRef getSymbol() const
It might return null.
TypedRegion - An abstract class representing regions that are typed.
virtual QualType getLocationType() const =0
TypedValueRegion - An abstract class representing regions having a typed value.
virtual QualType getValueType() const =0
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getRegion() const
Get the underlining region.
The simplest example of a concrete compound value is nonloc::CompoundVal, which represents a concrete...
LLVM_ATTRIBUTE_RETURNS_NONNULL const CompoundValData * getValue() const
llvm::ImmutableList< SVal >::iterator iterator
While nonloc::CompoundVal covers a few simple use cases, nonloc::LazyCompoundVal is a more performant...
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
This function itself is immaterial.
const void * getStore() const
It might return null.
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 NamedDecl * getDecl() const
Represents symbolic expression that isn't a location.
LLVM_ATTRIBUTE_RETURNS_NONNULL SymbolRef getSymbol() const
The JSON file list parser is used to communicate input to InstallAPI.
std::string JsonFormat(StringRef RawSR, bool AddQuotes)