19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/Statistic.h"
22 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
27 #define DEBUG_TYPE "StatsChecker"
30 "The # of blocks in top level functions");
32 "The # of unreachable blocks in analyzing top level functions");
35 class AnalyzerStatsChecker :
public Checker<check::EndAnalysis> {
44 const CFG *
C =
nullptr;
46 llvm::SmallPtrSet<const CFGBlock*, 32> reachable;
72 unsigned total = 0, unreachable = 0;
79 if (!reachable.count(CB)) {
92 llvm::raw_svector_ostream output(buf);
97 if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) {
101 else if (isa<BlockDecl>(D)) {
105 NumBlocksUnreachable += unreachable;
107 std::string NameOfRootFunction = output.str();
109 output <<
" -> Total CFGBlocks: " << total <<
" | Unreachable CFGBlocks: "
110 << unreachable <<
" | Exhausted Block: "
112 <<
" | Empty WorkList: "
115 B.
EmitBasicReport(D,
this,
"Analyzer Statistics",
"Internal Statistics",
119 typedef CoreEngine::BlocksExhausted::const_iterator ExhaustedIterator;
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(),
unsigned getColumn() const
Return the presumed column number of this location.
Defines the SourceManager interface.
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
BlocksExhausted::const_iterator blocks_exhausted_end() const
roots_iterator roots_begin()
BlocksExhausted::const_iterator blocks_exhausted_begin() const
unsigned getLine() const
Return the presumed line number of this location.
detail::InMemoryDirectory::const_iterator I
CFGBlock - Represents a single basic block in a source-level CFG.
const CFGBlock * getDst() const
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Represents an unpacked "presumed" location which can be presented to the user.
BugReporter is a utility class for generating PathDiagnostics for analysis.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
CHECKER * registerChecker()
Used to register checkers.
node_iterator nodes_begin()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=None)
node_iterator nodes_end()
const Decl * getDecl() const
CoreEngine - Implements the core logic of the graph-reachability analysis.
const LocationContext * getLocationContext() const
detail::InMemoryDirectory::const_iterator E
Optional< T > getAs() const
Convert to the specified ProgramPoint type, returning None if this ProgramPoint is not of the desired...
bool wasBlocksExhausted() const
bool hasEmptyWorkList() const
SourceManager & getSourceManager()
CFGElement - Represents a top-level expression in a basic block.
AllNodesTy::iterator node_iterator
STATISTIC(NumBlocks,"The # of blocks in top level functions")
NamedDecl - This represents a decl with a name.
const CoreEngine & getCoreEngine() const
This class handles loading and caching of source files into memory.
Optional< T > getAs() const
Convert to the specified CFGElement type, returning None if this CFGElement is not of the desired typ...
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.