1 //===- AnalysisOrderChecker - Print callbacks called ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
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"
22 using namespace clang;
27 class AnalysisOrderChecker : public Checker< check::PreStmt<CastExpr>,
28 check::PostStmt<CastExpr>,
29 check::PreStmt<ArraySubscriptExpr>,
30 check::PostStmt<ArraySubscriptExpr>> {
31 bool isCallbackEnabled(CheckerContext &C, StringRef CallbackName) const {
32 AnalyzerOptions &Opts = C.getAnalysisManager().getAnalyzerOptions();
33 return Opts.getBooleanOption("*", false, this) ||
34 Opts.getBooleanOption(CallbackName, false, this);
38 void checkPreStmt(const CastExpr *CE, CheckerContext &C) const {
39 if (isCallbackEnabled(C, "PreStmtCastExpr"))
40 llvm::errs() << "PreStmt<CastExpr> (Kind : " << CE->getCastKindName()
44 void checkPostStmt(const CastExpr *CE, CheckerContext &C) const {
45 if (isCallbackEnabled(C, "PostStmtCastExpr"))
46 llvm::errs() << "PostStmt<CastExpr> (Kind : " << CE->getCastKindName()
50 void checkPreStmt(const ArraySubscriptExpr *SubExpr, CheckerContext &C) const {
51 if (isCallbackEnabled(C, "PreStmtArraySubscriptExpr"))
52 llvm::errs() << "PreStmt<ArraySubscriptExpr>\n";
55 void checkPostStmt(const ArraySubscriptExpr *SubExpr, CheckerContext &C) const {
56 if (isCallbackEnabled(C, "PostStmtArraySubscriptExpr"))
57 llvm::errs() << "PostStmt<ArraySubscriptExpr>\n";
62 //===----------------------------------------------------------------------===//
64 //===----------------------------------------------------------------------===//
66 void ento::registerAnalysisOrderChecker(CheckerManager &mgr) {
67 mgr.registerChecker<AnalysisOrderChecker>();