26#include "llvm/ADT/ImmutableMap.h"
27#include "llvm/ADT/SmallPtrSet.h"
28#include "llvm/ADT/iterator.h"
29#include "llvm/Support/ErrorHandling.h"
30#include "llvm/Support/raw_ostream.h"
40 case Stmt::OpaqueValueExprClass:
46 case Stmt::ExprWithCleanupsClass:
49 case Stmt::ConstantExprClass:
52 case Stmt::CXXBindTemporaryExprClass:
55 case Stmt::SubstNonTypeTemplateParmExprClass:
71 const SVal*
X = ExprBindings.lookup(E);
85 case Stmt::CXXBindTemporaryExprClass:
86 case Stmt::ExprWithCleanupsClass:
87 case Stmt::GenericSelectionExprClass:
88 case Stmt::ConstantExprClass:
89 case Stmt::ParenExprClass:
90 case Stmt::SubstNonTypeTemplateParmExprClass:
91 llvm_unreachable(
"Should have been handled by ignoreTransparentExprs");
93 case Stmt::AddrLabelExprClass:
94 case Stmt::CharacterLiteralClass:
95 case Stmt::CXXBoolLiteralExprClass:
96 case Stmt::CXXScalarValueInitExprClass:
97 case Stmt::ImplicitValueInitExprClass:
98 case Stmt::IntegerLiteralClass:
99 case Stmt::ObjCBoolLiteralExprClass:
100 case Stmt::CXXNullPtrLiteralExprClass:
101 case Stmt::ObjCStringLiteralClass:
102 case Stmt::StringLiteralClass:
103 case Stmt::TypeTraitExprClass:
104 case Stmt::SizeOfPackExprClass:
105 case Stmt::PredefinedExprClass:
134 MarkLiveCallback(
SymbolReaper &symreaper) : SymReaper(symreaper) {}
136 bool VisitSymbol(
SymbolRef sym)
override {
137 SymReaper.markLive(sym);
141 bool VisitMemRegion(
const MemRegion *R)
override {
142 SymReaper.markLive(R);
159 MarkLiveCallback CB(SymReaper);
163 return Environment(F.filter(Env.ExprBindings, [&](
const auto &B) {
164 const EnvironmentEntry &BlkExpr = B.first;
165 if (!SymReaper.isLive(BlkExpr.getExpr(), BlkExpr.getStackFrame()))
167 RSScaner.scan(B.second);
174 unsigned int Space,
bool IsDot)
const {
175 Indent(Out, Space, IsDot) <<
"\"environment\": ";
177 if (ExprBindings.isEmpty()) {
178 Out <<
"null," << NL;
186 for (
const auto &I : *
this) {
187 const StackFrame *CurrentSF = I.first.getStackFrame();
188 if (FoundStackFrames.count(CurrentSF) == 0) {
191 FoundStackFrames.insert_range(
199 Out <<
"{ \"pointer\": \"" << (
const void *)SF <<
"\", \"items\": [" << NL;
204 bool HasItem =
false;
205 unsigned int InnerSpace = Space + 1;
208 BindingsTy::iterator LastI = ExprBindings.end();
209 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
211 if (I->first.getStackFrame() != SF)
219 const Expr *Ex = I->first.getExpr();
221 assert(Ex !=
nullptr &&
"Expected non-null Expr");
226 for (BindingsTy::iterator I = ExprBindings.begin(); I != ExprBindings.end();
228 if (I->first.getStackFrame() != SF)
231 const Expr *Ex = I->first.getExpr();
232 Indent(Out, InnerSpace, IsDot)
233 <<
"{ \"stmt_id\": " << Ex->
getID(Ctx) <<
", \"kind\": \""
237 Out <<
", \"value\": ";
238 I->second.printJson(Out,
true);
248 Indent(Out, --InnerSpace, IsDot) <<
']';
253 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.
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 represents a stack frame of the call stack.
void printJson(raw_ostream &Out, const char *NL="\n", unsigned int Space=0, bool IsDot=false, std::function< void(const StackFrame *)> printMoreInfoPerStackFrame=[](const StackFrame *) {}) const
Prints out the call stack in json format.
llvm::iterator_range< parent_iterator > parentsIncludingSelf() const
Iterates over this frame followed by all of its ancestors.
void printJson(raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const
Pretty-prints in JSON format.
StmtClass getStmtClass() const
const char * getStmtClassName() const
int64_t getID(const ASTContext &Context) const
An entry in the environment consists of a Stmt and an StackFrame.
const Expr * getExpr() const
const StackFrame * getStackFrame() const
EnvironmentEntry(const Expr *E, const StackFrame *SF)
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 EnvironmentEntries 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 StackFrame *SF=nullptr, const char *NL="\n", unsigned int Space=0, bool IsDot=false) const
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.
A class responsible for cleaning up unused symbols.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
Top level wrappers for InstallAPI frontend operations.
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
U cast(CodeGen::Address addr)
Describes how types, statements, expressions, and declarations should be printed.