From: Devin Coughlin Date: Sat, 6 Feb 2016 17:17:32 +0000 (+0000) Subject: [analyzer] DeallocChecker: Don't warn on release of readonly assign property in dealloc. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44272b9ce7be2c5a2b81a81cb2383b07ad3948d8;p=clang [analyzer] DeallocChecker: Don't warn on release of readonly assign property in dealloc. 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 --- diff --git a/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp b/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp index d17a8b5397..1a3519307a 100644 --- a/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp +++ b/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp @@ -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)"; diff --git a/test/Analysis/PR2978.m b/test/Analysis/PR2978.m index 6d5a6dfefc..1fbd9723a2 100644 --- a/test/Analysis/PR2978.m +++ b/test/Analysis/PR2978.m @@ -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'}}