27#include "llvm/ADT/ImmutableMap.h"
28#include "llvm/ADT/SmallPtrSet.h"
29#include "llvm/Support/ErrorHandling.h"
30#include "llvm/Support/raw_ostream.h"
40 case Stmt::OpaqueValueExprClass:
41 if (
const Expr *SE = cast<OpaqueValueExpr>(
E)->getSourceExpr()) {
46 case Stmt::ExprWithCleanupsClass:
47 E = cast<ExprWithCleanups>(
E)->getSubExpr();
49 case Stmt::ConstantExprClass:
50 E = cast<ConstantExpr>(
E)->getSubExpr();
52 case Stmt::CXXBindTemporaryExprClass:
53 E = cast<CXXBindTemporaryExpr>(
E)->getSubExpr();
55 case Stmt::SubstNonTypeTemplateParmExprClass:
56 E = cast<SubstNonTypeTemplateParmExpr>(
E)->getReplacement();
67 if (
const auto *
E = dyn_cast<Expr>(S))
75 L ? L->getStackFrame()
79 const SVal*
X = ExprBindings.lookup(
E);
90 assert(!isa<ObjCForCollectionStmt>(S) &&
91 "Use ExprEngine::hasMoreIteration()!");
92 assert((isa<Expr, ReturnStmt>(S)) &&
93 "Environment can only argue about Exprs, since only they express "
94 "a value! Any non-expression statement stored in Environment is a "
98 switch (S->getStmtClass()) {
99 case Stmt::CXXBindTemporaryExprClass:
100 case Stmt::ExprWithCleanupsClass:
101 case Stmt::GenericSelectionExprClass:
102 case Stmt::ConstantExprClass:
103 case Stmt::ParenExprClass:
104 case Stmt::SubstNonTypeTemplateParmExprClass:
105 llvm_unreachable(
"Should have been handled by ignoreTransparentExprs");
107 case Stmt::AddrLabelExprClass:
108 case Stmt::CharacterLiteralClass:
109 case Stmt::CXXBoolLiteralExprClass:
110 case Stmt::CXXScalarValueInitExprClass:
111 case Stmt::ImplicitValueInitExprClass:
112 case Stmt::IntegerLiteralClass:
113 case Stmt::ObjCBoolLiteralExprClass:
114 case Stmt::CXXNullPtrLiteralExprClass:
115 case Stmt::ObjCStringLiteralClass:
116 case Stmt::StringLiteralClass:
117 case Stmt::TypeTraitExprClass:
118 case Stmt::SizeOfPackExprClass:
119 case Stmt::PredefinedExprClass:
123 case Stmt::ReturnStmtClass: {
124 const auto *RS = cast<ReturnStmt>(S);
125 if (
const Expr *RE = RS->getRetValue())
155 MarkLiveCallback(
SymbolReaper &symreaper) : SymReaper(symreaper) {}
157 bool VisitSymbol(
SymbolRef sym)
override {
158 SymReaper.markLive(sym);
162 bool VisitMemRegion(
const MemRegion *R)
override {
163 SymReaper.markLive(R);
186 MarkLiveCallback CB(SymReaper);
189 llvm::ImmutableMapRef<EnvironmentEntry, SVal>
190 EBMapRef(NewEnv.ExprBindings.getRootWithoutRetain(),
196 SVal X = I.getData();
204 EBMapRef = EBMapRef.add(BlkExpr,
X);
211 NewEnv.ExprBindings = EBMapRef.asImmutableMap();
217 unsigned int Space,
bool IsDot)
const {
218 Indent(Out, Space, IsDot) <<
"\"environment\": ";
220 if (ExprBindings.isEmpty()) {
221 Out <<
"null," << NL;
229 for (
const auto &I : *
this) {
231 if (FoundContexts.count(LC) == 0) {
235 FoundContexts.insert(LCI);
242 Out <<
"{ \"pointer\": \"" << (
const void *)LCtx->
getStackFrame()
243 <<
"\", \"items\": [" << NL;
248 bool HasItem =
false;
249 unsigned int InnerSpace = Space + 1;
252 BindingsTy::iterator LastI = ExprBindings.end();
253 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
255 if (I->first.getLocationContext() != LC)
263 const Stmt *S = I->first.getStmt();
265 assert(S !=
nullptr &&
"Expected non-null Stmt");
270 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
272 if (I->first.getLocationContext() != LC)
275 const Stmt *S = I->first.getStmt();
276 Indent(Out, InnerSpace, IsDot)
277 <<
"{ \"stmt_id\": " << S->getID(Ctx) <<
", \"kind\": \""
278 << S->getStmtClassName() <<
"\", \"pretty\": ";
279 S->printJson(Out,
nullptr, PP,
true);
281 Out <<
", \"value\": ";
282 I->second.printJson(Out,
true);
292 Indent(Out, --InnerSpace, IsDot) <<
']';
297 Indent(Out, --Space, IsDot) <<
"]}," << NL;
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static const Expr * ignoreTransparentExprs(const Expr *E)
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the Objective-C statement AST node classes.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const clang::PrintingPolicy & getPrintingPolicy() const
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const LocationContext * getParent() const
It might return null.
const StackFrameContext * getStackFrame() const
void printJson(raw_ostream &Out, const char *NL="\n", unsigned int Space=0, bool IsDot=false, std::function< void(const LocationContext *)> printMoreInfoPerContext=[](const LocationContext *) {}) const
Prints out the call stack in json format.
It represents a stack frame of the call stack (based on CallEvent).
Stmt - This represents one statement.
StmtClass getStmtClass() const
An entry in the environment consists of a Stmt and an LocationContext.
const Stmt * getStmt() const
EnvironmentEntry(const Stmt *s, const LocationContext *L)
const LocationContext * getLocationContext() const
Environment getInitialEnvironment()
Environment bindExpr(Environment Env, const EnvironmentEntry &E, SVal V, bool Invalidate)
Bind a symbolic value to the given environment entry.
Environment removeDeadBindings(Environment Env, SymbolReaper &SymReaper, ProgramStateRef state)
An immutable map from EnvironemntEntries to SVals.
SVal getSVal(const EnvironmentEntry &E, SValBuilder &svalBuilder) const
Fetches the current binding of the expression in the Environment.
void printJson(raw_ostream &Out, const ASTContext &Ctx, const LocationContext *LCtx=nullptr, const char *NL="\n", unsigned int Space=0, bool IsDot=false) const
BindingsTy::iterator iterator
MemRegion - The root abstract class for all memory regions.
std::optional< SVal > getConstantVal(const Expr *E)
Returns the value of E, if it can be determined in a non-path-sensitive manner.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
A utility class that visits the reachable symbols using a custom SymbolVisitor.
bool scan(nonloc::LazyCompoundVal val)
A class responsible for cleaning up unused symbols.
bool isLive(SymbolRef sym)
The JSON file list parser is used to communicate input to InstallAPI.
Describes how types, statements, expressions, and declarations should be printed.