blob: 91b7cf3db6f7a967f508ce317dbef407bce1a6fd [file] [log] [blame]
Ted Kremenek78d46242008-07-22 16:21:24 +00001//=-- GRExprEngineInternalChecks.cpp - Builtin GRExprEngine Checks---*- 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 file defines the BugType classes used by GRExprEngine to report
11// bugs derived from builtin checks in the path-sensitive engine.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Analysis/PathSensitive/BugReporter.h"
16#include "clang/Analysis/PathSensitive/GRExprEngine.h"
Ted Kremenekc26a8b02009-07-22 21:46:56 +000017#include "clang/Analysis/PathSensitive/CheckerVisitor.h"
Ted Kremenekdd986cc2009-05-07 00:45:33 +000018#include "clang/Analysis/PathDiagnostic.h"
Ted Kremenek8aed8062008-10-31 00:13:20 +000019#include "clang/Basic/SourceManager.h"
Ted Kremenek78d46242008-07-22 16:21:24 +000020#include "llvm/Support/Compiler.h"
Ted Kremenekad51a602008-10-31 00:18:30 +000021#include "llvm/Support/raw_ostream.h"
Ted Kremenek78d46242008-07-22 16:21:24 +000022
23using namespace clang;
Ted Kremenek53500662009-07-22 17:55:28 +000024using namespace clang::bugreporter;
Ted Kremenek78d46242008-07-22 16:21:24 +000025
26//===----------------------------------------------------------------------===//
27// Utility functions.
28//===----------------------------------------------------------------------===//
29
30template <typename ITERATOR> inline
Zhongxing Xuc5619d92009-08-06 01:32:16 +000031ExplodedNode* GetNode(ITERATOR I) {
Ted Kremenek78d46242008-07-22 16:21:24 +000032 return *I;
33}
34
35template <> inline
Zhongxing Xuc5619d92009-08-06 01:32:16 +000036ExplodedNode* GetNode(GRExprEngine::undef_arg_iterator I) {
Ted Kremenek78d46242008-07-22 16:21:24 +000037 return I->first;
38}
39
40//===----------------------------------------------------------------------===//
41// Bug Descriptions.
42//===----------------------------------------------------------------------===//
43
44namespace {
Ted Kremenekdd986cc2009-05-07 00:45:33 +000045
Ted Kremenek0c313172009-05-13 19:16:35 +000046class VISIBILITY_HIDDEN BuiltinBugReport : public RangedBugReport {
Ted Kremenekdd986cc2009-05-07 00:45:33 +000047public:
48 BuiltinBugReport(BugType& bt, const char* desc,
Zhongxing Xuc5619d92009-08-06 01:32:16 +000049 ExplodedNode *n)
Ted Kremenek0c313172009-05-13 19:16:35 +000050 : RangedBugReport(bt, desc, n) {}
Ted Kremenekdd986cc2009-05-07 00:45:33 +000051
Ted Kremenek85ac9342009-05-15 05:25:09 +000052 BuiltinBugReport(BugType& bt, const char *shortDesc, const char *desc,
Zhongxing Xuc5619d92009-08-06 01:32:16 +000053 ExplodedNode *n)
Ted Kremenek85ac9342009-05-15 05:25:09 +000054 : RangedBugReport(bt, shortDesc, desc, n) {}
55
Ted Kremenekdd986cc2009-05-07 00:45:33 +000056 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +000057 const ExplodedNode* N);
Ted Kremenekdd986cc2009-05-07 00:45:33 +000058};
59
Ted Kremenekcf118d42009-02-04 23:49:09 +000060class VISIBILITY_HIDDEN BuiltinBug : public BugType {
61 GRExprEngine &Eng;
Ted Kremenek159d2482008-12-09 00:44:16 +000062protected:
Ted Kremenekcf118d42009-02-04 23:49:09 +000063 const std::string desc;
Ted Kremenek78d46242008-07-22 16:21:24 +000064public:
Ted Kremenekcf118d42009-02-04 23:49:09 +000065 BuiltinBug(GRExprEngine *eng, const char* n, const char* d)
Ted Kremenek0c313172009-05-13 19:16:35 +000066 : BugType(n, "Logic errors"), Eng(*eng), desc(d) {}
Ted Kremenekcf118d42009-02-04 23:49:09 +000067
68 BuiltinBug(GRExprEngine *eng, const char* n)
Ted Kremenek0c313172009-05-13 19:16:35 +000069 : BugType(n, "Logic errors"), Eng(*eng), desc(n) {}
Zhongxing Xu904e1e32009-09-02 07:09:39 +000070
71 const std::string &getDescription() const { return desc; }
Ted Kremenek22bda882008-07-31 20:31:27 +000072
Ted Kremenekcf118d42009-02-04 23:49:09 +000073 virtual void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) = 0;
74
75 void FlushReports(BugReporter& BR) { FlushReportsImpl(BR, Eng); }
Ted Kremenek78d46242008-07-22 16:21:24 +000076
Ted Kremenekdd986cc2009-05-07 00:45:33 +000077 virtual void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +000078 const ExplodedNode* N,
Ted Kremenekdd986cc2009-05-07 00:45:33 +000079 BuiltinBugReport *R) {}
80
81 template <typename ITER> void Emit(BugReporter& BR, ITER I, ITER E);
Ted Kremenek78d46242008-07-22 16:21:24 +000082};
83
Ted Kremenekdd986cc2009-05-07 00:45:33 +000084
85template <typename ITER>
86void BuiltinBug::Emit(BugReporter& BR, ITER I, ITER E) {
87 for (; I != E; ++I) BR.EmitReport(new BuiltinBugReport(*this, desc.c_str(),
88 GetNode(I)));
89}
90
91void BuiltinBugReport::registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +000092 const ExplodedNode* N) {
Ted Kremenekdd986cc2009-05-07 00:45:33 +000093 static_cast<BuiltinBug&>(getBugType()).registerInitialVisitors(BRC, N, this);
94}
95
Ted Kremenek78d46242008-07-22 16:21:24 +000096class VISIBILITY_HIDDEN NullDeref : public BuiltinBug {
97public:
Ted Kremenekcf118d42009-02-04 23:49:09 +000098 NullDeref(GRExprEngine* eng)
Ted Kremenek0fa96542009-04-07 04:54:31 +000099 : BuiltinBug(eng,"Null dereference", "Dereference of null pointer") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000100
Ted Kremenekcf118d42009-02-04 23:49:09 +0000101 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000102 Emit(BR, Eng.null_derefs_begin(), Eng.null_derefs_end());
103 }
Ted Kremenekdd986cc2009-05-07 00:45:33 +0000104
105 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000106 const ExplodedNode* N,
Ted Kremenekdd986cc2009-05-07 00:45:33 +0000107 BuiltinBugReport *R) {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000108 registerTrackNullOrUndefValue(BRC, GetDerefExpr(N), N);
Ted Kremenekdd986cc2009-05-07 00:45:33 +0000109 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000110};
111
Ted Kremenek0c313172009-05-13 19:16:35 +0000112class VISIBILITY_HIDDEN NilReceiverStructRet : public BuiltinBug {
Ted Kremenek21fe8372009-02-19 04:06:22 +0000113public:
114 NilReceiverStructRet(GRExprEngine* eng) :
Ted Kremenek0c313172009-05-13 19:16:35 +0000115 BuiltinBug(eng, "'nil' receiver with struct return type") {}
Ted Kremenek21fe8372009-02-19 04:06:22 +0000116
Ted Kremenek0c313172009-05-13 19:16:35 +0000117 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek21fe8372009-02-19 04:06:22 +0000118 for (GRExprEngine::nil_receiver_struct_ret_iterator
119 I=Eng.nil_receiver_struct_ret_begin(),
120 E=Eng.nil_receiver_struct_ret_end(); I!=E; ++I) {
121
122 std::string sbuf;
123 llvm::raw_string_ostream os(sbuf);
124 PostStmt P = cast<PostStmt>((*I)->getLocation());
Ted Kremenek5f85e172009-07-22 22:35:28 +0000125 const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
Ted Kremenek21fe8372009-02-19 04:06:22 +0000126 os << "The receiver in the message expression is 'nil' and results in the"
127 " returned value (of type '"
128 << ME->getType().getAsString()
129 << "') to be garbage or otherwise undefined.";
130
Ted Kremenek0c313172009-05-13 19:16:35 +0000131 BuiltinBugReport *R = new BuiltinBugReport(*this, os.str().c_str(), *I);
Ted Kremenek21fe8372009-02-19 04:06:22 +0000132 R->addRange(ME->getReceiver()->getSourceRange());
133 BR.EmitReport(R);
134 }
135 }
Ted Kremenek0c313172009-05-13 19:16:35 +0000136
137 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000138 const ExplodedNode* N,
Ted Kremenek0c313172009-05-13 19:16:35 +0000139 BuiltinBugReport *R) {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000140 registerTrackNullOrUndefValue(BRC, GetReceiverExpr(N), N);
Ted Kremenek0c313172009-05-13 19:16:35 +0000141 }
Ted Kremenek21fe8372009-02-19 04:06:22 +0000142};
Ted Kremenek899b3de2009-04-08 03:07:17 +0000143
Ted Kremenek0c313172009-05-13 19:16:35 +0000144class VISIBILITY_HIDDEN NilReceiverLargerThanVoidPtrRet : public BuiltinBug {
Ted Kremenek899b3de2009-04-08 03:07:17 +0000145public:
146 NilReceiverLargerThanVoidPtrRet(GRExprEngine* eng) :
Ted Kremenek0c313172009-05-13 19:16:35 +0000147 BuiltinBug(eng,
148 "'nil' receiver with return type larger than sizeof(void *)") {}
Ted Kremenek899b3de2009-04-08 03:07:17 +0000149
Ted Kremenek0c313172009-05-13 19:16:35 +0000150 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek899b3de2009-04-08 03:07:17 +0000151 for (GRExprEngine::nil_receiver_larger_than_voidptr_ret_iterator
152 I=Eng.nil_receiver_larger_than_voidptr_ret_begin(),
153 E=Eng.nil_receiver_larger_than_voidptr_ret_end(); I!=E; ++I) {
154
155 std::string sbuf;
156 llvm::raw_string_ostream os(sbuf);
157 PostStmt P = cast<PostStmt>((*I)->getLocation());
Ted Kremenek5f85e172009-07-22 22:35:28 +0000158 const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(P.getStmt());
Ted Kremenek899b3de2009-04-08 03:07:17 +0000159 os << "The receiver in the message expression is 'nil' and results in the"
160 " returned value (of type '"
161 << ME->getType().getAsString()
162 << "' and of size "
163 << Eng.getContext().getTypeSize(ME->getType()) / 8
164 << " bytes) to be garbage or otherwise undefined.";
165
Ted Kremenek0c313172009-05-13 19:16:35 +0000166 BuiltinBugReport *R = new BuiltinBugReport(*this, os.str().c_str(), *I);
Ted Kremenek899b3de2009-04-08 03:07:17 +0000167 R->addRange(ME->getReceiver()->getSourceRange());
168 BR.EmitReport(R);
169 }
Ted Kremenek0c313172009-05-13 19:16:35 +0000170 }
171 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000172 const ExplodedNode* N,
Ted Kremenek0c313172009-05-13 19:16:35 +0000173 BuiltinBugReport *R) {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000174 registerTrackNullOrUndefValue(BRC, GetReceiverExpr(N), N);
Ted Kremenek899b3de2009-04-08 03:07:17 +0000175 }
176};
Ted Kremenek21fe8372009-02-19 04:06:22 +0000177
Ted Kremenek78d46242008-07-22 16:21:24 +0000178class VISIBILITY_HIDDEN UndefinedDeref : public BuiltinBug {
179public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000180 UndefinedDeref(GRExprEngine* eng)
Ted Kremenek17a8e072009-03-01 05:43:22 +0000181 : BuiltinBug(eng,"Dereference of undefined pointer value") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000182
Ted Kremenekcf118d42009-02-04 23:49:09 +0000183 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000184 Emit(BR, Eng.undef_derefs_begin(), Eng.undef_derefs_end());
185 }
Ted Kremenek0c313172009-05-13 19:16:35 +0000186
187 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000188 const ExplodedNode* N,
Ted Kremenek0c313172009-05-13 19:16:35 +0000189 BuiltinBugReport *R) {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000190 registerTrackNullOrUndefValue(BRC, GetDerefExpr(N), N);
Ted Kremenek0c313172009-05-13 19:16:35 +0000191 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000192};
193
194class VISIBILITY_HIDDEN DivZero : public BuiltinBug {
195public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000196 DivZero(GRExprEngine* eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000197 : BuiltinBug(eng,"Division-by-zero",
198 "Division by zero or undefined value.") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000199
Ted Kremenekcf118d42009-02-04 23:49:09 +0000200 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000201 Emit(BR, Eng.explicit_bad_divides_begin(), Eng.explicit_bad_divides_end());
202 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000203
204 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000205 const ExplodedNode* N,
Ted Kremenek85ac9342009-05-15 05:25:09 +0000206 BuiltinBugReport *R) {
207 registerTrackNullOrUndefValue(BRC, GetDenomExpr(N), N);
208 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000209};
210
211class VISIBILITY_HIDDEN UndefResult : public BuiltinBug {
212public:
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000213 UndefResult(GRExprEngine* eng) : BuiltinBug(eng,"Undefined result",
Ted Kremenek78d46242008-07-22 16:21:24 +0000214 "Result of operation is undefined.") {}
215
Ted Kremenekcf118d42009-02-04 23:49:09 +0000216 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000217 Emit(BR, Eng.undef_results_begin(), Eng.undef_results_end());
218 }
219};
220
221class VISIBILITY_HIDDEN BadCall : public BuiltinBug {
222public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000223 BadCall(GRExprEngine *eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000224 : BuiltinBug(eng, "Invalid function call",
Ted Kremenek17a8e072009-03-01 05:43:22 +0000225 "Called function pointer is a null or undefined pointer value") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000226
Ted Kremenekcf118d42009-02-04 23:49:09 +0000227 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000228 Emit(BR, Eng.bad_calls_begin(), Eng.bad_calls_end());
229 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000230
231 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000232 const ExplodedNode* N,
Ted Kremenek85ac9342009-05-15 05:25:09 +0000233 BuiltinBugReport *R) {
234 registerTrackNullOrUndefValue(BRC, GetCalleeExpr(N), N);
235 }
236};
237
238
239class VISIBILITY_HIDDEN ArgReport : public BuiltinBugReport {
240 const Stmt *Arg;
241public:
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000242 ArgReport(BugType& bt, const char* desc, ExplodedNode *n,
Ted Kremenek85ac9342009-05-15 05:25:09 +0000243 const Stmt *arg)
244 : BuiltinBugReport(bt, desc, n), Arg(arg) {}
245
246 ArgReport(BugType& bt, const char *shortDesc, const char *desc,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000247 ExplodedNode *n, const Stmt *arg)
Ted Kremenek85ac9342009-05-15 05:25:09 +0000248 : BuiltinBugReport(bt, shortDesc, desc, n), Arg(arg) {}
249
Zhongxing Xu9a5bca32009-08-29 02:11:01 +0000250 const Stmt *getArg() const { return Arg; }
Ted Kremenek78d46242008-07-22 16:21:24 +0000251};
252
253class VISIBILITY_HIDDEN BadArg : public BuiltinBug {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000254public:
Zhongxing Xu904e1e32009-09-02 07:09:39 +0000255 BadArg() : BuiltinBug(0, "Uninitialized argument",
256 "Pass-by-value argument in function call is undefined.") {}
257
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000258 BadArg(GRExprEngine* eng) : BuiltinBug(eng,"Uninitialized argument",
Ted Kremenek17a8e072009-03-01 05:43:22 +0000259 "Pass-by-value argument in function call is undefined.") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000260
Ted Kremenekcf118d42009-02-04 23:49:09 +0000261 BadArg(GRExprEngine* eng, const char* d)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000262 : BuiltinBug(eng,"Uninitialized argument", d) {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000263
Ted Kremenekcf118d42009-02-04 23:49:09 +0000264 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000265 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000266
267 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000268 const ExplodedNode* N,
Ted Kremenek85ac9342009-05-15 05:25:09 +0000269 BuiltinBugReport *R) {
270 registerTrackNullOrUndefValue(BRC, static_cast<ArgReport*>(R)->getArg(),
271 N);
272 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000273};
274
275class VISIBILITY_HIDDEN BadMsgExprArg : public BadArg {
276public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000277 BadMsgExprArg(GRExprEngine* eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000278 : BadArg(eng,"Pass-by-value argument in message expression is undefined"){}
Ted Kremenek78d46242008-07-22 16:21:24 +0000279
Ted Kremenekcf118d42009-02-04 23:49:09 +0000280 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000281 for (GRExprEngine::UndefArgsTy::iterator I=Eng.msg_expr_undef_arg_begin(),
Ted Kremenekcf118d42009-02-04 23:49:09 +0000282 E = Eng.msg_expr_undef_arg_end(); I!=E; ++I) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000283 // Generate a report for this bug.
Ted Kremenek85ac9342009-05-15 05:25:09 +0000284 ArgReport *report = new ArgReport(*this, desc.c_str(), I->first,
285 I->second);
Ted Kremenekcf118d42009-02-04 23:49:09 +0000286 report->addRange(I->second->getSourceRange());
287 BR.EmitReport(report);
Ted Kremenek78d46242008-07-22 16:21:24 +0000288 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000289 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000290};
291
292class VISIBILITY_HIDDEN BadReceiver : public BuiltinBug {
293public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000294 BadReceiver(GRExprEngine* eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000295 : BuiltinBug(eng,"Uninitialized receiver",
296 "Receiver in message expression is an uninitialized value") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000297
Ted Kremenekcf118d42009-02-04 23:49:09 +0000298 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenekefd59942008-12-08 22:47:34 +0000299 for (GRExprEngine::ErrorNodes::iterator I=Eng.undef_receivers_begin(),
Ted Kremenek78d46242008-07-22 16:21:24 +0000300 End = Eng.undef_receivers_end(); I!=End; ++I) {
301
302 // Generate a report for this bug.
Ted Kremenek0c313172009-05-13 19:16:35 +0000303 BuiltinBugReport *report = new BuiltinBugReport(*this, desc.c_str(), *I);
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000304 ExplodedNode* N = *I;
Ted Kremenek5f85e172009-07-22 22:35:28 +0000305 const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
306 const Expr* E = cast<ObjCMessageExpr>(S)->getReceiver();
Ted Kremenek78d46242008-07-22 16:21:24 +0000307 assert (E && "Receiver cannot be NULL");
Ted Kremenekcf118d42009-02-04 23:49:09 +0000308 report->addRange(E->getSourceRange());
309 BR.EmitReport(report);
Ted Kremenek0c313172009-05-13 19:16:35 +0000310 }
311 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000312
Ted Kremenek0c313172009-05-13 19:16:35 +0000313 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000314 const ExplodedNode* N,
Ted Kremenek0c313172009-05-13 19:16:35 +0000315 BuiltinBugReport *R) {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000316 registerTrackNullOrUndefValue(BRC, GetReceiverExpr(N), N);
317 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000318};
Ted Kremenek5917d782008-11-21 00:27:44 +0000319
Ted Kremenek78d46242008-07-22 16:21:24 +0000320class VISIBILITY_HIDDEN RetStack : public BuiltinBug {
321public:
Ted Kremenek17a8e072009-03-01 05:43:22 +0000322 RetStack(GRExprEngine* eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000323 : BuiltinBug(eng, "Return of address to stack-allocated memory") {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000324
Ted Kremenekcf118d42009-02-04 23:49:09 +0000325 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenekb7714b22008-07-30 17:49:12 +0000326 for (GRExprEngine::ret_stackaddr_iterator I=Eng.ret_stackaddr_begin(),
327 End = Eng.ret_stackaddr_end(); I!=End; ++I) {
Ted Kremenek22bda882008-07-31 20:31:27 +0000328
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000329 ExplodedNode* N = *I;
Ted Kremenek5f85e172009-07-22 22:35:28 +0000330 const Stmt *S = cast<PostStmt>(N->getLocation()).getStmt();
331 const Expr* E = cast<ReturnStmt>(S)->getRetValue();
332 assert(E && "Return expression cannot be NULL");
Ted Kremenek22bda882008-07-31 20:31:27 +0000333
334 // Get the value associated with E.
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000335 loc::MemRegionVal V = cast<loc::MemRegionVal>(N->getState()->getSVal(E));
Ted Kremenek22bda882008-07-31 20:31:27 +0000336
337 // Generate a report for this bug.
Ted Kremenekad51a602008-10-31 00:18:30 +0000338 std::string buf;
339 llvm::raw_string_ostream os(buf);
Ted Kremenek8aed8062008-10-31 00:13:20 +0000340 SourceRange R;
Ted Kremenek22bda882008-07-31 20:31:27 +0000341
Ted Kremenek8aed8062008-10-31 00:13:20 +0000342 // Check if the region is a compound literal.
343 if (const CompoundLiteralRegion* CR =
344 dyn_cast<CompoundLiteralRegion>(V.getRegion())) {
345
346 const CompoundLiteralExpr* CL = CR->getLiteralExpr();
347 os << "Address of stack memory associated with a compound literal "
348 "declared on line "
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000349 << BR.getSourceManager()
350 .getInstantiationLineNumber(CL->getLocStart())
Ted Kremenek8aed8062008-10-31 00:13:20 +0000351 << " returned.";
352
353 R = CL->getSourceRange();
354 }
Ted Kremenekde8cd192008-11-02 00:35:25 +0000355 else if (const AllocaRegion* AR = dyn_cast<AllocaRegion>(V.getRegion())) {
356 const Expr* ARE = AR->getExpr();
357 SourceLocation L = ARE->getLocStart();
358 R = ARE->getSourceRange();
359
360 os << "Address of stack memory allocated by call to alloca() on line "
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000361 << BR.getSourceManager().getInstantiationLineNumber(L)
Ted Kremenekde8cd192008-11-02 00:35:25 +0000362 << " returned.";
363 }
Ted Kremenek8aed8062008-10-31 00:13:20 +0000364 else {
365 os << "Address of stack memory associated with local variable '"
366 << V.getRegion()->getString() << "' returned.";
367 }
Ted Kremenek22bda882008-07-31 20:31:27 +0000368
Ted Kremenekcf118d42009-02-04 23:49:09 +0000369 RangedBugReport *report = new RangedBugReport(*this, os.str().c_str(), N);
370 report->addRange(E->getSourceRange());
371 if (R.isValid()) report->addRange(R);
372 BR.EmitReport(report);
Ted Kremenekb7714b22008-07-30 17:49:12 +0000373 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000374 }
375};
Ted Kremenek5917d782008-11-21 00:27:44 +0000376
377class VISIBILITY_HIDDEN RetUndef : public BuiltinBug {
378public:
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000379 RetUndef(GRExprEngine* eng) : BuiltinBug(eng, "Uninitialized return value",
Ted Kremenek0c313172009-05-13 19:16:35 +0000380 "Uninitialized or undefined value returned to caller.") {}
Ted Kremenek5917d782008-11-21 00:27:44 +0000381
Ted Kremenekcf118d42009-02-04 23:49:09 +0000382 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek5917d782008-11-21 00:27:44 +0000383 Emit(BR, Eng.ret_undef_begin(), Eng.ret_undef_end());
384 }
Ted Kremenek0c313172009-05-13 19:16:35 +0000385
386 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000387 const ExplodedNode* N,
Ted Kremenek0c313172009-05-13 19:16:35 +0000388 BuiltinBugReport *R) {
Ted Kremenek85ac9342009-05-15 05:25:09 +0000389 registerTrackNullOrUndefValue(BRC, GetRetValExpr(N), N);
390 }
Ted Kremenek5917d782008-11-21 00:27:44 +0000391};
Ted Kremenek78d46242008-07-22 16:21:24 +0000392
393class VISIBILITY_HIDDEN UndefBranch : public BuiltinBug {
394 struct VISIBILITY_HIDDEN FindUndefExpr {
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000395 GRStateManager& VM;
396 const GRState* St;
Ted Kremenek78d46242008-07-22 16:21:24 +0000397
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000398 FindUndefExpr(GRStateManager& V, const GRState* S) : VM(V), St(S) {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000399
Ted Kremenekb7714b22008-07-30 17:49:12 +0000400 Expr* FindExpr(Expr* Ex) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000401 if (!MatchesCriteria(Ex))
Ted Kremenekb7714b22008-07-30 17:49:12 +0000402 return 0;
Ted Kremenek78d46242008-07-22 16:21:24 +0000403
Ted Kremenekb7714b22008-07-30 17:49:12 +0000404 for (Stmt::child_iterator I=Ex->child_begin(), E=Ex->child_end();I!=E;++I)
Ted Kremenek78d46242008-07-22 16:21:24 +0000405 if (Expr* ExI = dyn_cast_or_null<Expr>(*I)) {
406 Expr* E2 = FindExpr(ExI);
407 if (E2) return E2;
408 }
409
410 return Ex;
411 }
412
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000413 bool MatchesCriteria(Expr* Ex) { return St->getSVal(Ex).isUndef(); }
Ted Kremenek78d46242008-07-22 16:21:24 +0000414 };
415
416public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000417 UndefBranch(GRExprEngine *eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000418 : BuiltinBug(eng,"Use of uninitialized value",
Ted Kremenek78d46242008-07-22 16:21:24 +0000419 "Branch condition evaluates to an uninitialized value.") {}
420
Ted Kremenekcf118d42009-02-04 23:49:09 +0000421 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000422 for (GRExprEngine::undef_branch_iterator I=Eng.undef_branches_begin(),
423 E=Eng.undef_branches_end(); I!=E; ++I) {
424
425 // What's going on here: we want to highlight the subexpression of the
426 // condition that is the most likely source of the "uninitialized
427 // branch condition." We do a recursive walk of the condition's
428 // subexpressions and roughly look for the most nested subexpression
429 // that binds to Undefined. We then highlight that expression's range.
Ted Kremenek78d46242008-07-22 16:21:24 +0000430 BlockEdge B = cast<BlockEdge>((*I)->getLocation());
431 Expr* Ex = cast<Expr>(B.getSrc()->getTerminatorCondition());
432 assert (Ex && "Block must have a terminator.");
433
434 // Get the predecessor node and check if is a PostStmt with the Stmt
435 // being the terminator condition. We want to inspect the state
436 // of that node instead because it will contain main information about
437 // the subexpressions.
Ted Kremenek78d46242008-07-22 16:21:24 +0000438 assert (!(*I)->pred_empty());
439
440 // Note: any predecessor will do. They should have identical state,
441 // since all the BlockEdge did was act as an error sink since the value
442 // had to already be undefined.
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000443 ExplodedNode *N = *(*I)->pred_begin();
Ted Kremenek78d46242008-07-22 16:21:24 +0000444 ProgramPoint P = N->getLocation();
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000445 const GRState* St = (*I)->getState();
Ted Kremenek78d46242008-07-22 16:21:24 +0000446
447 if (PostStmt* PS = dyn_cast<PostStmt>(&P))
448 if (PS->getStmt() == Ex)
449 St = N->getState();
450
451 FindUndefExpr FindIt(Eng.getStateManager(), St);
452 Ex = FindIt.FindExpr(Ex);
453
Ted Kremenek85ac9342009-05-15 05:25:09 +0000454 ArgReport *R = new ArgReport(*this, desc.c_str(), *I, Ex);
Ted Kremenekcf118d42009-02-04 23:49:09 +0000455 R->addRange(Ex->getSourceRange());
456 BR.EmitReport(R);
Ted Kremenek78d46242008-07-22 16:21:24 +0000457 }
458 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000459
460 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000461 const ExplodedNode* N,
Ted Kremenek85ac9342009-05-15 05:25:09 +0000462 BuiltinBugReport *R) {
463 registerTrackNullOrUndefValue(BRC, static_cast<ArgReport*>(R)->getArg(),
464 N);
465 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000466};
467
Zhongxing Xu1c0c2332008-11-23 05:52:28 +0000468class VISIBILITY_HIDDEN OutOfBoundMemoryAccess : public BuiltinBug {
469public:
Ted Kremenekcf118d42009-02-04 23:49:09 +0000470 OutOfBoundMemoryAccess(GRExprEngine* eng)
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000471 : BuiltinBug(eng,"Out-of-bounds memory access",
Ted Kremenekcf118d42009-02-04 23:49:09 +0000472 "Load or store into an out-of-bound memory position.") {}
Zhongxing Xu1c0c2332008-11-23 05:52:28 +0000473
Ted Kremenekcf118d42009-02-04 23:49:09 +0000474 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Zhongxing Xu1c0c2332008-11-23 05:52:28 +0000475 Emit(BR, Eng.explicit_oob_memacc_begin(), Eng.explicit_oob_memacc_end());
476 }
477};
Ted Kremenekefd59942008-12-08 22:47:34 +0000478
Ted Kremenek159d2482008-12-09 00:44:16 +0000479class VISIBILITY_HIDDEN BadSizeVLA : public BuiltinBug {
Ted Kremenekefd59942008-12-08 22:47:34 +0000480public:
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000481 BadSizeVLA(GRExprEngine* eng) :
482 BuiltinBug(eng, "Bad variable-length array (VLA) size") {}
Ted Kremenekefd59942008-12-08 22:47:34 +0000483
Ted Kremenekcf118d42009-02-04 23:49:09 +0000484 void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {
Ted Kremenekefd59942008-12-08 22:47:34 +0000485 for (GRExprEngine::ErrorNodes::iterator
Ted Kremenek159d2482008-12-09 00:44:16 +0000486 I = Eng.ExplicitBadSizedVLA.begin(),
487 E = Eng.ExplicitBadSizedVLA.end(); I!=E; ++I) {
488
489 // Determine whether this was a 'zero-sized' VLA or a VLA with an
490 // undefined size.
Zhongxing Xu031ccc02009-08-06 12:48:26 +0000491 ExplodedNode* N = *I;
Ted Kremenek159d2482008-12-09 00:44:16 +0000492 PostStmt PS = cast<PostStmt>(N->getLocation());
Ted Kremenek5f85e172009-07-22 22:35:28 +0000493 const DeclStmt *DS = cast<DeclStmt>(PS.getStmt());
Ted Kremenekefd59942008-12-08 22:47:34 +0000494 VarDecl* VD = cast<VarDecl>(*DS->decl_begin());
495 QualType T = Eng.getContext().getCanonicalType(VD->getType());
496 VariableArrayType* VT = cast<VariableArrayType>(T);
Ted Kremenek159d2482008-12-09 00:44:16 +0000497 Expr* SizeExpr = VT->getSizeExpr();
Ted Kremenekefd59942008-12-08 22:47:34 +0000498
Ted Kremenek159d2482008-12-09 00:44:16 +0000499 std::string buf;
500 llvm::raw_string_ostream os(buf);
Ted Kremenek5d88ff82009-04-02 02:40:26 +0000501 os << "The expression used to specify the number of elements in the "
502 "variable-length array (VLA) '"
Ted Kremenekcf118d42009-02-04 23:49:09 +0000503 << VD->getNameAsString() << "' evaluates to ";
Ted Kremenek159d2482008-12-09 00:44:16 +0000504
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000505 bool isUndefined = N->getState()->getSVal(SizeExpr).isUndef();
Ted Kremenekd49967f2009-04-29 21:58:13 +0000506
507 if (isUndefined)
Ted Kremenek159d2482008-12-09 00:44:16 +0000508 os << "an undefined or garbage value.";
Ted Kremenekcf118d42009-02-04 23:49:09 +0000509 else
510 os << "0. VLAs with no elements have undefined behavior.";
Ted Kremenekd49967f2009-04-29 21:58:13 +0000511
512 std::string shortBuf;
513 llvm::raw_string_ostream os_short(shortBuf);
514 os_short << "Variable-length array '" << VD->getNameAsString() << "' "
Ted Kremenekeaedfea2009-05-10 05:11:21 +0000515 << (isUndefined ? "garbage value for array size"
516 : "has zero elements (undefined behavior)");
Ted Kremenek159d2482008-12-09 00:44:16 +0000517
Ted Kremenek85ac9342009-05-15 05:25:09 +0000518 ArgReport *report = new ArgReport(*this, os_short.str().c_str(),
519 os.str().c_str(), N, SizeExpr);
520
Ted Kremenekcf118d42009-02-04 23:49:09 +0000521 report->addRange(SizeExpr->getSourceRange());
522 BR.EmitReport(report);
Ted Kremenekefd59942008-12-08 22:47:34 +0000523 }
524 }
Ted Kremenek85ac9342009-05-15 05:25:09 +0000525
526 void registerInitialVisitors(BugReporterContext& BRC,
Zhongxing Xuc5619d92009-08-06 01:32:16 +0000527 const ExplodedNode* N,
Ted Kremenek85ac9342009-05-15 05:25:09 +0000528 BuiltinBugReport *R) {
529 registerTrackNullOrUndefValue(BRC, static_cast<ArgReport*>(R)->getArg(),
530 N);
531 }
Ted Kremenekefd59942008-12-08 22:47:34 +0000532};
Zhongxing Xu1c0c2332008-11-23 05:52:28 +0000533
Ted Kremenek78d46242008-07-22 16:21:24 +0000534//===----------------------------------------------------------------------===//
535// __attribute__(nonnull) checking
536
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000537class VISIBILITY_HIDDEN CheckAttrNonNull :
538 public CheckerVisitor<CheckAttrNonNull> {
539
Ted Kremenekcf118d42009-02-04 23:49:09 +0000540 BugType *BT;
Ted Kremenek78d46242008-07-22 16:21:24 +0000541
542public:
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000543 CheckAttrNonNull() : BT(0) {}
Ted Kremenek31112182009-07-24 00:40:31 +0000544 ~CheckAttrNonNull() {}
Ted Kremenek78d46242008-07-22 16:21:24 +0000545
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000546 const void *getTag() {
547 static int x = 0;
548 return &x;
549 }
550
551 void PreVisitCallExpr(CheckerContext &C, const CallExpr *CE) {
552 const GRState *state = C.getState();
553 const GRState *originalState = state;
Ted Kremenek78d46242008-07-22 16:21:24 +0000554
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000555 // Check if the callee has a 'nonnull' attribute.
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000556 SVal X = state->getSVal(CE->getCallee());
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000557
Zhongxing Xu369f4472009-04-20 05:24:46 +0000558 const FunctionDecl* FD = X.getAsFunctionDecl();
559 if (!FD)
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000560 return;
Zhongxing Xu369f4472009-04-20 05:24:46 +0000561
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000562 const NonNullAttr* Att = FD->getAttr<NonNullAttr>();
Ted Kremenek78d46242008-07-22 16:21:24 +0000563 if (!Att)
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000564 return;
Ted Kremenek78d46242008-07-22 16:21:24 +0000565
566 // Iterate through the arguments of CE and check them for null.
Ted Kremenek78d46242008-07-22 16:21:24 +0000567 unsigned idx = 0;
Ted Kremenek78d46242008-07-22 16:21:24 +0000568
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000569 for (CallExpr::const_arg_iterator I=CE->arg_begin(), E=CE->arg_end(); I!=E;
Ted Kremenek78d46242008-07-22 16:21:24 +0000570 ++I, ++idx) {
Ted Kremenek78d46242008-07-22 16:21:24 +0000571
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000572 if (!Att->isNonNull(idx))
573 continue;
574
Ted Kremenek08780072009-08-24 22:47:34 +0000575 const SVal &V = state->getSVal(*I);
576 const DefinedSVal *DV = dyn_cast<DefinedSVal>(&V);
577
578 if (!DV)
579 continue;
580
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000581 ConstraintManager &CM = C.getConstraintManager();
582 const GRState *stateNotNull, *stateNull;
Ted Kremenek08780072009-08-24 22:47:34 +0000583 llvm::tie(stateNotNull, stateNull) = CM.AssumeDual(state, *DV);
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000584
585 if (stateNull && !stateNotNull) {
586 // Generate an error node. Check for a null node in case
587 // we cache out.
Ted Kremenek592362b2009-08-18 01:05:30 +0000588 if (ExplodedNode *errorNode = C.generateNode(CE, stateNull, true)) {
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000589
590 // Lazily allocate the BugType object if it hasn't already been
591 // created. Ownership is transferred to the BugReporter object once
592 // the BugReport is passed to 'EmitWarning'.
593 if (!BT)
594 BT = new BugType("Argument with 'nonnull' attribute passed null",
595 "API");
596
Ted Kremenek592362b2009-08-18 01:05:30 +0000597 EnhancedBugReport *R =
598 new EnhancedBugReport(*BT,
599 "Null pointer passed as an argument to a "
600 "'nonnull' parameter", errorNode);
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000601
602 // Highlight the range of the argument that was null.
Ted Kremenek592362b2009-08-18 01:05:30 +0000603 const Expr *arg = *I;
604 R->addRange(arg->getSourceRange());
605 R->addVisitorCreator(registerTrackNullOrUndefValue, arg);
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000606
607 // Emit the bug report.
608 C.EmitReport(R);
609 }
610
611 // Always return. Either we cached out or we just emitted an error.
612 return;
613 }
614
615 // If a pointer value passed the check we should assume that it is
616 // indeed not null from this point forward.
617 assert(stateNotNull);
618 state = stateNotNull;
619 }
620
621 // If we reach here all of the arguments passed the nonnull check.
622 // If 'state' has been updated generated a new node.
623 if (state != originalState)
Ted Kremenekbb977222009-07-28 19:24:31 +0000624 C.addTransition(C.generateNode(CE, state));
Ted Kremenek78d46242008-07-22 16:21:24 +0000625 }
Ted Kremenek78d46242008-07-22 16:21:24 +0000626};
627} // end anonymous namespace
628
Zhongxing Xu9a5bca32009-08-29 02:11:01 +0000629// Undefined arguments checking.
630namespace {
631class VISIBILITY_HIDDEN CheckUndefinedArg
632 : public CheckerVisitor<CheckUndefinedArg> {
633
Zhongxing Xu904e1e32009-09-02 07:09:39 +0000634 BadArg *BT;
Zhongxing Xu9a5bca32009-08-29 02:11:01 +0000635
636public:
637 CheckUndefinedArg() : BT(0) {}
638 ~CheckUndefinedArg() {}
639
640 const void *getTag() {
641 static int x = 0;
642 return &x;
643 }
644
645 void PreVisitCallExpr(CheckerContext &C, const CallExpr *CE);
646};
647
648void CheckUndefinedArg::PreVisitCallExpr(CheckerContext &C, const CallExpr *CE){
649 for (CallExpr::const_arg_iterator I = CE->arg_begin(), E = CE->arg_end();
650 I != E; ++I) {
651 if (C.getState()->getSVal(*I).isUndef()) {
652 if (ExplodedNode *ErrorNode = C.generateNode(CE, C.getState(), true)) {
653 if (!BT)
Zhongxing Xu904e1e32009-09-02 07:09:39 +0000654 BT = new BadArg();
Zhongxing Xu9a5bca32009-08-29 02:11:01 +0000655 // Generate a report for this bug.
Zhongxing Xu904e1e32009-09-02 07:09:39 +0000656 ArgReport *Report = new ArgReport(*BT, BT->getDescription().c_str(),
Zhongxing Xu9a5bca32009-08-29 02:11:01 +0000657 ErrorNode, *I);
658 Report->addRange((*I)->getSourceRange());
659 C.EmitReport(Report);
660 }
661 }
662 }
663}
664
665}
Ted Kremenek78d46242008-07-22 16:21:24 +0000666//===----------------------------------------------------------------------===//
667// Check registration.
Ted Kremenekcf118d42009-02-04 23:49:09 +0000668//===----------------------------------------------------------------------===//
Ted Kremenek78d46242008-07-22 16:21:24 +0000669
670void GRExprEngine::RegisterInternalChecks() {
Ted Kremenekcf118d42009-02-04 23:49:09 +0000671 // Register internal "built-in" BugTypes with the BugReporter. These BugTypes
672 // are different than what probably many checks will do since they don't
673 // create BugReports on-the-fly but instead wait until GRExprEngine finishes
674 // analyzing a function. Generation of BugReport objects is done via a call
675 // to 'FlushReports' from BugReporter.
676 BR.Register(new NullDeref(this));
677 BR.Register(new UndefinedDeref(this));
678 BR.Register(new UndefBranch(this));
679 BR.Register(new DivZero(this));
680 BR.Register(new UndefResult(this));
681 BR.Register(new BadCall(this));
682 BR.Register(new RetStack(this));
683 BR.Register(new RetUndef(this));
Ted Kremenekcf118d42009-02-04 23:49:09 +0000684 BR.Register(new BadMsgExprArg(this));
685 BR.Register(new BadReceiver(this));
686 BR.Register(new OutOfBoundMemoryAccess(this));
687 BR.Register(new BadSizeVLA(this));
Ted Kremenek21fe8372009-02-19 04:06:22 +0000688 BR.Register(new NilReceiverStructRet(this));
Ted Kremenek899b3de2009-04-08 03:07:17 +0000689 BR.Register(new NilReceiverLargerThanVoidPtrRet(this));
Ted Kremenekcf118d42009-02-04 23:49:09 +0000690
691 // The following checks do not need to have their associated BugTypes
692 // explicitly registered with the BugReporter. If they issue any BugReports,
693 // their associated BugType will get registered with the BugReporter
694 // automatically. Note that the check itself is owned by the GRExprEngine
695 // object.
Ted Kremenekc26a8b02009-07-22 21:46:56 +0000696 registerCheck(new CheckAttrNonNull());
Zhongxing Xu9a5bca32009-08-29 02:11:01 +0000697 registerCheck(new CheckUndefinedArg());
Ted Kremenek78d46242008-07-22 16:21:24 +0000698}