16 #ifndef LLVM_CLANG_STATICANALYZER_CHECKERS_SVALEXPLAINER_H
17 #define LLVM_CLANG_STATICANALYZER_CHECKERS_SVALEXPLAINER_H
30 std::string printStmt(
const Stmt *
S) {
32 llvm::raw_string_ostream OS(Str);
38 if (
auto S = dyn_cast<SymbolRegionValue>(R->
getSymbol()))
39 if (isa<CXXThisRegion>(S->getRegion()))
48 return "unknown value";
52 return "undefined value";
58 if (
auto SR = dyn_cast<SymbolicRegion>(R)) {
60 if (!isThisObject(SR))
61 return Visit(SR->getSymbol());
63 return "pointer to " +
Visit(R);
69 llvm::raw_string_ostream OS(Str);
70 OS <<
"concrete memory address '" << I <<
"'";
81 llvm::raw_string_ostream OS(Str);
82 OS << (I.isSigned() ?
"signed " :
"unsigned ") << I.getBitWidth()
83 <<
"-bit integer '" << I <<
"'";
94 if (
auto V = dyn_cast<VarRegion>(R))
95 if (
auto D = dyn_cast<ParmVarDecl>(V->getDecl()))
96 return "argument '" + D->getQualifiedNameAsString() +
"'";
97 return "initial value of " +
Visit(R);
102 "' conjured at statement '" + printStmt(S->
getStmt()) +
"'";
121 llvm::raw_string_ostream OS(Str);
144 return "'this' object";
149 return "region allocated by '" + printStmt(R->
getExpr()) +
"'";
157 return "string literal " + R->
getString();
162 llvm::raw_string_ostream OS(Str);
177 if (isa<ParmVarDecl>(VD))
178 return "parameter '" + Name +
"'";
180 return "local variable '" + Name +
"'";
182 return "static local variable '" + Name +
"'";
184 return "global variable '" + Name +
"'";
186 llvm_unreachable(
"A variable is either local or global");
195 return "temporary object constructed at statement '" +
206 llvm::raw_string_ostream OS(Str);
208 return "a value unsupported by the explainer: (" +
209 std::string(OS.str()) +
")";
214 llvm::raw_string_ostream OS(Str);
216 return "a symbolic expression unsupported by the explainer: (" +
217 std::string(OS.str()) +
")";
222 llvm::raw_string_ostream OS(Str);
224 return "a memory region unsupported by the explainer (" +
225 std::string(OS.str()) +
")";
CompoundLiteralRegion - A memory region representing a compound literal.
MemRegion - The root abstract class for all memory regions.
const llvm::APSInt & getRHS() const
std::string Visit(SVal V)
const SymExpr * getLHS() const
std::string VisitFieldRegion(const FieldRegion *R)
std::string getAsString() const
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'...
const SymExpr * getRHS() const
VarDecl - An instance of this class is created to represent a variable declaration or definition...
const Expr * getExpr() const
std::string VisitSymbolRegionValue(const SymbolRegionValue *S)
QualType getElementType() const
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
std::string getString() const
Get a string representation of a region for debug use.
SymbolRef getParentSymbol() const
Describes how types, statements, expressions, and declarations should be printed. ...
std::string VisitSymExpr(SymbolRef S)
std::string VisitElementRegion(const ElementRegion *R)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
std::string VisitStringRegion(const StringRegion *R)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
std::string VisitSymSymExpr(const SymSymExpr *S)
FullSValVisitor - a convenient mixed visitor for all three: SVal, SymExpr and MemRegion subclasses...
const CXXRecordDecl * getDecl() const
const SymExpr * getLHS() const
const VarDecl * getDecl() const
const LangOptions & getLangOpts() const
SymbolRef getSymbol() const
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
const SubRegion * getRegion() const
Represents a symbolic expression like 'x' + 3.
A symbol representing the value of a MemRegion whose parent region has symbolic value.
bool isStaticLocal() const
isStaticLocal - Returns true if a variable with function scope is a static local variable.
std::string VisitSVal(SVal V)
QualType getType() const override
detail::InMemoryDirectory::const_iterator I
const MemRegion * getSuperRegion() const
const Stmt * getStmt() const
std::string VisitSymbolDerived(const SymbolDerived *S)
SValExplainer(ASTContext &Ctx)
const Expr * getExpr() const
std::string VisitNonLocLazyCompoundVal(nonloc::LazyCompoundVal V)
SymbolicRegion - A special, "non-concrete" region.
std::string VisitMemRegion(const MemRegion *R)
std::string VisitSymbolMetadata(const SymbolMetadata *S)
std::string VisitUnknownVal(UnknownVal V)
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
std::string VisitSymIntExpr(const SymIntExpr *S)
const TypedValueRegion * getRegion() const
const TypedValueRegion * getRegion() const
std::string VisitVarRegion(const VarRegion *R)
std::string VisitNonLocConcreteInt(nonloc::ConcreteInt V)
const FieldDecl * getDecl() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
std::string VisitLocConcreteInt(loc::ConcreteInt V)
SymbolRef getSymbol() const
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.
StringRef getOpcodeStr() const
const llvm::APSInt & getValue() const
Represents symbolic expression.
virtual void dumpToStream(raw_ostream &os) const
BinaryOperator::Opcode getOpcode() const
const TypedValueRegion * getRegion() const
std::string VisitNonLocSymbolVal(nonloc::SymbolVal V)
std::string VisitUndefinedVal(UndefinedVal V)
const CompoundLiteralExpr * getLiteralExpr() const
std::string getQualifiedNameAsString() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
std::string VisitLocMemRegionVal(loc::MemRegionVal V)
std::string VisitCXXTempObjectRegion(const CXXTempObjectRegion *R)
std::string VisitCompoundLiteralRegion(const CompoundLiteralRegion *R)
StringRegion - Region associated with a StringLiteral.
std::string VisitAllocaRegion(const AllocaRegion *R)
ElementRegin is used to represent both array elements and casts.
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
const llvm::APSInt & getValue() const
const MemRegion * getRegion() const
Get the underlining region.
Represents a symbolic expression like 'x' + 'y'.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
std::string VisitCXXBaseObjectRegion(const CXXBaseObjectRegion *R)