blob: b454a3605c19260454045b35282404b8cac1b705 [file] [log] [blame]
Ted Kremenek99c6ad32008-03-27 07:25:52 +00001//== BasicObjCFoundationChecks.cpp - Simple Apple-Foundation 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 BasicObjCFoundationChecks, a class that encapsulates
11// a set of simple checks to run on Objective-C code using Apple's Foundation
12// classes.
13//
14//===----------------------------------------------------------------------===//
15
Ted Kremenek52755612008-03-27 17:17:22 +000016#include "BasicObjCFoundationChecks.h"
17
Ted Kremenek99c6ad32008-03-27 07:25:52 +000018#include "clang/Analysis/PathSensitive/ExplodedGraph.h"
19#include "clang/Analysis/PathSensitive/GRSimpleAPICheck.h"
Ted Kremenek78d46242008-07-22 16:21:24 +000020#include "clang/Analysis/PathSensitive/GRExprEngine.h"
Ted Kremenek4adc81e2008-08-13 04:27:00 +000021#include "clang/Analysis/PathSensitive/GRState.h"
Ted Kremenekf1ae7052008-04-03 17:57:38 +000022#include "clang/Analysis/PathSensitive/BugReporter.h"
Ted Kremenek9e240492008-10-04 05:50:14 +000023#include "clang/Analysis/PathSensitive/MemRegion.h"
Ted Kremenek99c6ad32008-03-27 07:25:52 +000024#include "clang/Analysis/PathDiagnostic.h"
Ted Kremenek78d46242008-07-22 16:21:24 +000025#include "clang/Analysis/LocalCheckers.h"
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +000026#include "clang/AST/DeclObjC.h"
Ted Kremenek99c6ad32008-03-27 07:25:52 +000027#include "clang/AST/Expr.h"
Steve Narofff494b572008-05-29 21:12:08 +000028#include "clang/AST/ExprObjC.h"
Ted Kremenek99c6ad32008-03-27 07:25:52 +000029#include "clang/AST/ASTContext.h"
30#include "llvm/Support/Compiler.h"
31
Ted Kremenek99c6ad32008-03-27 07:25:52 +000032using namespace clang;
Ted Kremenek52755612008-03-27 17:17:22 +000033
Steve Naroff14108da2009-07-10 23:34:53 +000034static const ObjCInterfaceType* GetReceiverType(const ObjCMessageExpr* ME) {
35 const Expr* Receiver = ME->getReceiver();
Ted Kremenek4ba62832008-03-27 22:05:32 +000036
37 if (!Receiver)
38 return NULL;
39
Steve Naroff14108da2009-07-10 23:34:53 +000040 if (const ObjCObjectPointerType *PT =
41 Receiver->getType()->getAsObjCObjectPointerType())
42 return PT->getInterfaceType();
Ted Kremenekc1ff3cd2008-04-30 22:48:21 +000043
Ted Kremenekc1ff3cd2008-04-30 22:48:21 +000044 return NULL;
Ted Kremenek4ba62832008-03-27 22:05:32 +000045}
46
Steve Naroff14108da2009-07-10 23:34:53 +000047static const char* GetReceiverNameType(const ObjCMessageExpr* ME) {
48 const ObjCInterfaceType *ReceiverType = GetReceiverType(ME);
Ted Kremenek4ba62832008-03-27 22:05:32 +000049 return ReceiverType ? ReceiverType->getDecl()->getIdentifier()->getName()
50 : NULL;
51}
Ted Kremenek52755612008-03-27 17:17:22 +000052
Ted Kremenekf1ae7052008-04-03 17:57:38 +000053namespace {
Ted Kremenekb344f912008-09-21 19:01:39 +000054
Ted Kremenekcf118d42009-02-04 23:49:09 +000055class VISIBILITY_HIDDEN APIMisuse : public BugType {
Ted Kremenekf1ae7052008-04-03 17:57:38 +000056public:
Ted Kremenekcf118d42009-02-04 23:49:09 +000057 APIMisuse(const char* name) : BugType(name, "API Misuse (Apple)") {}
Ted Kremenekf1ae7052008-04-03 17:57:38 +000058};
Ted Kremenekf1ae7052008-04-03 17:57:38 +000059
60class VISIBILITY_HIDDEN BasicObjCFoundationChecks : public GRSimpleAPICheck {
Ted Kremenekcf118d42009-02-04 23:49:09 +000061 APIMisuse *BT;
62 BugReporter& BR;
Ted Kremenekf1ae7052008-04-03 17:57:38 +000063 ASTContext &Ctx;
Ted Kremenekf1ae7052008-04-03 17:57:38 +000064
Steve Naroff14108da2009-07-10 23:34:53 +000065 bool isNSString(const ObjCInterfaceType *T, const char* suffix);
Ted Kremenekf1ae7052008-04-03 17:57:38 +000066 bool AuditNSString(NodeTy* N, ObjCMessageExpr* ME);
67
68 void Warn(NodeTy* N, Expr* E, const std::string& s);
69 void WarnNilArg(NodeTy* N, Expr* E);
70
71 bool CheckNilArg(NodeTy* N, unsigned Arg);
72
73public:
Ted Kremenek23ec48c2009-06-18 23:58:37 +000074 BasicObjCFoundationChecks(ASTContext& ctx, BugReporter& br)
75 : BT(0), BR(br), Ctx(ctx) {}
Ted Kremenekcf118d42009-02-04 23:49:09 +000076
77 bool Audit(ExplodedNode<GRState>* N, GRStateManager&);
Ted Kremenekf1ae7052008-04-03 17:57:38 +000078
Ted Kremenekcf118d42009-02-04 23:49:09 +000079private:
80 void WarnNilArg(NodeTy* N, ObjCMessageExpr* ME, unsigned Arg) {
81 std::string sbuf;
82 llvm::raw_string_ostream os(sbuf);
83 os << "Argument to '" << GetReceiverNameType(ME) << "' method '"
84 << ME->getSelector().getAsString() << "' cannot be nil.";
85
86 // Lazily create the BugType object for NilArg. This will be owned
87 // by the BugReporter object 'BR' once we call BR.EmitWarning.
88 if (!BT) BT = new APIMisuse("nil argument");
89
90 RangedBugReport *R = new RangedBugReport(*BT, os.str().c_str(), N);
91 R->addRange(ME->getArg(Arg)->getSourceRange());
92 BR.EmitReport(R);
Ted Kremenekf1ae7052008-04-03 17:57:38 +000093 }
94};
95
96} // end anonymous namespace
97
98
99GRSimpleAPICheck*
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000100clang::CreateBasicObjCFoundationChecks(ASTContext& Ctx, BugReporter& BR) {
101 return new BasicObjCFoundationChecks(Ctx, BR);
Ted Kremenekf1ae7052008-04-03 17:57:38 +0000102}
103
104
105
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000106bool BasicObjCFoundationChecks::Audit(ExplodedNode<GRState>* N,
107 GRStateManager&) {
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000108
109 ObjCMessageExpr* ME =
110 cast<ObjCMessageExpr>(cast<PostStmt>(N->getLocation()).getStmt());
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000111
Steve Naroff14108da2009-07-10 23:34:53 +0000112 const ObjCInterfaceType *ReceiverType = GetReceiverType(ME);
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000113
114 if (!ReceiverType)
Nuno Lopesf7427942008-05-20 17:33:56 +0000115 return false;
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000116
Ted Kremenek4ba62832008-03-27 22:05:32 +0000117 const char* name = ReceiverType->getDecl()->getIdentifier()->getName();
118
119 if (!name)
120 return false;
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000121
122 if (name[0] != 'N' || name[1] != 'S')
123 return false;
124
125 name += 2;
126
Steve Naroff14108da2009-07-10 23:34:53 +0000127 // FIXME: Make all of this faster.
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000128 if (isNSString(ReceiverType, name))
129 return AuditNSString(N, ME);
130
Nuno Lopesf7427942008-05-20 17:33:56 +0000131 return false;
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000132}
133
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000134static inline bool isNil(SVal X) {
135 return isa<loc::ConcreteInt>(X);
Ted Kremeneke5d5c202008-03-27 21:15:17 +0000136}
137
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000138//===----------------------------------------------------------------------===//
139// Error reporting.
140//===----------------------------------------------------------------------===//
141
Ted Kremenek4ba62832008-03-27 22:05:32 +0000142bool BasicObjCFoundationChecks::CheckNilArg(NodeTy* N, unsigned Arg) {
143 ObjCMessageExpr* ME =
144 cast<ObjCMessageExpr>(cast<PostStmt>(N->getLocation()).getStmt());
145
146 Expr * E = ME->getArg(Arg);
147
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000148 if (isNil(N->getState()->getSVal(E))) {
Ted Kremenekf1ae7052008-04-03 17:57:38 +0000149 WarnNilArg(N, ME, Arg);
Ted Kremenek4ba62832008-03-27 22:05:32 +0000150 return true;
151 }
152
153 return false;
154}
155
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000156//===----------------------------------------------------------------------===//
157// NSString checking.
158//===----------------------------------------------------------------------===//
159
Steve Naroff14108da2009-07-10 23:34:53 +0000160bool BasicObjCFoundationChecks::isNSString(const ObjCInterfaceType *T,
161 const char* suffix) {
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000162 return !strcmp("String", suffix) || !strcmp("MutableString", suffix);
163}
164
165bool BasicObjCFoundationChecks::AuditNSString(NodeTy* N,
166 ObjCMessageExpr* ME) {
167
168 Selector S = ME->getSelector();
169
170 if (S.isUnarySelector())
171 return false;
172
173 // FIXME: This is going to be really slow doing these checks with
174 // lexical comparisons.
175
Chris Lattner077bf5e2008-11-24 03:33:13 +0000176 std::string name = S.getAsString();
Ted Kremenek9b3fdea2008-03-27 21:23:57 +0000177 assert (!name.empty());
178 const char* cstr = &name[0];
179 unsigned len = name.size();
Ted Kremenek4ba62832008-03-27 22:05:32 +0000180
Ted Kremenek9b3fdea2008-03-27 21:23:57 +0000181 switch (len) {
182 default:
183 break;
Ted Kremenek8730e132008-03-28 16:09:38 +0000184 case 8:
Ted Kremenek4ba62832008-03-27 22:05:32 +0000185 if (!strcmp(cstr, "compare:"))
186 return CheckNilArg(N, 0);
187
188 break;
Ted Kremenek8730e132008-03-28 16:09:38 +0000189
190 case 15:
191 // FIXME: Checking for initWithFormat: will not work in most cases
192 // yet because [NSString alloc] returns id, not NSString*. We will
193 // need support for tracking expected-type information in the analyzer
194 // to find these errors.
195 if (!strcmp(cstr, "initWithFormat:"))
196 return CheckNilArg(N, 0);
197
198 break;
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000199
Ted Kremenek4ba62832008-03-27 22:05:32 +0000200 case 16:
201 if (!strcmp(cstr, "compare:options:"))
202 return CheckNilArg(N, 0);
Ted Kremenek9b3fdea2008-03-27 21:23:57 +0000203
204 break;
Ted Kremenek4ba62832008-03-27 22:05:32 +0000205
206 case 22:
207 if (!strcmp(cstr, "compare:options:range:"))
208 return CheckNilArg(N, 0);
209
210 break;
211
212 case 23:
213
214 if (!strcmp(cstr, "caseInsensitiveCompare:"))
215 return CheckNilArg(N, 0);
216
217 break;
Ted Kremenek8730e132008-03-28 16:09:38 +0000218
Ted Kremenek4ba62832008-03-27 22:05:32 +0000219 case 29:
220 if (!strcmp(cstr, "compare:options:range:locale:"))
221 return CheckNilArg(N, 0);
222
223 break;
224
225 case 37:
226 if (!strcmp(cstr, "componentsSeparatedByCharactersInSet:"))
227 return CheckNilArg(N, 0);
228
229 break;
Ted Kremenek99c6ad32008-03-27 07:25:52 +0000230 }
231
232 return false;
233}
Ted Kremenek04bc8762008-06-26 23:59:48 +0000234
235//===----------------------------------------------------------------------===//
236// Error reporting.
237//===----------------------------------------------------------------------===//
238
239namespace {
Ted Kremenek04bc8762008-06-26 23:59:48 +0000240
Ted Kremenek04bc8762008-06-26 23:59:48 +0000241class VISIBILITY_HIDDEN AuditCFNumberCreate : public GRSimpleAPICheck {
Ted Kremenekcf118d42009-02-04 23:49:09 +0000242 APIMisuse* BT;
Ted Kremenek04bc8762008-06-26 23:59:48 +0000243
244 // FIXME: Either this should be refactored into GRSimpleAPICheck, or
245 // it should always be passed with a call to Audit. The latter
246 // approach makes this class more stateless.
247 ASTContext& Ctx;
248 IdentifierInfo* II;
Ted Kremenekcf118d42009-02-04 23:49:09 +0000249 BugReporter& BR;
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000250
Ted Kremenek04bc8762008-06-26 23:59:48 +0000251public:
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000252 AuditCFNumberCreate(ASTContext& ctx, BugReporter& br)
253 : BT(0), Ctx(ctx), II(&Ctx.Idents.get("CFNumberCreate")), BR(br){}
Ted Kremenek04bc8762008-06-26 23:59:48 +0000254
Ted Kremenekcf118d42009-02-04 23:49:09 +0000255 ~AuditCFNumberCreate() {}
Ted Kremenek04bc8762008-06-26 23:59:48 +0000256
Ted Kremenekcf118d42009-02-04 23:49:09 +0000257 bool Audit(ExplodedNode<GRState>* N, GRStateManager&);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000258
259private:
Ted Kremenek993f1c72008-10-17 20:28:54 +0000260 void AddError(const TypedRegion* R, Expr* Ex, ExplodedNode<GRState> *N,
Ted Kremenek04bc8762008-06-26 23:59:48 +0000261 uint64_t SourceSize, uint64_t TargetSize, uint64_t NumberKind);
262};
263} // end anonymous namespace
264
265enum CFNumberType {
266 kCFNumberSInt8Type = 1,
267 kCFNumberSInt16Type = 2,
268 kCFNumberSInt32Type = 3,
269 kCFNumberSInt64Type = 4,
270 kCFNumberFloat32Type = 5,
271 kCFNumberFloat64Type = 6,
272 kCFNumberCharType = 7,
273 kCFNumberShortType = 8,
274 kCFNumberIntType = 9,
275 kCFNumberLongType = 10,
276 kCFNumberLongLongType = 11,
277 kCFNumberFloatType = 12,
278 kCFNumberDoubleType = 13,
279 kCFNumberCFIndexType = 14,
280 kCFNumberNSIntegerType = 15,
281 kCFNumberCGFloatType = 16
282};
283
284namespace {
285 template<typename T>
286 class Optional {
287 bool IsKnown;
288 T Val;
289 public:
290 Optional() : IsKnown(false), Val(0) {}
291 Optional(const T& val) : IsKnown(true), Val(val) {}
292
293 bool isKnown() const { return IsKnown; }
294
295 const T& getValue() const {
296 assert (isKnown());
297 return Val;
298 }
299
300 operator const T&() const {
301 return getValue();
302 }
303 };
304}
305
306static Optional<uint64_t> GetCFNumberSize(ASTContext& Ctx, uint64_t i) {
307 static unsigned char FixedSize[] = { 8, 16, 32, 64, 32, 64 };
308
309 if (i < kCFNumberCharType)
310 return FixedSize[i-1];
311
312 QualType T;
313
314 switch (i) {
315 case kCFNumberCharType: T = Ctx.CharTy; break;
316 case kCFNumberShortType: T = Ctx.ShortTy; break;
317 case kCFNumberIntType: T = Ctx.IntTy; break;
318 case kCFNumberLongType: T = Ctx.LongTy; break;
319 case kCFNumberLongLongType: T = Ctx.LongLongTy; break;
320 case kCFNumberFloatType: T = Ctx.FloatTy; break;
321 case kCFNumberDoubleType: T = Ctx.DoubleTy; break;
322 case kCFNumberCFIndexType:
323 case kCFNumberNSIntegerType:
324 case kCFNumberCGFloatType:
325 // FIXME: We need a way to map from names to Type*.
326 default:
327 return Optional<uint64_t>();
328 }
329
330 return Ctx.getTypeSize(T);
331}
332
333#if 0
334static const char* GetCFNumberTypeStr(uint64_t i) {
335 static const char* Names[] = {
336 "kCFNumberSInt8Type",
337 "kCFNumberSInt16Type",
338 "kCFNumberSInt32Type",
339 "kCFNumberSInt64Type",
340 "kCFNumberFloat32Type",
341 "kCFNumberFloat64Type",
342 "kCFNumberCharType",
343 "kCFNumberShortType",
344 "kCFNumberIntType",
345 "kCFNumberLongType",
346 "kCFNumberLongLongType",
347 "kCFNumberFloatType",
348 "kCFNumberDoubleType",
349 "kCFNumberCFIndexType",
350 "kCFNumberNSIntegerType",
351 "kCFNumberCGFloatType"
352 };
353
354 return i <= kCFNumberCGFloatType ? Names[i-1] : "Invalid CFNumberType";
355}
356#endif
357
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000358bool AuditCFNumberCreate::Audit(ExplodedNode<GRState>* N,GRStateManager&){
Ted Kremenek04bc8762008-06-26 23:59:48 +0000359 CallExpr* CE = cast<CallExpr>(cast<PostStmt>(N->getLocation()).getStmt());
360 Expr* Callee = CE->getCallee();
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000361 SVal CallV = N->getState()->getSVal(Callee);
Zhongxing Xu369f4472009-04-20 05:24:46 +0000362 const FunctionDecl* FD = CallV.getAsFunctionDecl();
Ted Kremenek04bc8762008-06-26 23:59:48 +0000363
Zhongxing Xu369f4472009-04-20 05:24:46 +0000364 if (!FD || FD->getIdentifier() != II || CE->getNumArgs()!=3)
Ted Kremenek04bc8762008-06-26 23:59:48 +0000365 return false;
366
367 // Get the value of the "theType" argument.
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000368 SVal TheTypeVal = N->getState()->getSVal(CE->getArg(1));
Ted Kremenek04bc8762008-06-26 23:59:48 +0000369
370 // FIXME: We really should allow ranges of valid theType values, and
371 // bifurcate the state appropriately.
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000372 nonloc::ConcreteInt* V = dyn_cast<nonloc::ConcreteInt>(&TheTypeVal);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000373
374 if (!V)
375 return false;
376
377 uint64_t NumberKind = V->getValue().getLimitedValue();
378 Optional<uint64_t> TargetSize = GetCFNumberSize(Ctx, NumberKind);
379
380 // FIXME: In some cases we can emit an error.
381 if (!TargetSize.isKnown())
382 return false;
383
384 // Look at the value of the integer being passed by reference. Essentially
385 // we want to catch cases where the value passed in is not equal to the
386 // size of the type being created.
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000387 SVal TheValueExpr = N->getState()->getSVal(CE->getArg(2));
Ted Kremenek04bc8762008-06-26 23:59:48 +0000388
389 // FIXME: Eventually we should handle arbitrary locations. We can do this
390 // by having an enhanced memory model that does low-level typing.
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000391 loc::MemRegionVal* LV = dyn_cast<loc::MemRegionVal>(&TheValueExpr);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000392
393 if (!LV)
394 return false;
395
Ted Kremenek993f1c72008-10-17 20:28:54 +0000396 const TypedRegion* R = dyn_cast<TypedRegion>(LV->getRegion());
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000397 if (!R) return false;
Ted Kremenek9e240492008-10-04 05:50:14 +0000398
Ted Kremenek0312c0e2009-03-01 05:44:08 +0000399 while (const TypedViewRegion* ATR = dyn_cast<TypedViewRegion>(R)) {
Ted Kremenek6eddeb12008-12-13 21:49:13 +0000400 R = dyn_cast<TypedRegion>(ATR->getSuperRegion());
401 if (!R) return false;
402 }
Ted Kremenek9e240492008-10-04 05:50:14 +0000403
Zhongxing Xua82d8aa2009-05-09 03:57:34 +0000404 QualType T = Ctx.getCanonicalType(R->getValueType(Ctx));
Ted Kremenek04bc8762008-06-26 23:59:48 +0000405
406 // FIXME: If the pointee isn't an integer type, should we flag a warning?
407 // People can do weird stuff with pointers.
408
409 if (!T->isIntegerType())
410 return false;
411
412 uint64_t SourceSize = Ctx.getTypeSize(T);
413
414 // CHECK: is SourceSize == TargetSize
415
416 if (SourceSize == TargetSize)
417 return false;
418
Ted Kremenek9e240492008-10-04 05:50:14 +0000419 AddError(R, CE->getArg(2), N, SourceSize, TargetSize, NumberKind);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000420
421 // FIXME: We can actually create an abstract "CFNumber" object that has
422 // the bits initialized to the provided values.
423 return SourceSize < TargetSize;
424}
425
Ted Kremenek993f1c72008-10-17 20:28:54 +0000426void AuditCFNumberCreate::AddError(const TypedRegion* R, Expr* Ex,
Ted Kremenek4adc81e2008-08-13 04:27:00 +0000427 ExplodedNode<GRState> *N,
Ted Kremenek04bc8762008-06-26 23:59:48 +0000428 uint64_t SourceSize, uint64_t TargetSize,
429 uint64_t NumberKind) {
Ted Kremenekcf118d42009-02-04 23:49:09 +0000430
431 std::string sbuf;
432 llvm::raw_string_ostream os(sbuf);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000433
434 os << (SourceSize == 8 ? "An " : "A ")
435 << SourceSize << " bit integer is used to initialize a CFNumber "
436 "object that represents "
437 << (TargetSize == 8 ? "an " : "a ")
438 << TargetSize << " bit integer. ";
439
440 if (SourceSize < TargetSize)
441 os << (TargetSize - SourceSize)
442 << " bits of the CFNumber value will be garbage." ;
443 else
444 os << (SourceSize - TargetSize)
445 << " bits of the input integer will be lost.";
446
Ted Kremenekcf118d42009-02-04 23:49:09 +0000447 // Lazily create the BugType object. This will be owned
448 // by the BugReporter object 'BR' once we call BR.EmitWarning.
449 if (!BT) BT = new APIMisuse("Bad use of CFNumberCreate");
450 RangedBugReport *report = new RangedBugReport(*BT, os.str().c_str(), N);
451 report->addRange(Ex->getSourceRange());
452 BR.EmitReport(report);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000453}
454
455GRSimpleAPICheck*
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000456clang::CreateAuditCFNumberCreate(ASTContext& Ctx, BugReporter& BR) {
457 return new AuditCFNumberCreate(Ctx, BR);
Ted Kremenek04bc8762008-06-26 23:59:48 +0000458}
459
Ted Kremenek78d46242008-07-22 16:21:24 +0000460//===----------------------------------------------------------------------===//
461// Check registration.
462
463void clang::RegisterAppleChecks(GRExprEngine& Eng) {
464 ASTContext& Ctx = Eng.getContext();
Ted Kremenekcf118d42009-02-04 23:49:09 +0000465 BugReporter &BR = Eng.getBugReporter();
Ted Kremenek78d46242008-07-22 16:21:24 +0000466
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000467 Eng.AddCheck(CreateBasicObjCFoundationChecks(Ctx, BR),
Ted Kremenek78d46242008-07-22 16:21:24 +0000468 Stmt::ObjCMessageExprClass);
469
Ted Kremenek23ec48c2009-06-18 23:58:37 +0000470 Eng.AddCheck(CreateAuditCFNumberCreate(Ctx, BR),
Ted Kremenekcfdf9b42008-09-18 21:25:13 +0000471 Stmt::CallExprClass);
472
Ted Kremenekcf118d42009-02-04 23:49:09 +0000473 RegisterNSErrorChecks(BR, Eng);
Ted Kremenek78d46242008-07-22 16:21:24 +0000474}