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();
72 const CFGBlock *CB = *I;
75 if (!reachable.count(CB)) {
88 llvm::raw_svector_ostream output(buf);
102 std::string NameOfRootFunction = std::string(output.str());
104 output <<
" -> Total CFGBlocks: " << total <<
" | Unreachable CFGBlocks: "
107 <<
" | Empty WorkList: "
110 B.
EmitBasicReport(D,
this,
"Analyzer Statistics",
"Internal Statistics",
111 output.str(), PathDiagnosticLocation(D,
SM));
116 const CFGBlock *Exit = BE.getDst();
119 const CFGElement &CE = Exit->front();
120 if (std::optional<CFGStmt> CS = CE.
getAs<CFGStmt>()) {
121 SmallString<128> bufI;
122 llvm::raw_svector_ostream outputI(bufI);
123 outputI <<
"(" << NameOfRootFunction <<
")" <<
124 ": The analyzer generated a sink at this point";
126 D,
this,
"Sink Point",
"Internal Statistics", outputI.str(),
132void ento::registerAnalyzerStatsChecker(CheckerManager &mgr) {
136bool 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...
CFGBlockListTy::const_iterator const_iterator
SourceLocation getLocation() const
const Decl * getDecl() const
unsigned getColumn() const
Return the presumed column number of this location.
unsigned getLine() const
Return the presumed line number of this location.
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
const LocationContext * getLocationContext() 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 CoreEngine & getCoreEngine() const
const LocationContext * getRootLocationContext() 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.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
U cast(CodeGen::Address addr)