r273441 - [analyzer] Teach ObjCDeallocChecker about XCTestCase

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 10:03:11 PDT 2016


Author: dcoughlin
Date: Wed Jun 22 12:03:10 2016
New Revision: 273441

URL: http://llvm.org/viewvc/llvm-project?rev=273441&view=rev
Log:
[analyzer] Teach ObjCDeallocChecker about XCTestCase

Like with SenTestCase, subclasses of XCTestCase follow a "tear down" idiom to
release instance variables and so typically do not release ivars in -dealloc.
This commit applies the existing special casing for SenTestCase to XCTestCase
as well.

rdar://problem/25884696

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
    cfe/trunk/test/Analysis/DeallocMissingRelease.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp?rev=273441&r1=273440&r2=273441&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp Wed Jun 22 12:03:10 2016
@@ -98,8 +98,9 @@ class ObjCDeallocChecker
                      check::PointerEscape,
                      check::PreStmt<ReturnStmt>> {
 
-  mutable IdentifierInfo *NSObjectII, *SenTestCaseII, *Block_releaseII,
-                         *CIFilterII;
+  mutable IdentifierInfo *NSObjectII, *SenTestCaseII, *XCTestCaseII,
+      *Block_releaseII, *CIFilterII;
+
   mutable Selector DeallocSel, ReleaseSel;
 
   std::unique_ptr<BugType> MissingReleaseBugType;
@@ -760,9 +761,9 @@ bool ObjCDeallocChecker::diagnoseMistake
   return true;
 }
 
-ObjCDeallocChecker::
-    ObjCDeallocChecker()
-    : NSObjectII(nullptr), SenTestCaseII(nullptr), CIFilterII(nullptr) {
+ObjCDeallocChecker::ObjCDeallocChecker()
+    : NSObjectII(nullptr), SenTestCaseII(nullptr), XCTestCaseII(nullptr),
+      CIFilterII(nullptr) {
 
   MissingReleaseBugType.reset(
       new BugType(this, "Missing ivar release (leak)",
@@ -784,6 +785,7 @@ void ObjCDeallocChecker::initIdentifierI
 
   NSObjectII = &Ctx.Idents.get("NSObject");
   SenTestCaseII = &Ctx.Idents.get("SenTestCase");
+  XCTestCaseII = &Ctx.Idents.get("XCTestCase");
   Block_releaseII = &Ctx.Idents.get("_Block_release");
   CIFilterII = &Ctx.Idents.get("CIFilter");
 
@@ -1023,11 +1025,11 @@ bool ObjCDeallocChecker::classHasSeparat
     if (II == NSObjectII)
       return false;
 
-    // FIXME: For now, ignore classes that subclass SenTestCase, as these don't
-    // need to implement -dealloc.  They implement tear down in another way,
-    // which we should try and catch later.
+    // FIXME: For now, ignore classes that subclass SenTestCase and XCTestCase,
+    // as these don't need to implement -dealloc.  They implement tear down in
+    // another way, which we should try and catch later.
     //  http://llvm.org/bugs/show_bug.cgi?id=3187
-    if (II == SenTestCaseII)
+    if (II == XCTestCaseII || II == SenTestCaseII)
       return true;
   }
 

Modified: cfe/trunk/test/Analysis/DeallocMissingRelease.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/DeallocMissingRelease.m?rev=273441&r1=273440&r2=273441&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/DeallocMissingRelease.m (original)
+++ cfe/trunk/test/Analysis/DeallocMissingRelease.m Wed Jun 22 12:03:10 2016
@@ -723,6 +723,28 @@ struct SomeStruct {
 }
 @end
 
+ at interface XCTestCase : NSObject {}
+ at end
+
+ at interface MyClassXCTest : XCTestCase
+ at property (retain) NSObject *ivar;
+ at end
+
+ at implementation MyClassXCTest
+-(void)tearDown {
+#if NON_ARC
+  [_ivar release];
+#endif
+}
+
+-(void)dealloc; {
+#if NON_ARC
+  [super dealloc]; // no-warning
+#endif
+}
+ at end
+
+
 __attribute__((objc_root_class))
 @interface NonNSObjectMissingDealloc
 @property (retain) NSObject *ivar;




More information about the cfe-commits mailing list