27 #include "llvm/ADT/ImmutableMap.h" 28 #include "llvm/ADT/SmallPtrSet.h" 29 #include "llvm/Support/Casting.h" 30 #include "llvm/Support/ErrorHandling.h" 31 #include "llvm/Support/raw_ostream.h" 34 using namespace clang;
41 case Stmt::OpaqueValueExprClass:
42 E = cast<OpaqueValueExpr>(E)->getSourceExpr();
44 case Stmt::ExprWithCleanupsClass:
45 E = cast<ExprWithCleanups>(E)->getSubExpr();
47 case Stmt::ConstantExprClass:
48 E = cast<ConstantExpr>(E)->getSubExpr();
50 case Stmt::CXXBindTemporaryExprClass:
51 E = cast<CXXBindTemporaryExpr>(E)->getSubExpr();
53 case Stmt::SubstNonTypeTemplateParmExprClass:
54 E = cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement();
65 if (
const auto *E = dyn_cast<Expr>(S))
73 L ? L->getStackFrame()
77 const SVal*
X = ExprBindings.lookup(E);
91 case Stmt::CXXBindTemporaryExprClass:
92 case Stmt::ExprWithCleanupsClass:
93 case Stmt::GenericSelectionExprClass:
94 case Stmt::OpaqueValueExprClass:
95 case Stmt::ConstantExprClass:
96 case Stmt::ParenExprClass:
97 case Stmt::SubstNonTypeTemplateParmExprClass:
98 llvm_unreachable(
"Should have been handled by ignoreTransparentExprs");
100 case Stmt::AddrLabelExprClass:
101 case Stmt::CharacterLiteralClass:
102 case Stmt::CXXBoolLiteralExprClass:
103 case Stmt::CXXScalarValueInitExprClass:
104 case Stmt::ImplicitValueInitExprClass:
105 case Stmt::IntegerLiteralClass:
106 case Stmt::ObjCBoolLiteralExprClass:
107 case Stmt::CXXNullPtrLiteralExprClass:
108 case Stmt::ObjCStringLiteralClass:
109 case Stmt::StringLiteralClass:
110 case Stmt::TypeTraitExprClass:
114 case Stmt::ReturnStmtClass: {
115 const auto *RS = cast<ReturnStmt>(S);
116 if (
const Expr *RE = RS->getRetValue())
146 MarkLiveCallback(
SymbolReaper &symreaper) : SymReaper(symreaper) {}
148 bool VisitSymbol(
SymbolRef sym)
override {
149 SymReaper.markLive(sym);
153 bool VisitMemRegion(
const MemRegion *R)
override {
154 SymReaper.markLive(R);
177 MarkLiveCallback CB(SymReaper);
180 llvm::ImmutableMapRef<EnvironmentEntry, SVal>
181 EBMapRef(NewEnv.ExprBindings.getRootWithoutRetain(),
188 const SVal &
X = I.getData();
192 EBMapRef = EBMapRef.add(BlkExpr, X);
199 NewEnv.ExprBindings = EBMapRef.asImmutableMap();
207 if (ExprBindings.isEmpty())
212 llvm::SmallPtrSet<const LocationContext *, 16> FoundContexts;
213 for (
auto I : *
this) {
215 if (FoundContexts.count(LC) == 0) {
219 FoundContexts.insert(LCI);
228 Out << NL <<
"Expressions by stack frame:" << NL;
230 for (
auto I : ExprBindings) {
231 if (I.first.getLocationContext() != LC)
234 const Stmt *S = I.first.getStmt();
235 assert(S !=
nullptr &&
"Expected non-null Stmt");
237 Out <<
"(LC" << LC->
getID() <<
", S" << S->
getID(Context) <<
") ";
239 Out <<
" : " << I.second << NL;
EnvironmentEntry(const Stmt *s, const LocationContext *L)
MemRegion - The root abstract class for all memory regions.
Stmt - This represents one statement.
A utility class that visits the reachable symbols using a custom SymbolVisitor.
Describes how types, statements, expressions, and declarations should be printed. ...
Defines the clang::Expr interface and subclasses for C++ expressions.
const Stmt * getStmt() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void dumpStack(raw_ostream &OS, StringRef Indent={}, const char *NL="\, const char *Sep="", std::function< void(const LocationContext *)> printMoreInfoPerContext=[](const LocationContext *) {}) const
Environment bindExpr(Environment Env, const EnvironmentEntry &E, SVal V, bool Invalidate)
Bind a symbolic value to the given environment entry.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
static const Expr * ignoreTransparentExprs(const Expr *E)
const clang::PrintingPolicy & getPrintingPolicy() const
const LocationContext * getParent() const
BindingsTy::iterator iterator
This represents one expression.
Defines the clang::LangOptions interface.
void print(raw_ostream &Out, const char *NL, const char *Sep, const ASTContext &Context, const LocationContext *WithLC=nullptr) const
bool scan(nonloc::LazyCompoundVal val)
SVal getSVal(const EnvironmentEntry &E, SValBuilder &svalBuilder) const
Fetches the current binding of the expression in the Environment.
An entry in the environment consists of a Stmt and an LocationContext.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
int64_t getID(const ASTContext &Context) const
A class responsible for cleaning up unused symbols.
An immutable map from EnvironemntEntries to SVals.
Dataflow Directional Tag Classes.
StmtClass getStmtClass() const
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
Optional< SVal > getConstantVal(const Expr *E)
Returns the value of E, if it can be determined in a non-path-sensitive manner.
Environment removeDeadBindings(Environment Env, SymbolReaper &SymReaper, ProgramStateRef state)
bool isLive(SymbolRef sym)
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
const LocationContext * getLocationContext() const