18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/Statistic.h"
21 #include "llvm/Support/raw_ostream.h"
23 using namespace clang;
26 #define DEBUG_TYPE "StatsChecker"
29 "The # of blocks in top level functions");
31 "The # of unreachable blocks in analyzing top level functions");
34 class AnalyzerStatsChecker :
public Checker<check::EndAnalysis> {
36 void checkEndAnalysis(ExplodedGraph &G, BugReporter &B,ExprEngine &Eng)
const;
40 void AnalyzerStatsChecker::checkEndAnalysis(ExplodedGraph &G,
42 ExprEngine &Eng)
const {
43 const CFG *
C =
nullptr;
48 const ExplodedNode *GraphRoot = *G.roots_begin();
49 const LocationContext *LC = GraphRoot->getLocation().getLocationContext();
55 I != G.nodes_end(); ++I) {
59 if (D !=
P.getLocationContext()->getDecl())
71 unsigned total = 0, unreachable = 0;
78 if (!reachable.count(CB)) {
91 llvm::raw_svector_ostream output(buf);
96 if (isa<FunctionDecl, ObjCMethodDecl>(D)) {
99 }
else if (isa<BlockDecl>(D)) {
103 NumBlocksUnreachable += unreachable;
107 output <<
" -> Total CFGBlocks: " << total <<
" | Unreachable CFGBlocks: "
108 << unreachable <<
" | Exhausted Block: "
109 << (Eng.wasBlocksExhausted() ?
"yes" :
"no")
110 <<
" | Empty WorkList: "
111 << (Eng.hasEmptyWorkList() ?
"yes" :
"no");
113 B.EmitBasicReport(D,
this,
"Analyzer Statistics",
"Internal Statistics",
114 output.str(), PathDiagnosticLocation(D,
SM));
117 typedef CoreEngine::BlocksExhausted::const_iterator ExhaustedIterator;
118 const CoreEngine &CE = Eng.getCoreEngine();
119 for (ExhaustedIterator I = CE.blocks_exhausted_begin(),
120 E = CE.blocks_exhausted_end(); I != E; ++I) {
128 llvm::raw_svector_ostream outputI(bufI);
129 outputI <<
"(" << NameOfRootFunction <<
")" <<
130 ": The analyzer generated a sink at this point";
132 D,
this,
"Sink Point",
"Internal Statistics", outputI.str(),
138 void ento::registerAnalyzerStatsChecker(CheckerManager &mgr) {
139 mgr.registerChecker<AnalyzerStatsChecker>();
142 bool ento::shouldRegisterAnalyzerStatsChecker(
const CheckerManager &mgr) {