]> granicus.if.org Git - clang/commitdiff
[analyzer] DeallocChecker: Don't warn on release of readonly assign property in dealloc.
authorDevin Coughlin <dcoughlin@apple.com>
Sat, 6 Feb 2016 17:17:32 +0000 (17:17 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Sat, 6 Feb 2016 17:17:32 +0000 (17:17 +0000)
It is common for the ivars for read-only assign properties to always be stored retained,
so don't warn for a release in dealloc for the ivar backing these properties.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259998 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
test/Analysis/PR2978.m

index d17a8b539787a5a5a1f8aee874804af39263d887..1a3519307a21151a683f33ca3086d83218893101 100644 (file)
@@ -216,6 +216,12 @@ static void checkObjCDealloc(const CheckerBase *Checker,
            << "' was retained by a synthesized property "
               "but was not released in 'dealloc'";
       } else {
+        // It is common for the ivars for read-only assign properties to
+        // always be stored retained, so don't warn for a release in
+        // dealloc for the ivar backing these properties.
+        if (PD->isReadOnly())
+          continue;
+
         name = LOpts.getGC() == LangOptions::NonGC
                ? "extra ivar release (use-after-release)"
                : "extra ivar release (Hybrid MM, non-GC)";
index 6d5a6dfefc2e3c8e54a08c500567b831075e9246..1fbd9723a2b1ce2d08025b655f4272bfa76ff3eb 100644 (file)
@@ -39,7 +39,7 @@
 @synthesize Z = _Z; // expected-warning{{The '_Z' instance variable in 'MyClass' was not retained by a synthesized property but was released in 'dealloc'}}
 @synthesize K = _K;
 @synthesize L = _L; // no-warning
-@synthesize N = _N; // expected-warning{{The '_N' instance variable in 'MyClass' was not retained by a synthesized property but was released in 'dealloc'}}
+@synthesize N = _N; // no-warning
 @synthesize M = _M;
 @synthesize V = _V;
 @synthesize W = _W; // expected-warning{{The '_W' instance variable in 'MyClass' was retained by a synthesized property but was not released in 'dealloc'}}