25 using namespace clang;
30 class AnalysisOrderChecker
31 :
public Checker<check::PreStmt<CastExpr>,
32 check::PostStmt<CastExpr>,
33 check::PreStmt<ArraySubscriptExpr>,
34 check::PostStmt<ArraySubscriptExpr>,
35 check::PreStmt<CXXNewExpr>,
36 check::PostStmt<CXXNewExpr>,
37 check::PreStmt<OffsetOfExpr>,
38 check::PostStmt<OffsetOfExpr>,
47 bool isCallbackEnabled(
AnalyzerOptions &Opts, StringRef CallbackName)
const {
52 bool isCallbackEnabled(CheckerContext &C, StringRef CallbackName)
const {
54 return isCallbackEnabled(Opts, CallbackName);
59 .getAnalysisManager().getAnalyzerOptions();
60 return isCallbackEnabled(Opts, CallbackName);
64 void checkPreStmt(
const CastExpr *CE, CheckerContext &C)
const {
65 if (isCallbackEnabled(C,
"PreStmtCastExpr"))
70 void checkPostStmt(
const CastExpr *CE, CheckerContext &C)
const {
71 if (isCallbackEnabled(C,
"PostStmtCastExpr"))
77 CheckerContext &C)
const {
78 if (isCallbackEnabled(C,
"PreStmtArraySubscriptExpr"))
79 llvm::errs() <<
"PreStmt<ArraySubscriptExpr>\n";
83 CheckerContext &C)
const {
84 if (isCallbackEnabled(C,
"PostStmtArraySubscriptExpr"))
85 llvm::errs() <<
"PostStmt<ArraySubscriptExpr>\n";
88 void checkPreStmt(
const CXXNewExpr *NE, CheckerContext &C)
const {
89 if (isCallbackEnabled(C,
"PreStmtCXXNewExpr"))
90 llvm::errs() <<
"PreStmt<CXXNewExpr>\n";
93 void checkPostStmt(
const CXXNewExpr *NE, CheckerContext &C)
const {
94 if (isCallbackEnabled(C,
"PostStmtCXXNewExpr"))
95 llvm::errs() <<
"PostStmt<CXXNewExpr>\n";
98 void checkPreStmt(
const OffsetOfExpr *OOE, CheckerContext &C)
const {
99 if (isCallbackEnabled(C,
"PreStmtOffsetOfExpr"))
100 llvm::errs() <<
"PreStmt<OffsetOfExpr>\n";
103 void checkPostStmt(
const OffsetOfExpr *OOE, CheckerContext &C)
const {
104 if (isCallbackEnabled(C,
"PostStmtOffsetOfExpr"))
105 llvm::errs() <<
"PostStmt<OffsetOfExpr>\n";
108 void checkPreCall(
const CallEvent &Call, CheckerContext &C)
const {
109 if (isCallbackEnabled(C,
"PreCall")) {
110 llvm::errs() <<
"PreCall";
111 if (
const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Call.getDecl()))
112 llvm::errs() <<
" (" << ND->getQualifiedNameAsString() <<
')';
113 llvm::errs() <<
'\n';
117 void checkPostCall(
const CallEvent &Call, CheckerContext &C)
const {
118 if (isCallbackEnabled(C,
"PostCall")) {
119 llvm::errs() <<
"PostCall";
120 if (
const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Call.getDecl()))
121 llvm::errs() <<
" (" << ND->getQualifiedNameAsString() <<
')';
122 llvm::errs() <<
'\n';
126 void checkEndFunction(
const ReturnStmt *S, CheckerContext &C)
const {
127 if (isCallbackEnabled(C,
"EndFunction")) {
128 llvm::errs() <<
"EndFunction\nReturnStmt: " << (S ?
"yes" :
"no") <<
"\n";
132 llvm::errs() <<
"CFGElement: ";
133 CFGStmtMap *Map = C.getCurrentAnalysisDeclContext()->getCFGStmtMap();
137 llvm::errs() <<
"CFGStmt\n";
139 llvm::errs() <<
"CFGAutomaticObjDtor\n";
143 void checkNewAllocator(
const CXXNewExpr *CNE, SVal Target,
144 CheckerContext &C)
const {
145 if (isCallbackEnabled(C,
"NewAllocator"))
146 llvm::errs() <<
"NewAllocator\n";
149 void checkBind(SVal Loc, SVal Val,
const Stmt *S, CheckerContext &C)
const {
150 if (isCallbackEnabled(C,
"Bind"))
151 llvm::errs() <<
"Bind\n";
154 void checkLiveSymbols(
ProgramStateRef State, SymbolReaper &SymReaper)
const {
155 if (isCallbackEnabled(State,
"LiveSymbols"))
156 llvm::errs() <<
"LiveSymbols\n";
165 if (isCallbackEnabled(State,
"RegionChanges"))
166 llvm::errs() <<
"RegionChanges\n";
176 void ento::registerAnalysisOrderChecker(CheckerManager &mgr) {
177 mgr.registerChecker<AnalysisOrderChecker>();
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...
bool getCheckerBooleanOption(StringRef Name, bool DefaultVal, const ento::CheckerBase *C, bool SearchInParents=false) const
Interprets an option's string value as a boolean.
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...
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).