[PATCH] D31541: [analyzer] MisusedMovedObjectChecker: Add a printState() method.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 31 09:16:48 PDT 2017


NoQ created this revision.

The `printState()` method adds the checker's information to the `State->dump()`. I find it very handy when debugging by looking at the exploded graphs, so i think it's great to have this method implemented in all checkers. It helped me already.

I think it's not a problem if the graphs become too large when all checkers print their state, because since you're always only debugging a few checkers, you can easily disable the rest of them.


https://reviews.llvm.org/D31541

Files:
  lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp


Index: lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
@@ -56,6 +56,8 @@
                      ArrayRef<const MemRegion *> ExplicitRegions,
                      ArrayRef<const MemRegion *> Regions,
                      const LocationContext *LCtx, const CallEvent *Call) const;
+  void printState(raw_ostream &Out, ProgramStateRef State,
+                  const char *NL, const char *Sep) const override;
 
 private:
   class MovedBugVisitor : public BugReporterVisitorImpl<MovedBugVisitor> {
@@ -476,6 +478,25 @@
   return State;
 }
 
+void MisusedMovedObjectChecker::printState(raw_ostream &Out,
+                                           ProgramStateRef State,
+                                           const char *NL,
+                                           const char *Sep) const {
+
+  TrackedRegionMapTy RS = State->get<TrackedRegionMap>();
+
+  if (!RS.isEmpty()) {
+    Out << Sep << "Moved-from objects :" << NL;
+    for (auto I: RS) {
+      I.first->dumpToStream(Out);
+      if (I.second.isMoved())
+        Out << ": moved";
+      else
+        Out << ": moved and reported";
+      Out << NL;
+    }
+  }
+}
 void ento::registerMisusedMovedObjectChecker(CheckerManager &mgr) {
   mgr.registerChecker<MisusedMovedObjectChecker>();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31541.93661.patch
Type: text/x-patch
Size: 1462 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170331/f1e356bb/attachment.bin>


More information about the cfe-commits mailing list