1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
//== Checker.h - Registration mechanism for checkers -------------*- C++ -*--=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines Checker, used to create and register checkers.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SA_CORE_CHECKER
#define LLVM_CLANG_SA_CORE_CHECKER
#include "clang/Analysis/ProgramPoint.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
#include "llvm/Support/Casting.h"
namespace clang {
namespace ento {
class BugReporter;
namespace check {
struct _VoidCheck {
static void _register(void *checker, CheckerManager &mgr) { }
};
template <typename DECL>
class ASTDecl {
template <typename CHECKER>
static void _checkDecl(void *checker, const Decl *D, AnalysisManager& mgr,
BugReporter &BR) {
((const CHECKER *)checker)->checkASTDecl(cast<DECL>(D), mgr, BR);
}
static bool _handlesDecl(const Decl *D) {
return isa<DECL>(D);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForDecl(CheckerManager::CheckDeclFunc(checker,
_checkDecl<CHECKER>),
_handlesDecl);
}
};
class ASTCodeBody {
template <typename CHECKER>
static void _checkBody(void *checker, const Decl *D, AnalysisManager& mgr,
BugReporter &BR) {
((const CHECKER *)checker)->checkASTCodeBody(D, mgr, BR);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForBody(CheckerManager::CheckDeclFunc(checker,
_checkBody<CHECKER>));
}
};
class EndOfTranslationUnit {
template <typename CHECKER>
static void _checkEndOfTranslationUnit(void *checker,
const TranslationUnitDecl *TU,
AnalysisManager& mgr,
BugReporter &BR) {
((const CHECKER *)checker)->checkEndOfTranslationUnit(TU, mgr, BR);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr){
mgr._registerForEndOfTranslationUnit(
CheckerManager::CheckEndOfTranslationUnit(checker,
_checkEndOfTranslationUnit<CHECKER>));
}
};
template <typename STMT>
class PreStmt {
template <typename CHECKER>
static void _checkStmt(void *checker, const Stmt *S, CheckerContext &C) {
((const CHECKER *)checker)->checkPreStmt(cast<STMT>(S), C);
}
static bool _handlesStmt(const Stmt *S) {
return isa<STMT>(S);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPreStmt(CheckerManager::CheckStmtFunc(checker,
_checkStmt<CHECKER>),
_handlesStmt);
}
};
template <typename STMT>
class PostStmt {
template <typename CHECKER>
static void _checkStmt(void *checker, const Stmt *S, CheckerContext &C) {
((const CHECKER *)checker)->checkPostStmt(cast<STMT>(S), C);
}
static bool _handlesStmt(const Stmt *S) {
return isa<STMT>(S);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPostStmt(CheckerManager::CheckStmtFunc(checker,
_checkStmt<CHECKER>),
_handlesStmt);
}
};
class PreObjCMessage {
template <typename CHECKER>
static void _checkObjCMessage(void *checker, const ObjCMethodCall &msg,
CheckerContext &C) {
((const CHECKER *)checker)->checkPreObjCMessage(msg, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPreObjCMessage(
CheckerManager::CheckObjCMessageFunc(checker, _checkObjCMessage<CHECKER>));
}
};
class PostObjCMessage {
template <typename CHECKER>
static void _checkObjCMessage(void *checker, const ObjCMethodCall &msg,
CheckerContext &C) {
((const CHECKER *)checker)->checkPostObjCMessage(msg, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPostObjCMessage(
CheckerManager::CheckObjCMessageFunc(checker, _checkObjCMessage<CHECKER>));
}
};
class PreCall {
template <typename CHECKER>
static void _checkCall(void *checker, const CallEvent &msg,
CheckerContext &C) {
((const CHECKER *)checker)->checkPreCall(msg, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPreCall(
CheckerManager::CheckCallFunc(checker, _checkCall<CHECKER>));
}
};
class PostCall {
template <typename CHECKER>
static void _checkCall(void *checker, const CallEvent &msg,
CheckerContext &C) {
((const CHECKER *)checker)->checkPostCall(msg, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPostCall(
CheckerManager::CheckCallFunc(checker, _checkCall<CHECKER>));
}
};
class Location {
template <typename CHECKER>
static void _checkLocation(void *checker,
const SVal &location, bool isLoad, const Stmt *S,
CheckerContext &C) {
((const CHECKER *)checker)->checkLocation(location, isLoad, S, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForLocation(
CheckerManager::CheckLocationFunc(checker, _checkLocation<CHECKER>));
}
};
class Bind {
template <typename CHECKER>
static void _checkBind(void *checker,
const SVal &location, const SVal &val, const Stmt *S,
CheckerContext &C) {
((const CHECKER *)checker)->checkBind(location, val, S, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForBind(
CheckerManager::CheckBindFunc(checker, _checkBind<CHECKER>));
}
};
class EndAnalysis {
template <typename CHECKER>
static void _checkEndAnalysis(void *checker, ExplodedGraph &G,
BugReporter &BR, ExprEngine &Eng) {
((const CHECKER *)checker)->checkEndAnalysis(G, BR, Eng);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForEndAnalysis(
CheckerManager::CheckEndAnalysisFunc(checker, _checkEndAnalysis<CHECKER>));
}
};
class EndFunction {
template <typename CHECKER>
static void _checkEndFunction(void *checker,
CheckerContext &C) {
((const CHECKER *)checker)->checkEndFunction(C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForEndFunction(
CheckerManager::CheckEndFunctionFunc(checker, _checkEndFunction<CHECKER>));
}
};
class BranchCondition {
template <typename CHECKER>
static void _checkBranchCondition(void *checker, const Stmt *Condition,
CheckerContext & C) {
((const CHECKER *)checker)->checkBranchCondition(Condition, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForBranchCondition(
CheckerManager::CheckBranchConditionFunc(checker,
_checkBranchCondition<CHECKER>));
}
};
class LiveSymbols {
template <typename CHECKER>
static void _checkLiveSymbols(void *checker, ProgramStateRef state,
SymbolReaper &SR) {
((const CHECKER *)checker)->checkLiveSymbols(state, SR);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForLiveSymbols(
CheckerManager::CheckLiveSymbolsFunc(checker, _checkLiveSymbols<CHECKER>));
}
};
class DeadSymbols {
template <typename CHECKER>
static void _checkDeadSymbols(void *checker,
SymbolReaper &SR, CheckerContext &C) {
((const CHECKER *)checker)->checkDeadSymbols(SR, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForDeadSymbols(
CheckerManager::CheckDeadSymbolsFunc(checker, _checkDeadSymbols<CHECKER>));
}
};
class RegionChanges {
template <typename CHECKER>
static ProgramStateRef
_checkRegionChanges(void *checker,
ProgramStateRef state,
const InvalidatedSymbols *invalidated,
ArrayRef<const MemRegion *> Explicits,
ArrayRef<const MemRegion *> Regions,
const CallEvent *Call) {
return ((const CHECKER *)checker)->checkRegionChanges(state, invalidated,
Explicits, Regions, Call);
}
template <typename CHECKER>
static bool _wantsRegionChangeUpdate(void *checker,
ProgramStateRef state) {
return ((const CHECKER *)checker)->wantsRegionChangeUpdate(state);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForRegionChanges(
CheckerManager::CheckRegionChangesFunc(checker,
_checkRegionChanges<CHECKER>),
CheckerManager::WantsRegionChangeUpdateFunc(checker,
_wantsRegionChangeUpdate<CHECKER>));
}
};
class PointerEscape {
template <typename CHECKER>
static ProgramStateRef
_checkPointerEscape(void *checker,
ProgramStateRef State,
const InvalidatedSymbols &Escaped,
const CallEvent *Call,
PointerEscapeKind Kind) {
return ((const CHECKER *)checker)->checkPointerEscape(State,
Escaped,
Call,
Kind);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForPointerEscape(
CheckerManager::CheckPointerEscapeFunc(checker,
_checkPointerEscape<CHECKER>));
}
};
template <typename EVENT>
class Event {
template <typename CHECKER>
static void _checkEvent(void *checker, const void *event) {
((const CHECKER *)checker)->checkEvent(*(const EVENT *)event);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerListenerForEvent<EVENT>(
CheckerManager::CheckEventFunc(checker, _checkEvent<CHECKER>));
}
};
} // end check namespace
namespace eval {
class Assume {
template <typename CHECKER>
static ProgramStateRef _evalAssume(void *checker,
ProgramStateRef state,
const SVal &cond,
bool assumption) {
return ((const CHECKER *)checker)->evalAssume(state, cond, assumption);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForEvalAssume(
CheckerManager::EvalAssumeFunc(checker, _evalAssume<CHECKER>));
}
};
class Call {
template <typename CHECKER>
static bool _evalCall(void *checker, const CallExpr *CE, CheckerContext &C) {
return ((const CHECKER *)checker)->evalCall(CE, C);
}
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerForEvalCall(
CheckerManager::EvalCallFunc(checker, _evalCall<CHECKER>));
}
};
} // end eval namespace
class CheckerBase : public ProgramPointTag {
public:
StringRef getTagDescription() const;
/// See CheckerManager::runCheckersForPrintState.
virtual void printState(raw_ostream &Out, ProgramStateRef State,
const char *NL, const char *Sep) const { }
};
template <typename CHECK1, typename CHECK2=check::_VoidCheck,
typename CHECK3=check::_VoidCheck, typename CHECK4=check::_VoidCheck,
typename CHECK5=check::_VoidCheck, typename CHECK6=check::_VoidCheck,
typename CHECK7=check::_VoidCheck, typename CHECK8=check::_VoidCheck,
typename CHECK9=check::_VoidCheck, typename CHECK10=check::_VoidCheck,
typename CHECK11=check::_VoidCheck,typename CHECK12=check::_VoidCheck,
typename CHECK13=check::_VoidCheck,typename CHECK14=check::_VoidCheck,
typename CHECK15=check::_VoidCheck,typename CHECK16=check::_VoidCheck,
typename CHECK17=check::_VoidCheck,typename CHECK18=check::_VoidCheck,
typename CHECK19=check::_VoidCheck,typename CHECK20=check::_VoidCheck,
typename CHECK21=check::_VoidCheck,typename CHECK22=check::_VoidCheck,
typename CHECK23=check::_VoidCheck,typename CHECK24=check::_VoidCheck>
class Checker;
template <>
class Checker<check::_VoidCheck>
: public CheckerBase
{
virtual void anchor();
public:
static void _register(void *checker, CheckerManager &mgr) { }
};
template <typename CHECK1, typename CHECK2, typename CHECK3, typename CHECK4,
typename CHECK5, typename CHECK6, typename CHECK7, typename CHECK8,
typename CHECK9, typename CHECK10,typename CHECK11,typename CHECK12,
typename CHECK13,typename CHECK14,typename CHECK15,typename CHECK16,
typename CHECK17,typename CHECK18,typename CHECK19,typename CHECK20,
typename CHECK21,typename CHECK22,typename CHECK23,typename CHECK24>
class Checker
: public CHECK1,
public Checker<CHECK2, CHECK3, CHECK4, CHECK5, CHECK6, CHECK7,
CHECK8, CHECK9, CHECK10,CHECK11,CHECK12,CHECK13,
CHECK14,CHECK15,CHECK16,CHECK17,CHECK18,CHECK19,
CHECK20,CHECK21,CHECK22,CHECK23,CHECK24> {
public:
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
CHECK1::_register(checker, mgr);
Checker<CHECK2, CHECK3, CHECK4, CHECK5, CHECK6, CHECK7,
CHECK8, CHECK9, CHECK10,CHECK11,CHECK12,CHECK13,
CHECK14,CHECK15,CHECK16,CHECK17,CHECK18,CHECK19,
CHECK20,CHECK21,CHECK22,CHECK23,CHECK24>::_register(checker, mgr);
}
};
template <typename EVENT>
class EventDispatcher {
CheckerManager *Mgr;
public:
EventDispatcher() : Mgr(0) { }
template <typename CHECKER>
static void _register(CHECKER *checker, CheckerManager &mgr) {
mgr._registerDispatcherForEvent<EVENT>();
static_cast<EventDispatcher<EVENT> *>(checker)->Mgr = &mgr;
}
void dispatchEvent(const EVENT &event) const {
Mgr->_dispatchEvent(event);
}
};
/// \brief We dereferenced a location that may be null.
struct ImplicitNullDerefEvent {
SVal Location;
bool IsLoad;
ExplodedNode *SinkNode;
BugReporter *BR;
};
/// \brief A helper class which wraps a boolean value set to false by default.
struct DefaultBool {
bool val;
DefaultBool() : val(false) {}
operator bool() const { return val; }
DefaultBool &operator=(bool b) { val = b; return *this; }
};
} // end ento namespace
} // end clang namespace
#endif
|