]> granicus.if.org Git - clang/commitdiff
Teach analyzer about NSAutoreleasePool -allocWithZone:. Fixes <rdar://problem/10640253>.
authorTed Kremenek <kremenek@apple.com>
Sat, 18 Feb 2012 21:37:48 +0000 (21:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 18 Feb 2012 21:37:48 +0000 (21:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150892 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
test/Analysis/retain-release.m

index 9ba83ce8dc96d2473a75f1af9324afefa5559981..b6f91d9fdcab20ec644e809ba505db8647f643f3 100644 (file)
@@ -655,10 +655,11 @@ private:
     ObjCMethodSummaries[S] = Summ;
   }
 
-  void addClassMethSummary(const char* Cls, const char* nullaryName,
-                           const RetainSummary *Summ) {
+  void addClassMethSummary(const char* Cls, const char* name,
+                           const RetainSummary *Summ, bool isNullary = true) {
     IdentifierInfo* ClsII = &Ctx.Idents.get(Cls);
-    Selector S = GetNullarySelector(nullaryName, Ctx);
+    Selector S = isNullary ? GetNullarySelector(name, Ctx) 
+                           : GetUnarySelector(name, Ctx);
     ObjCClassMethodSummaries[ObjCSummaryKey(ClsII, S)]  = Summ;
   }
 
@@ -1508,6 +1509,7 @@ void RetainSummaryManager::InitializeMethodSummaries() {
   // Don't track allocated autorelease pools yet, as it is okay to prematurely
   // exit a method.
   addClassMethSummary("NSAutoreleasePool", "alloc", NoTrackYet);
+  addClassMethSummary("NSAutoreleasePool", "allocWithZone", NoTrackYet, false);
 
   // Create summaries QCRenderer/QCView -createSnapShotImageOfType:
   addInstMethSummary("QCRenderer", AllocSumm,
index a6c24cee00b26c7140a8d0e4df6841c9f1e0f63e..bb32635b4b8b13ab62155b181d24f76454ed4956 100644 (file)
@@ -672,7 +672,7 @@ void rdar6704930(unsigned char *s, unsigned int length) {
 //===----------------------------------------------------------------------===//
 // <rdar://problem/6257780> clang checker fails to catch use-after-release
 //===----------------------------------------------------------------------===//
-                                 
+
 int rdar_6257780_Case1() {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   NSArray *array = [NSArray array];
@@ -681,6 +681,15 @@ int rdar_6257780_Case1() {
   return 0;
 }
 
+//===----------------------------------------------------------------------===//
+// <rdar://problem/10640253> Analyzer is confused about NSAutoreleasePool -allocWithZone:.
+//===----------------------------------------------------------------------===//
+
+void rdar_10640253_autorelease_allocWithZone() {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool allocWithZone:(NSZone*)0] init];
+    (void) pool;
+}
+
 //===----------------------------------------------------------------------===//
 // <rdar://problem/6866843> Checker should understand new/setObject:/release constructs
 //===----------------------------------------------------------------------===//