19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/SmallPtrSet.h"
21#include "llvm/Support/raw_ostream.h"
27#define DEBUG_TYPE "StatsChecker"
31 "The # of unreachable blocks in analyzing top level functions");
34class AnalyzerStatsChecker :
public Checker<check::EndAnalysis> {
43 const CFG *
C =
nullptr;
45 llvm::SmallPtrSet<const CFGBlock*, 32> reachable;
52 for (
const ExplodedNode &N : G.
nodes()) {
59 if (std::optional<BlockEntrance> BE = P.
getAs<BlockEntrance>()) {
60 const CFGBlock *CB = BE->getBlock();
69 unsigned total = llvm::size(*
C);
70 auto IsUnreachable = [&](
const CFGBlock *CB) {
return !reachable.count(CB); };
71 unsigned unreachable = llvm::count_if(*
C, IsUnreachable);
81 llvm::raw_svector_ostream output(buf);
95 std::string NameOfRootFunction = std::string(output.str());
97 output <<
" -> Total CFGBlocks: " << total <<
" | Unreachable CFGBlocks: "
100 <<
" | Empty WorkList: "
103 B.
EmitBasicReport(D,
this,
"Analyzer Statistics",
"Internal Statistics",
104 output.str(), PathDiagnosticLocation(D, SM));
109 const CFGBlock *Exit = BE.getBlock();
112 const CFGElement &CE = Exit->front();
113 if (std::optional<CFGStmt> CS = CE.
getAs<CFGStmt>()) {
114 SmallString<128> bufI;
115 llvm::raw_svector_ostream outputI(bufI);
116 outputI <<
"(" << NameOfRootFunction <<
")" <<
117 ": The analyzer generated a sink at this point";
119 D,
this,
"Sink Point",
"Internal Statistics", outputI.str(),
125void ento::registerAnalyzerStatsChecker(CheckerManager &mgr) {
129bool ento::shouldRegisterAnalyzerStatsChecker(
const CheckerManager &mgr) {
#define STAT_COUNTER(VARNAME, DESC)
Defines the SourceManager interface.
std::optional< T > getAs() const
Convert to the specified CFGElement type, returning std::nullopt if this CFGElement is not of the des...
SourceLocation getLocation() const
unsigned getColumn() const
Return the presumed column number of this location.
unsigned getLine() const
Return the presumed line number of this location.
const StackFrame * getStackFrame() const
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
const Decl * getDecl() const
BugReporter is a utility class for generating PathDiagnostics for analysis.
const SourceManager & getSourceManager()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerFrontend *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges={}, ArrayRef< FixItHint > Fixits={})
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
auto exhausted_blocks() const
llvm::iterator_range< node_iterator > nodes()
const StackFrame * getRootStackFrame() const
const CoreEngine & getCoreEngine() const
bool hasEmptyWorkList() const
bool wasBlocksExhausted() const
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
const Fact * ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
U cast(CodeGen::Address addr)