15 #ifndef LLVM_CLANG_STATICANALYZER_CHECKERS_SVALEXPLAINER_H 16 #define LLVM_CLANG_STATICANALYZER_CHECKERS_SVALEXPLAINER_H 29 std::string printStmt(
const Stmt *S) {
31 llvm::raw_string_ostream
OS(Str);
37 if (
auto S = dyn_cast<SymbolRegionValue>(R->
getSymbol()))
38 if (isa<CXXThisRegion>(S->getRegion()))
47 return "unknown value";
51 return "undefined value";
57 if (
auto SR = dyn_cast<SymbolicRegion>(R)) {
59 if (!isThisObject(SR))
60 return Visit(SR->getSymbol());
62 return "pointer to " +
Visit(R);
68 llvm::raw_string_ostream
OS(Str);
69 OS <<
"concrete memory address '" << I <<
"'";
80 llvm::raw_string_ostream
OS(Str);
81 OS << (I.isSigned() ?
"signed " :
"unsigned ") << I.getBitWidth()
82 <<
"-bit integer '" << I <<
"'";
93 if (
auto V = dyn_cast<VarRegion>(R))
94 if (
auto D = dyn_cast<ParmVarDecl>(
V->getDecl()))
95 return "argument '" + D->getQualifiedNameAsString() +
"'";
96 return "initial value of " +
Visit(R);
101 "' conjured at statement '" + printStmt(S->
getStmt()) +
"'";
120 llvm::raw_string_ostream
OS(Str);
143 return "'this' object";
156 return "region allocated by '" + printStmt(R->
getExpr()) +
"'";
164 return "string literal " + R->
getString();
169 llvm::raw_string_ostream
OS(Str);
184 if (isa<ParmVarDecl>(VD))
185 return "parameter '" + Name +
"'";
186 else if (VD->
hasAttr<BlocksAttr>())
187 return "block variable '" + Name +
"'";
189 return "local variable '" + Name +
"'";
191 return "static local variable '" + Name +
"'";
193 return "global variable '" + Name +
"'";
195 llvm_unreachable(
"A variable is either local or global");
209 return "temporary object constructed at statement '" +
220 llvm::raw_string_ostream
OS(Str);
222 return "a value unsupported by the explainer: (" +
223 std::string(OS.str()) +
")";
228 llvm::raw_string_ostream
OS(Str);
230 return "a symbolic expression unsupported by the explainer: (" +
231 std::string(OS.str()) +
")";
236 llvm::raw_string_ostream
OS(Str);
238 return "a memory region unsupported by the explainer (" +
239 std::string(OS.str()) +
")";
CompoundLiteralRegion - A memory region representing a compound literal.
const ObjCIvarDecl * getDecl() const
MemRegion - The root abstract class for all memory regions.
std::string Visit(SVal V)
std::string VisitObjCIvarRegion(const ObjCIvarRegion *R)
std::string getString() const
Get a string representation of a region for debug use.
Stmt - This represents one statement.
std::string VisitFieldRegion(const FieldRegion *R)
std::string VisitSymbolExtent(const SymbolExtent *S)
Value representing integer constant.
AllocaRegion - A region that represents an untyped blob of bytes created by a call to 'alloca'...
Represents a variable declaration or definition.
const T * getAs() const
Member-template getAs<specific type>'.
std::string VisitSymbolRegionValue(const SymbolRegionValue *S)
QualType getElementType() const
Describes how types, statements, expressions, and declarations should be printed. ...
std::string VisitSymExpr(SymbolRef S)
const MemRegion * getSuperRegion() const
std::string VisitElementRegion(const ElementRegion *R)
std::string VisitStringRegion(const StringRegion *R)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const FieldDecl * getDecl() const
std::string VisitSymSymExpr(const SymSymExpr *S)
FullSValVisitor - a convenient mixed visitor for all three: SVal, SymExpr and MemRegion subclasses...
StringRef getOpcodeStr() const
const CXXRecordDecl * getDecl() const
virtual void dumpToStream(raw_ostream &os) const
Represents a symbolic expression like 'x' + 3.
A symbol representing the value of a MemRegion whose parent region has symbolic value.
std::string VisitSVal(SVal V)
QualType getType() const override
const MemSpaceRegion * getMemorySpace() const
virtual QualType getType() const =0
std::string VisitSymbolDerived(const SymbolDerived *S)
SValExplainer(ASTContext &Ctx)
std::string VisitNonLocLazyCompoundVal(nonloc::LazyCompoundVal V)
SymbolicRegion - A special, "non-concrete" region.
std::string VisitMemRegion(const MemRegion *R)
const TypedValueRegion * getRegion() const
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
const SubRegion * getRegion() const
std::string VisitSymbolMetadata(const SymbolMetadata *S)
std::string VisitUnknownVal(UnknownVal V)
std::string VisitSymIntExpr(const SymIntExpr *S)
std::string VisitVarRegion(const VarRegion *R)
const VarDecl * getDecl() const
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
const MemRegion * getRegion() const
Get the underlining region.
std::string VisitNonLocConcreteInt(nonloc::ConcreteInt V)
QualType getCanonicalType() const
const TypedValueRegion * getRegion() const
const SymExpr * getLHS() const
SymbolRef getSymbol() const
const CompoundLiteralExpr * getLiteralExpr() const
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
std::string VisitLocConcreteInt(loc::ConcreteInt V)
A symbol representing the result of an expression in the case when we do not know anything about what...
std::string VisitSymbolConjured(const SymbolConjured *S)
std::string VisitSymbolicRegion(const SymbolicRegion *R)
A symbol representing the value stored at a MemRegion.
Dataflow Directional Tag Classes.
const llvm::APSInt & getRHS() const
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Represents symbolic expression that isn't a location.
const llvm::APSInt & getValue() const
Represents a pointer to an Objective C object.
const SymExpr * getRHS() const
const Expr * getExpr() const
Indicates that the tracking object is a descendant of a referenced-counted OSObject, used in the Darwin kernel.
SymbolRef getSymbol() const
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
std::string VisitNonLocSymbolVal(nonloc::SymbolVal V)
const Stmt * getStmt() const
std::string VisitUndefinedVal(UndefinedVal V)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const Expr * getExpr() const
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
std::string VisitLocMemRegionVal(loc::MemRegionVal V)
BinaryOperator::Opcode getOpcode() const
SymbolRef getParentSymbol() const
std::string VisitCXXTempObjectRegion(const CXXTempObjectRegion *R)
const TypedValueRegion * getRegion() const
std::string VisitCompoundLiteralRegion(const CompoundLiteralRegion *R)
StringRegion - Region associated with a StringLiteral.
std::string VisitAllocaRegion(const AllocaRegion *R)
ElementRegion is used to represent both array elements and casts.
std::string getQualifiedNameAsString() const
const llvm::APSInt & getValue() const
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
const LangOptions & getLangOpts() const
Represents a symbolic expression like 'x' + 'y'.
const SymExpr * getLHS() const
std::string VisitCXXBaseObjectRegion(const CXXBaseObjectRegion *R)