24 using namespace clang;
29 class AnalysisOrderChecker
30 :
public Checker<check::PreStmt<CastExpr>,
31 check::PostStmt<CastExpr>,
32 check::PreStmt<ArraySubscriptExpr>,
33 check::PostStmt<ArraySubscriptExpr>,
34 check::PreStmt<CXXNewExpr>,
35 check::PostStmt<CXXNewExpr>,
36 check::PreStmt<OffsetOfExpr>,
37 check::PostStmt<OffsetOfExpr>,
46 bool isCallbackEnabled(
AnalyzerOptions &Opts, StringRef CallbackName)
const {
51 bool isCallbackEnabled(CheckerContext &C, StringRef CallbackName)
const {
53 return isCallbackEnabled(Opts, CallbackName);
58 .getAnalysisManager().getAnalyzerOptions();
59 return isCallbackEnabled(Opts, CallbackName);
63 void checkPreStmt(
const CastExpr *CE, CheckerContext &C)
const {
64 if (isCallbackEnabled(C,
"PreStmtCastExpr"))
69 void checkPostStmt(
const CastExpr *CE, CheckerContext &C)
const {
70 if (isCallbackEnabled(C,
"PostStmtCastExpr"))
76 CheckerContext &C)
const {
77 if (isCallbackEnabled(C,
"PreStmtArraySubscriptExpr"))
78 llvm::errs() <<
"PreStmt<ArraySubscriptExpr>\n";
82 CheckerContext &C)
const {
83 if (isCallbackEnabled(C,
"PostStmtArraySubscriptExpr"))
84 llvm::errs() <<
"PostStmt<ArraySubscriptExpr>\n";
87 void checkPreStmt(
const CXXNewExpr *NE, CheckerContext &C)
const {
88 if (isCallbackEnabled(C,
"PreStmtCXXNewExpr"))
89 llvm::errs() <<
"PreStmt<CXXNewExpr>\n";
92 void checkPostStmt(
const CXXNewExpr *NE, CheckerContext &C)
const {
93 if (isCallbackEnabled(C,
"PostStmtCXXNewExpr"))
94 llvm::errs() <<
"PostStmt<CXXNewExpr>\n";
97 void checkPreStmt(
const OffsetOfExpr *OOE, CheckerContext &C)
const {
98 if (isCallbackEnabled(C,
"PreStmtOffsetOfExpr"))
99 llvm::errs() <<
"PreStmt<OffsetOfExpr>\n";
102 void checkPostStmt(
const OffsetOfExpr *OOE, CheckerContext &C)
const {
103 if (isCallbackEnabled(C,
"PostStmtOffsetOfExpr"))
104 llvm::errs() <<
"PostStmt<OffsetOfExpr>\n";
107 void checkPreCall(
const CallEvent &Call, CheckerContext &C)
const {
108 if (isCallbackEnabled(C,
"PreCall")) {
109 llvm::errs() <<
"PreCall";
110 if (
const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Call.getDecl()))
111 llvm::errs() <<
" (" << ND->getQualifiedNameAsString() <<
')';
112 llvm::errs() <<
'\n';
116 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const {
117 if (isCallbackEnabled(C,
"PostCall")) {
118 llvm::errs() <<
"PostCall";
119 if (
const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Call.getDecl()))
120 llvm::errs() <<
" (" << ND->getQualifiedNameAsString() <<
')';
121 llvm::errs() <<
'\n';
125 void checkEndFunction(
const ReturnStmt *S, CheckerContext &C)
const {
126 if (isCallbackEnabled(C,
"EndFunction")) {
127 llvm::errs() <<
"EndFunction\nReturnStmt: " << (S ?
"yes" :
"no") <<
"\n";
131 llvm::errs() <<
"CFGElement: ";
132 CFGStmtMap *Map = C.getCurrentAnalysisDeclContext()->getCFGStmtMap();
136 llvm::errs() <<
"CFGStmt\n";
138 llvm::errs() <<
"CFGAutomaticObjDtor\n";
142 void checkNewAllocator(
const CXXNewExpr *CNE, SVal Target,
143 CheckerContext &C)
const {
144 if (isCallbackEnabled(C,
"NewAllocator"))
145 llvm::errs() <<
"NewAllocator\n";
148 void checkBind(SVal Loc, SVal Val,
const Stmt *S, CheckerContext &C)
const {
149 if (isCallbackEnabled(C,
"Bind"))
150 llvm::errs() <<
"Bind\n";
153 void checkLiveSymbols(
ProgramStateRef State, SymbolReaper &SymReaper)
const {
154 if (isCallbackEnabled(State,
"LiveSymbols"))
155 llvm::errs() <<
"LiveSymbols\n";
164 if (isCallbackEnabled(State,
"RegionChanges"))
165 llvm::errs() <<
"RegionChanges\n";
175 void ento::registerAnalysisOrderChecker(CheckerManager &mgr) {
176 mgr.registerChecker<AnalysisOrderChecker>();
179 bool ento::shouldRegisterAnalysisOrderChecker(
const LangOptions &LO) {
llvm::DenseSet< SymbolRef > InvalidatedSymbols
Stmt - This represents one statement.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Defines the clang::Expr interface and subclasses for C++ expressions.
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CFGBlock * getBlock(Stmt *S)
Returns the CFGBlock the specified Stmt* appears in.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Optional< T > getAs() const
Convert to the specified CFGElement type, returning None if this CFGElement is not of the desired typ...
bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option's string value as a boolean.
Dataflow Directional Tag Classes.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
static const char * getCastKindName(CastKind CK)
Stores options for the analyzer from the command line.
Represents a top-level expression in a basic block.
This represents a decl that may have a name.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).