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:
111 case Stmt::SizeOfPackExprClass:
115 case Stmt::ReturnStmtClass: {
116 const auto *RS = cast<ReturnStmt>(S);
117 if (
const Expr *RE = RS->getRetValue())
147 MarkLiveCallback(
SymbolReaper &symreaper) : SymReaper(symreaper) {}
149 bool VisitSymbol(
SymbolRef sym)
override {
150 SymReaper.markLive(sym);
154 bool VisitMemRegion(
const MemRegion *R)
override {
155 SymReaper.markLive(R);
178 MarkLiveCallback CB(SymReaper);
181 llvm::ImmutableMapRef<EnvironmentEntry, SVal>
182 EBMapRef(NewEnv.ExprBindings.getRootWithoutRetain(),
189 const SVal &
X = I.getData();
193 EBMapRef = EBMapRef.add(BlkExpr, X);
200 NewEnv.ExprBindings = EBMapRef.asImmutableMap();
206 unsigned int Space,
bool IsDot)
const {
207 Indent(Out, Space, IsDot) <<
"\"environment\": ";
209 if (ExprBindings.isEmpty()) {
210 Out <<
"null," << NL;
217 llvm::SmallPtrSet<const LocationContext *, 16> FoundContexts;
218 for (
const auto &I : *
this) {
220 if (FoundContexts.count(LC) == 0) {
224 FoundContexts.insert(LCI);
231 Out <<
"{ \"pointer\": \"" << (
const void *)LCtx->
getStackFrame()
232 <<
"\", \"items\": [" << NL;
237 bool HasItem =
false;
238 unsigned int InnerSpace = Space + 1;
241 BindingsTy::iterator LastI = ExprBindings.end();
242 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
244 if (I->first.getLocationContext() != LC)
252 const Stmt *S = I->first.getStmt();
254 assert(S !=
nullptr &&
"Expected non-null Stmt");
259 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
261 if (I->first.getLocationContext() != LC)
264 const Stmt *S = I->first.getStmt();
265 Indent(Out, InnerSpace, IsDot)
266 <<
"{ \"stmt_id\": " << S->
getID(Ctx) <<
", \"pretty\": ";
269 Out <<
", \"value\": ";
270 I->second.printJson(Out,
true);
280 Indent(Out, --InnerSpace, IsDot) <<
']';
285 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