NoQ updated this revision to Diff 132010.
NoQ added a comment.

Address comments :)


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
@@ -383,8 +383,57 @@
                                                          LCtx, Call);
 }
 
+static void printInitializedTemporaries(raw_ostream &Out, ProgramStateRef State,
+                                        const char *NL, const char *Sep,
+                                        const LocationContext *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;
+          }
+        });
+  }
+}
+
+static void printCXXNewAllocatorValues(raw_ostream &Out, ProgramStateRef State,
+                                        const char *NL, const char *Sep,
+                                        const LocationContext *LCtx) {
+  LangOptions LO; // FIXME.
+  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) {
+          std::pair<const CXXNewExpr *, const LocationContext *> Key = I.first;
+          SVal Value = I.second;
+            if (Key.second != LC)
+              continue;
+            Out << '(' << Key.second << ',' << Key.first << ") ";
+            Key.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+            Out << " : " << Value << NL;
+          }
+        });
+  }
+}
+
 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) {
+    printInitializedTemporaries(Out, State, NL, Sep, LCtx);
+    printCXXNewAllocatorValues(Out, State, NL, Sep, LCtx);
+  }
   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; }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to