r182186 - [analyzer] Add a debug dump for PathPieces, a list of PathDiagnosticPieces.
Jordan Rose
jordan_rose at apple.com
Fri May 17 19:26:59 PDT 2013
Author: jrose
Date: Fri May 17 21:26:59 2013
New Revision: 182186
URL: http://llvm.org/viewvc/llvm-project?rev=182186&view=rev
Log:
[analyzer] Add a debug dump for PathPieces, a list of PathDiagnosticPieces.
Originally implemented by Ted, extended by me.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=182186&r1=182185&r2=182186&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Fri May 17 21:26:59 2013
@@ -415,6 +415,8 @@ public:
flattenTo(Result, Result, ShouldFlattenMacros);
return Result;
}
+
+ LLVM_ATTRIBUTE_USED void dump() const;
};
class PathDiagnosticSpotPiece : public PathDiagnosticPiece {
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=182186&r1=182185&r2=182186&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Fri May 17 21:26:59 2013
@@ -1873,6 +1873,60 @@ static bool isIncrementOrInitInForLoop(c
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) {
More information about the cfe-commits
mailing list