Go to the documentation of this file.
28 #include "llvm/ADT/Optional.h"
29 #include "llvm/Support/Casting.h"
30 #include "llvm/Support/Compiler.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/raw_ostream.h"
35 using namespace clang;
49 if (isa<SymbolConjured>(sym))
55 if (
const auto *SR = dyn_cast<SymbolicRegion>(R)) {
57 if (isa<SymbolConjured>(sym))
69 if (
const auto *FD = dyn_cast<FunctionDecl>(CTR->getDecl()))
73 if (
auto X = getAs<nonloc::PointerToMember>()) {
74 if (
const auto *MD = dyn_cast_or_null<CXXMethodDecl>(
X->getDecl()))
92 : dyn_cast<SymbolicRegion>(R->StripCasts()))
93 return SymR->getSymbol();
107 while (
const auto *SR = dyn_cast<SubRegion>(R)) {
108 if (
const auto *SymR = dyn_cast<SymbolicRegion>(SR))
109 return SymR->getSymbol();
111 R = SR->getSuperRegion();
126 return X->getSymbol();
133 return X->getRegion();
136 return X->getLoc().getAsRegion();
142 class TypeRetrievingVisitor
148 TypeRetrievingVisitor(
const ASTContext &Context) : Context(Context) {}
150 QualType VisitLocMemRegionVal(loc::MemRegionVal MRV) {
151 return Visit(MRV.getRegion());
153 QualType VisitLocGotoLabel(loc::GotoLabel GL) {
156 template <
class ConcreteInt>
QualType VisitConcreteInt(ConcreteInt CI) {
160 QualType VisitLocConcreteInt(loc::ConcreteInt CI) {
161 return VisitConcreteInt(CI);
163 QualType VisitNonLocConcreteInt(nonloc::ConcreteInt CI) {
164 return VisitConcreteInt(CI);
166 QualType VisitNonLocLocAsInteger(nonloc::LocAsInteger LI) {
167 QualType NestedType = Visit(LI.getLoc());
174 QualType VisitNonLocCompoundVal(nonloc::CompoundVal CV) {
175 return CV.getValue()->getType();
177 QualType VisitNonLocLazyCompoundVal(nonloc::LazyCompoundVal LCV) {
178 return LCV.getRegion()->getValueType();
180 QualType VisitNonLocSymbolVal(nonloc::SymbolVal SV) {
181 return Visit(SV.getSymbol());
183 QualType VisitSymbolicRegion(
const SymbolicRegion *SR) {
184 return Visit(SR->getSymbol());
186 QualType VisitTypedRegion(
const TypedRegion *TR) {
187 return TR->getLocationType();
189 QualType VisitSymExpr(
const SymExpr *SE) {
return SE->getType(); }
194 TypeRetrievingVisitor TRV{Context};
195 return TRV.Visit(*
this);
200 return R ? R->
StripCasts(StripBaseCasts) :
nullptr;
212 return getPTMData().isNull();
216 const auto PTMD = this->getPTMData();
260 return getAs<nonloc::ConcreteInt>() || getAs<loc::ConcreteInt>();
265 return LV->getValue() == I;
267 return NV->getValue() == I;
272 return isConstant(0);
322 LLVM_DUMP_METHOD
void SVal::dump()
const { dumpToStream(llvm::errs()); }
326 llvm::raw_string_ostream TempOut(Buf);
328 dumpToStream(TempOut);
334 switch (getBaseKind()) {
339 castAs<NonLoc>().dumpToStream(os);
342 castAs<Loc>().dumpToStream(os);
344 case UndefinedValKind:
351 switch (getSubKind()) {
352 case nonloc::ConcreteIntKind: {
353 const auto &
Value = castAs<nonloc::ConcreteInt>().getValue();
354 os <<
Value <<
' ' << (
Value.isSigned() ?
'S' :
'U')
355 <<
Value.getBitWidth() <<
'b';
358 case nonloc::SymbolValKind:
359 os << castAs<nonloc::SymbolVal>().getSymbol();
362 case nonloc::LocAsIntegerKind: {
364 os << C.getLoc() <<
" [as " << C.getNumBits() <<
" bit integer]";
367 case nonloc::CompoundValKind: {
369 os <<
"compoundVal{";
371 for (
const auto &I : C) {
373 os <<
' '; first =
false;
383 case nonloc::LazyCompoundValKind: {
385 os <<
"lazyCompoundVal{" <<
const_cast<void *
>(C.getStore())
386 <<
',' << C.getRegion()
390 case nonloc::PointerToMemberKind: {
391 os <<
"pointerToMember{";
393 castAs<nonloc::PointerToMember>();
397 for (
const auto &I : CastRes) {
399 os <<
' '; first =
false;
411 assert(
false &&
"Pretty-printed not implemented for this NonLoc.");
417 switch (getSubKind()) {
418 case loc::ConcreteIntKind:
419 os << castAs<loc::ConcreteInt>().getValue().getZExtValue() <<
" (Loc)";
421 case loc::GotoLabelKind:
422 os <<
"&&" << castAs<loc::GotoLabel>().getLabel()->getName();
424 case loc::MemRegionValKind:
425 os << '&' << castAs<loc::MemRegionVal>().getRegion()->getString();
428 llvm_unreachable(
"Pretty-printing not implemented for this Loc.");
void dumpToStream(raw_ostream &OS) const
ConcreteInt evalComplement(SValBuilder &svalBuilder) const
const FunctionDecl * getAsFunctionDecl() const
getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl...
const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
SymbolRef getLocSymbolInBase() const
Get the symbol in the SVal or its base region.
const MemRegion * getAsRegion() const
const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
bool hasConjuredSymbol() const
hasConjuredSymbol - If this SVal wraps a conjured symbol, return true;
This represents a decl that may have a name.
A (possibly-)qualified type.
bool isZeroConstant() const
void printJson(raw_ostream &Out, bool AddQuotes) const
printJson - Pretty-prints in JSON format.
Value representing integer constant.
void dumpToStream(raw_ostream &Out) const
static SVal getValue(SVal val, SValBuilder &svalBuilder)
bool isNullMemberPointer() const
MemRegion - The root abstract class for all memory regions.
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const void * getStore() const
Value representing pointer-to-member.
const NamedDecl * getDecl() const
BasicValueFactory & getBasicValueFactory()
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
llvm::ImmutableList< const CXXBaseSpecifier * >::iterator iterator
void dumpToStream(raw_ostream &Out) const
ConcreteInt evalMinus(SValBuilder &svalBuilder) const
FullSValVisitor - a convenient mixed visitor for all three: SVal, SymExpr and MemRegion subclasses.
SymbolicRegion - A special, "non-concrete" region.
const RegionTy * getAs() const
llvm::PointerUnion< const NamedDecl *, const PointerToMemberData * > PTMDataType
llvm::ImmutableList< SVal >::iterator iterator
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool isComparisonOp() const
FunctionCodeRegion - A region that represents code texts of function.
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
const TypedValueRegion * getRegion() const
std::string getQualifiedNameAsString() const
SVal evalBinOp(SValBuilder &svalBuilder, BinaryOperator::Opcode Op, const ConcreteInt &R) const
const llvm::APSInt & getValue() const
const llvm::APSInt * evalAPSInt(BinaryOperator::Opcode Op, const llvm::APSInt &V1, const llvm::APSInt &V2)
std::string JsonFormat(StringRef RawSR, bool AddQuotes)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
TypedValueRegion - An abstract class representing regions having a typed value.
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
SVal evalBinOp(BasicValueFactory &BasicVals, BinaryOperator::Opcode Op, const ConcreteInt &R) const
Represents a function declaration or definition.
QualType getType(const ASTContext &) const
Try to get a reasonable type for the given value.
const llvm::APSInt & getValue() const
const MemRegion * getRegion() const
Get the underlining region.