1 //===- AnalysisOrderChecker - Print callbacks called ------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This checker prints callbacks that are called during analysis. 11 // This is required to ensure that callbacks are fired in order 12 // and do not duplicate or get lost. 13 // Feel free to extend this checker with any callback you need to check. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #include "ClangSACheckers.h" 18 #include "clang/StaticAnalyzer/Core/Checker.h" 19 #include "clang/StaticAnalyzer/Core/CheckerManager.h" 20 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" 21 22 using namespace clang; 23 using namespace ento; 24 25 namespace { 26 27 class AnalysisOrderChecker : public Checker< check::PreStmt<CastExpr>, 28 check::PostStmt<CastExpr>> { 29 bool isCallbackEnabled(CheckerContext &C, StringRef CallbackName) const { 30 AnalyzerOptions &Opts = C.getAnalysisManager().getAnalyzerOptions(); 31 return Opts.getBooleanOption("*", false, this) || 32 Opts.getBooleanOption(CallbackName, false, this); 33 } 34 35 public: 36 void checkPreStmt(const CastExpr *CE, CheckerContext &C) const { 37 if (isCallbackEnabled(C, "PreStmtCastExpr")) 38 llvm::errs() << "PreStmt<CastExpr> (Kind : " << CE->getCastKindName() 39 << ")\n"; 40 } 41 42 void checkPostStmt(const CastExpr *CE, CheckerContext &C) const { 43 if (isCallbackEnabled(C, "PostStmtCastExpr")) 44 llvm::errs() << "PostStmt<CastExpr> (Kind : " << CE->getCastKindName() 45 << ")\n"; 46 } 47 }; 48 } 49 50 //===----------------------------------------------------------------------===// 51 // Registration. 52 //===----------------------------------------------------------------------===// 53 54 void ento::registerAnalysisOrderChecker(CheckerManager &mgr) { 55 mgr.registerChecker<AnalysisOrderChecker>(); 56 } 57