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();
205 unsigned int Space,
bool IsDot)
const {
206 Indent(Out, Space, IsDot) <<
"\"environment\": ";
208 if (ExprBindings.isEmpty()) {
209 Out <<
"null," << NL;
216 llvm::SmallPtrSet<const LocationContext *, 16> FoundContexts;
217 for (
const auto &I : *
this) {
219 if (FoundContexts.count(LC) == 0) {
223 FoundContexts.insert(LCI);
230 Out <<
"{ \"pointer\": \"" << (
const void *)LCtx->
getStackFrame()
231 <<
"\", \"items\": [" << NL;
236 bool HasItem =
false;
237 unsigned int InnerSpace = Space + 1;
240 BindingsTy::iterator LastI = ExprBindings.end();
241 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
243 if (I->first.getLocationContext() != LC)
251 const Stmt *S = I->first.getStmt();
253 assert(S !=
nullptr &&
"Expected non-null Stmt");
258 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
260 if (I->first.getLocationContext() != LC)
263 const Stmt *S = I->first.getStmt();
264 Indent(Out, InnerSpace, IsDot)
265 <<
"{ \"stmt_id\": " << S->
getID(Ctx) <<
", \"pretty\": ";
268 Out <<
", \"value\": ";
269 I->second.printJson(Out,
true);
279 Indent(Out, --InnerSpace, IsDot) <<
']';
284 Indent(Out, --Space, IsDot) <<
"]}," << 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 printJson(raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const
Pretty-prints in JSON format.
Environment bindExpr(Environment Env, const EnvironmentEntry &E, SVal V, bool Invalidate)
Bind a symbolic value to the given environment entry.
void printJson(raw_ostream &Out, const ASTContext &Ctx, const LocationContext *LCtx=nullptr, const char *NL="\, unsigned int Space=0, bool IsDot=false) const
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.
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
const StackFrameContext * getStackFrame() const
void printJson(raw_ostream &Out, const char *NL="\, unsigned int Space=0, bool IsDot=false, std::function< void(const LocationContext *)> printMoreInfoPerContext=[](const LocationContext *) {}) 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)
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
bool isLive(SymbolRef sym)
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
const LocationContext * getLocationContext() const