]> granicus.if.org Git - clang/commitdiff
[analyzer] Add a debug dump for PathPieces, a list of PathDiagnosticPieces.
authorJordan Rose <jordan_rose@apple.com>
Sat, 18 May 2013 02:26:59 +0000 (02:26 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 18 May 2013 02:26:59 +0000 (02:26 +0000)
Originally implemented by Ted, extended by me.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182186 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
lib/StaticAnalyzer/Core/BugReporter.cpp

index e15b5e7fe7d9819672943682014ac6f4bba8accc..cae47f8916269146edf0645e62212320a79287a7 100644 (file)
@@ -415,6 +415,8 @@ public:
     flattenTo(Result, Result, ShouldFlattenMacros);
     return Result;
   }
+
+  LLVM_ATTRIBUTE_USED void dump() const;
 };
 
 class PathDiagnosticSpotPiece : public PathDiagnosticPiece {
index 519555396dd475e3e61b35e54c6acac6f753ae1a..d4277fc218dd833ac706a81323e67d203e570858 100644 (file)
@@ -1873,6 +1873,60 @@ static bool isIncrementOrInitInForLoop(const Stmt *S, const Stmt *FL) {
 typedef llvm::DenseSet<const PathDiagnosticCallPiece *>
         OptimizedCallsSet;
 
+void PathPieces::dump() const {
+  unsigned index = 0;
+  for (PathPieces::const_iterator I = begin(), E = end(); I != E; ++I ) {
+    llvm::errs() << "[" << index++ << "]";
+
+    switch ((*I)->getKind()) {
+    case PathDiagnosticPiece::Call:
+      llvm::errs() << "  CALL\n--------------\n";
+
+      if (const Stmt *SLoc = getLocStmt((*I)->getLocation())) {
+        SLoc->dump();
+      } else {
+        const PathDiagnosticCallPiece *Call = cast<PathDiagnosticCallPiece>(*I);
+        if (const NamedDecl *ND = dyn_cast<NamedDecl>(Call->getCallee()))
+          llvm::errs() << *ND << "\n";
+      }
+      break;
+    case PathDiagnosticPiece::Event:
+      llvm::errs() << "  EVENT\n--------------\n";
+      llvm::errs() << (*I)->getString() << "\n";
+      if (const Stmt *SLoc = getLocStmt((*I)->getLocation())) {
+        llvm::errs() << " ---- at ----\n";
+        SLoc->dump();
+      }
+      break;
+    case PathDiagnosticPiece::Macro:
+      llvm::errs() << "  MACRO\n--------------\n";
+      // FIXME: print which macro is being invoked.
+      break;
+    case PathDiagnosticPiece::ControlFlow: {
+      const PathDiagnosticControlFlowPiece *CP =
+        cast<PathDiagnosticControlFlowPiece>(*I);
+      llvm::errs() << "  CONTROL\n--------------\n";
+
+      if (const Stmt *s1Start = getLocStmt(CP->getStartLocation()))
+        s1Start->dump();
+      else
+        llvm::errs() << "NULL\n";
+
+      llvm::errs() << " ---- to ----\n";
+
+      if (const Stmt *s1End = getLocStmt(CP->getEndLocation()))
+        s1End->dump();
+      else
+        llvm::errs() << "NULL\n";
+
+      break;
+    }
+    }
+
+    llvm::errs() << "\n";
+  }
+}
+
 static bool optimizeEdges(PathPieces &path, SourceManager &SM,
                           OptimizedCallsSet &OCS,
                           LocationContextMap &LCM) {