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())
152 return VisitConcreteInt(CI);
155 return VisitConcreteInt(CI);
185 TypeRetrievingVisitor TRV{Context};
186 return TRV.Visit(*
this);
202 return getPTMData().isNull();
206 const auto PTMD = this->getPTMData();
224 return getValue()->begin();
228 return getValue()->end();
250 return getAs<nonloc::ConcreteInt>() || getAs<loc::ConcreteInt>();
254 if (std::optional<loc::ConcreteInt> LV = getAs<loc::ConcreteInt>())
255 return LV->getValue() == I;
256 if (std::optional<nonloc::ConcreteInt> NV = getAs<nonloc::ConcreteInt>())
257 return NV->getValue() == I;
262 return isConstant(0);
269LLVM_DUMP_METHOD
void SVal::dump()
const { dumpToStream(llvm::errs()); }
273 llvm::raw_string_ostream TempOut(Buf);
275 dumpToStream(TempOut);
281 switch (getBaseKind()) {
286 castAs<NonLoc>().dumpToStream(os);
289 castAs<Loc>().dumpToStream(os);
291 case UndefinedValKind:
298 switch (getSubKind()) {
299 case nonloc::ConcreteIntKind: {
300 const auto &
Value = castAs<nonloc::ConcreteInt>().getValue();
301 os <<
Value <<
' ' << (
Value.isSigned() ?
'S' :
'U')
302 <<
Value.getBitWidth() <<
'b';
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.");
364 switch (getSubKind()) {
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.
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,...
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
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
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
const MemRegion * getRegion() const
Get the underlining region.
const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
LLVM_ATTRIBUTE_RETURNS_NONNULL const CompoundValData * getValue() const
llvm::ImmutableList< SVal >::iterator iterator
Value representing integer constant.
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
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
@ C
Languages that the frontend can parse and compile.
std::string JsonFormat(StringRef RawSR, bool AddQuotes)