[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 25 15:24:02 PST 2018
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.
When viewing the `ExplodedGraph` through graphviz, make `ExprEngine`'s two private program state traits - namely C++ allocator values and C++ initialized temporaries - visible in the dump.
How it looks:
F5784825: Graph.png <https://reviews.llvm.org/F5784825>
Unfortunately this relies on `LocationContext`, so it wouldn't be available in normal `ProgramState` dumps. Hmm, i guess i could add a mode to print them in an unsorted order.
Repository:
rC Clang
https://reviews.llvm.org/D42560
Files:
include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
lib/StaticAnalyzer/Core/ExprEngine.cpp
lib/StaticAnalyzer/Core/ProgramState.cpp
Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -450,7 +450,7 @@
Mgr.getConstraintManager().print(this, Out, NL, Sep);
// Print checker-specific data.
- Mgr.getOwningEngine()->printState(Out, this, NL, Sep);
+ Mgr.getOwningEngine()->printState(Out, this, NL, Sep, LC);
}
void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LC) const {
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -384,7 +384,44 @@
}
void ExprEngine::printState(raw_ostream &Out, ProgramStateRef State,
- const char *NL, const char *Sep) {
+ const char *NL, const char *Sep,
+ const LocationContext *LCtx) {
+ if (LCtx) {
+ LangOptions LO; // FIXME.
+
+ auto InitTempSet = State->get<InitializedTemporariesSet>();
+ if (!InitTempSet.isEmpty()) {
+ Out << Sep << "Initialized temporaries:" << NL;
+
+ LCtx->dumpStack(Out, "", NL, Sep,
+ [&Out, &LO, InitTempSet, NL](const LocationContext *LC) {
+ for (auto I : InitTempSet) {
+ if (I.second != LC)
+ continue;
+ Out << '(' << I.second << ',' << I.first << ") ";
+ I.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+ Out << NL;
+ }
+ });
+ }
+
+ auto NewAllocValsMap = State->get<CXXNewAllocatorValues>();
+ if (!NewAllocValsMap.isEmpty()) {
+ Out << Sep << "operator new() allocator return values:" << NL;
+
+ LCtx->dumpStack(Out, "", NL, Sep,
+ [&Out, &LO, NewAllocValsMap, NL](const LocationContext *LC) {
+ for (auto I : NewAllocValsMap) {
+ if (I.first.second != LC)
+ continue;
+ Out << '(' << I.first.second << ',' << I.first.first << ") ";
+ I.first.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+ Out << " : " << I.second << NL;
+ }
+ });
+ }
+ }
+
getCheckerManager().runCheckersForPrintState(Out, State, NL, Sep);
}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
@@ -155,7 +155,8 @@
/// printState - Called by ProgramStateManager to print checker-specific data.
virtual void printState(raw_ostream &Out, ProgramStateRef State,
- const char *NL, const char *Sep) = 0;
+ const char *NL, const char *Sep,
+ const LocationContext *LCtx = nullptr) = 0;
/// Called by CoreEngine when the analysis worklist is either empty or the
// maximum number of analysis steps have been reached.
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -299,8 +299,9 @@
const CallEvent *Call) override;
/// printState - Called by ProgramStateManager to print checker-specific data.
- void printState(raw_ostream &Out, ProgramStateRef State,
- const char *NL, const char *Sep) override;
+ void printState(raw_ostream &Out, ProgramStateRef State, const char *NL,
+ const char *Sep,
+ const LocationContext *LCtx = nullptr) override;
ProgramStateManager& getStateManager() override { return StateMgr; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42560.131519.patch
Type: text/x-patch
Size: 3928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180125/05efc9dc/attachment.bin>
More information about the cfe-commits
mailing list