[PATCH] [analyzer] Fix ObjC Dealloc Checker to operate only on classes with retained properties

Anna Zaks zaks.anna at gmail.com
Fri Aug 29 11:21:22 PDT 2014


================
Comment at: lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp:115
@@ -91,1 +114,3 @@
+  // writable pointers (or id<...>)?  If not, skip the check entirely.
+  // NOTE: This is motivated by PR 2517 and <rdar://problem/6074390>:
   //        http://llvm.org/bugs/show_bug.cgi?id=2517
----------------
We try to keep the codebase clear of radar (and PR) numbers. These are very welcome in the commit messages and test cases.

================
Comment at: lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp:206
@@ -194,3 +205,3 @@
     bool requiresRelease = PD->getSetterKind() != ObjCPropertyDecl::Assign;
     if (scan_ivar_release(MD->getBody(), ID, PD, RS, SelfII, Ctx)
        != requiresRelease) {
----------------
Would it be possible to move the checking of the setter (to be not 'assign') into the body of isSynthesizedWritablePointerProperty() ?

================
Comment at: test/Analysis/DeallocMissingRelease.m:142
@@ +141,3 @@
+
+// RUN: not %clang_cc1 -analyze -analyzer-checker=alpha.osx.cocoa.Dealloc -fblocks -triple x86_64-apple-darwin10 -fobjc-arc %s 2>&1 | FileCheck -check-prefix=CHECK-ARC %s
+// CHECK-ARC: DeallocMissingRelease.m:32:17: error: ARC forbids explicit message send of 'retain'
----------------
All of the run lines are usually placed in the front of the test file.

================
Comment at: test/Analysis/MissingDealloc.m:139
@@ +138,3 @@
+
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.osx.cocoa.Dealloc -fblocks %s 2>&1 | FileCheck -check-prefix=CHECK %s
+// CHECK: MissingDealloc.m:58:1: warning: Objective-C class 'MissingDeallocWithCopyProperty' lacks a 'dealloc' instance method
----------------
Run commands need to go into the beginning of the file.


================
Comment at: test/Analysis/PR2978.m:36
@@ -35,3 +35,3 @@
 @synthesize X = _X;
- at synthesize Y = _Y; // expected-warning{{The '_Y' instance variable was retained by a synthesized property but wasn't released in 'dealloc'}}
- at synthesize Z = _Z; // expected-warning{{The '_Z' instance variable was not retained by a synthesized property but was released in 'dealloc'}}
+ at synthesize Y = _Y; // expected-warning{{The '_Y' instance variable in Objective-C class 'MyClass' was retained by a synthesized property but was not released in 'dealloc'}}
+ at synthesize Z = _Z; // expected-warning{{The '_Z' instance variable in Objective-C class 'MyClass' was not retained by a synthesized property but was released in 'dealloc'}}
----------------
We prefer to keep the warning messages as short as possible. (One reason is that the IDE real estate is at a premium.) So here, I would drop "Objective-C class".

http://reviews.llvm.org/D5023






More information about the cfe-commits mailing list