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::CXXBindTemporaryExprClass:
48 E = cast<CXXBindTemporaryExpr>(E)->getSubExpr();
50 case Stmt::SubstNonTypeTemplateParmExprClass:
51 E = cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement();
62 if (
const auto *E = dyn_cast<Expr>(S))
70 L ? L->getStackFrame()
74 const SVal*
X = ExprBindings.lookup(E);
88 case Stmt::CXXBindTemporaryExprClass:
89 case Stmt::ExprWithCleanupsClass:
90 case Stmt::GenericSelectionExprClass:
91 case Stmt::OpaqueValueExprClass:
92 case Stmt::ParenExprClass:
93 case Stmt::SubstNonTypeTemplateParmExprClass:
94 llvm_unreachable(
"Should have been handled by ignoreTransparentExprs");
96 case Stmt::AddrLabelExprClass:
97 case Stmt::CharacterLiteralClass:
98 case Stmt::CXXBoolLiteralExprClass:
99 case Stmt::CXXScalarValueInitExprClass:
100 case Stmt::ImplicitValueInitExprClass:
101 case Stmt::IntegerLiteralClass:
102 case Stmt::ObjCBoolLiteralExprClass:
103 case Stmt::CXXNullPtrLiteralExprClass:
104 case Stmt::ObjCStringLiteralClass:
105 case Stmt::StringLiteralClass:
106 case Stmt::TypeTraitExprClass:
110 case Stmt::ReturnStmtClass: {
111 const auto *RS = cast<ReturnStmt>(S);
112 if (
const Expr *RE = RS->getRetValue())
142 MarkLiveCallback(
SymbolReaper &symreaper) : SymReaper(symreaper) {}
144 bool VisitSymbol(
SymbolRef sym)
override {
145 SymReaper.markLive(sym);
149 bool VisitMemRegion(
const MemRegion *R)
override {
150 SymReaper.markLive(R);
173 MarkLiveCallback CB(SymReaper);
176 llvm::ImmutableMapRef<EnvironmentEntry, SVal>
177 EBMapRef(NewEnv.ExprBindings.getRootWithoutRetain(),
184 const SVal &
X = I.getData();
188 EBMapRef = EBMapRef.add(BlkExpr, X);
195 for (; SI != SE; ++SI)
200 NewEnv.ExprBindings = EBMapRef.asImmutableMap();
206 if (ExprBindings.isEmpty())
211 llvm::SmallPtrSet<const LocationContext *, 16> FoundContexts;
212 for (
auto I : *
this) {
214 if (FoundContexts.count(LC) == 0) {
218 FoundContexts.insert(LCI);
228 Out << NL << 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 <<
"(" << (
const void *)LC <<
',' << (
const void *)S <<
") ";
239 Out <<
" : " << I.second << NL;
EnvironmentEntry(const Stmt *s, const LocationContext *L)
MemRegion - The root abstract class for all memory regions.
void print(raw_ostream &Out, const char *NL, const char *Sep, const LocationContext *WithLC=nullptr) const
Stmt - This represents one statement.
bool maybeDead(SymbolRef sym)
If a symbol is known to be live, marks the symbol as live.
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
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.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
static const Expr * ignoreTransparentExprs(const Expr *E)
const LocationContext * getParent() const
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, const ASTContext *Context=nullptr) const
SymExpr::symbol_iterator symbol_end() const
BindingsTy::iterator iterator
Expr - This represents one expression.
Defines the clang::LangOptions interface.
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...
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 ...
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)
SymExpr::symbol_iterator symbol_begin() const
bool isLive(SymbolRef sym)
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
const LocationContext * getLocationContext() const
Iterator over symbols that the current symbol depends on.