23 #include "llvm/Support/Process.h" 25 using namespace clang;
33 class DominatorsTreeDumper :
public Checker<check::ASTCodeBody> {
35 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
36 BugReporter &BR)
const {
46 void ento::registerDominatorsTreeDumper(CheckerManager &mgr) {
47 mgr.registerChecker<DominatorsTreeDumper>();
50 bool ento::shouldRegisterDominatorsTreeDumper(
const LangOptions &LO) {
59 class PostDominatorsTreeDumper :
public Checker<check::ASTCodeBody> {
61 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
62 BugReporter &BR)
const {
72 void ento::registerPostDominatorsTreeDumper(CheckerManager &mgr) {
73 mgr.registerChecker<PostDominatorsTreeDumper>();
76 bool ento::shouldRegisterPostDominatorsTreeDumper(
const LangOptions &LO) {
85 class ControlDependencyTreeDumper :
public Checker<check::ASTCodeBody> {
87 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
88 BugReporter &BR)
const {
97 void ento::registerControlDependencyTreeDumper(CheckerManager &mgr) {
98 mgr.registerChecker<ControlDependencyTreeDumper>();
101 bool ento::shouldRegisterControlDependencyTreeDumper(
const LangOptions &LO) {
110 class LiveVariablesDumper :
public Checker<check::ASTCodeBody> {
112 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
113 BugReporter &BR)
const {
115 L->dumpBlockLiveness(mgr.getSourceManager());
121 void ento::registerLiveVariablesDumper(CheckerManager &mgr) {
122 mgr.registerChecker<LiveVariablesDumper>();
125 bool ento::shouldRegisterLiveVariablesDumper(
const LangOptions &LO) {
134 class LiveStatementsDumper :
public Checker<check::ASTCodeBody> {
136 void checkASTCodeBody(
const Decl *D, AnalysisManager& Mgr,
137 BugReporter &BR)
const {
139 L->dumpStmtLiveness(Mgr.getSourceManager());
144 void ento::registerLiveStatementsDumper(CheckerManager &mgr) {
145 mgr.registerChecker<LiveStatementsDumper>();
148 bool ento::shouldRegisterLiveStatementsDumper(
const LangOptions &LO) {
157 class CFGViewer :
public Checker<check::ASTCodeBody> {
159 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
160 BugReporter &BR)
const {
161 if (
CFG *cfg = mgr.getCFG(D)) {
162 cfg->viewCFG(mgr.getLangOpts());
168 void ento::registerCFGViewer(CheckerManager &mgr) {
169 mgr.registerChecker<CFGViewer>();
172 bool ento::shouldRegisterCFGViewer(
const LangOptions &LO) {
181 class CFGDumper :
public Checker<check::ASTCodeBody> {
183 void checkASTCodeBody(
const Decl *D, AnalysisManager& mgr,
184 BugReporter &BR)
const {
187 Policy.PolishForDeclaration =
true;
188 D->
print(llvm::errs(), Policy);
190 if (
CFG *cfg = mgr.getCFG(D)) {
191 cfg->dump(mgr.getLangOpts(),
192 llvm::sys::Process::StandardErrHasColors());
198 void ento::registerCFGDumper(CheckerManager &mgr) {
199 mgr.registerChecker<CFGDumper>();
202 bool ento::shouldRegisterCFGDumper(
const LangOptions &LO) {
211 class CallGraphViewer :
public Checker< check::ASTDecl<TranslationUnitDecl> > {
214 BugReporter &BR)
const {
222 void ento::registerCallGraphViewer(CheckerManager &mgr) {
223 mgr.registerChecker<CallGraphViewer>();
226 bool ento::shouldRegisterCallGraphViewer(
const LangOptions &LO) {
235 class CallGraphDumper :
public Checker< check::ASTDecl<TranslationUnitDecl> > {
238 BugReporter &BR)
const {
246 void ento::registerCallGraphDumper(CheckerManager &mgr) {
247 mgr.registerChecker<CallGraphDumper>();
250 bool ento::shouldRegisterCallGraphDumper(
const LangOptions &LO) {
259 class ConfigDumper :
public Checker< check::EndOfTranslationUnit > {
262 static int compareEntry(
const Table::MapEntryTy *
const *LHS,
263 const Table::MapEntryTy *
const *RHS) {
264 return (*LHS)->getKey().compare((*RHS)->getKey());
269 AnalysisManager& mgr,
270 BugReporter &BR)
const {
271 const Table &Config = mgr.options.Config;
274 for (Table::const_iterator I = Config.begin(), E = Config.end(); I != E;
277 llvm::array_pod_sort(Keys.begin(), Keys.end(), compareEntry);
279 llvm::errs() <<
"[config]\n";
280 for (
unsigned I = 0, E = Keys.size(); I != E; ++I)
281 llvm::errs() << Keys[I]->getKey() <<
" = " 282 << (Keys[I]->second.empty() ?
"\"\"" : Keys[I]->second)
285 llvm::errs() <<
"[stats]\n" <<
"num-entries = " << Keys.size() <<
'\n';
290 void ento::registerConfigDumper(CheckerManager &mgr) {
291 mgr.registerChecker<ConfigDumper>();
294 bool ento::shouldRegisterConfigDumper(
const LangOptions &LO) {
303 class ExplodedGraphViewer :
public Checker< check::EndAnalysis > {
305 ExplodedGraphViewer() {}
306 void checkEndAnalysis(ExplodedGraph &G, BugReporter &B,ExprEngine &Eng)
const {
313 void ento::registerExplodedGraphViewer(CheckerManager &mgr) {
314 mgr.registerChecker<ExplodedGraphViewer>();
317 bool ento::shouldRegisterExplodedGraphViewer(
const LangOptions &LO) {
327 class ReportStmts :
public Checker<check::PreStmt<Stmt>> {
328 BuiltinBug BT_stmtLoc{
this,
"Statement"};
331 void checkPreStmt(
const Stmt *S, CheckerContext &C)
const {
332 ExplodedNode *
Node = C.generateNonFatalErrorNode();
336 auto Report = llvm::make_unique<BugReport>(BT_stmtLoc,
"Statement",
Node);
338 C.emitReport(std::move(Report));
344 void ento::registerReportStmts(CheckerManager &mgr) {
345 mgr.registerChecker<ReportStmts>();
348 bool ento::shouldRegisterReportStmts(
const LangOptions &LO) {
The AST-based call graph.
Stmt - This represents one statement.
Decl - This represents one declaration (or definition), e.g.
Describes how types, statements, expressions, and declarations should be printed. ...
unsigned TerseOutput
Provide a 'terse' output.
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
AnalysisDeclContext contains the context data for the function or method under analysis.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Dominator tree builder for Clang's CFG based on llvm::DominatorTreeBase.
LLVM_DUMP_METHOD void dump()
void dump()
Dumps immediate dominators for each block.
void buildDominatorTree(CFG *cfg)
Builds the dominator tree for a given CFG.
llvm::StringMap< std::string > ConfigTable
ast_type_traits::DynTypedNode Node
Dataflow Directional Tag Classes.
void addToCallGraph(Decl *D)
Populate the call graph with the functions in the given declaration.
The top declaration context.