[cfe-commits] r171769 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp test/Analysis/objc_invalidation.m

Anna Zaks ganna at apple.com
Mon Jan 7 11:12:57 PST 2013


Author: zaks
Date: Mon Jan  7 13:12:56 2013
New Revision: 171769

URL: http://llvm.org/viewvc/llvm-project?rev=171769&view=rev
Log:
[analyzer] Fix a false positive in the ivar invalidation checker.

When a property is "inherited" through both a parent class and directly
through a protocol, we should not require the child to invalidate it
since the backing ivar belongs to the parent class.
(Fixes radar://12913734)

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
    cfe/trunk/test/Analysis/objc_invalidation.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp?rev=171769&r1=171768&r2=171769&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp Mon Jan  7 13:12:56 2013
@@ -271,7 +271,9 @@
 
   // Lookup for the synthesized case.
   IvarD = Prop->getPropertyIvarDecl();
-  if (IvarD) {
+  // We only track the ivars/properties that are defined in the current 
+  // class (not the parent).
+  if (IvarD && IvarD->getContainingInterface() == InterfaceD) {
     if (TrackedIvars.count(IvarD)) {
       return IvarD;
     }

Modified: cfe/trunk/test/Analysis/objc_invalidation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objc_invalidation.m?rev=171769&r1=171768&r2=171769&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/objc_invalidation.m (original)
+++ cfe/trunk/test/Analysis/objc_invalidation.m Mon Jan  7 13:12:56 2013
@@ -151,3 +151,32 @@
  // expected-warning at -6 {{Instance variable _Ivar4 needs to be invalidated}}
  // expected-warning at -7 {{Instance variable Ivar5 needs to be invalidated or set to nil}}
 @end
+
+// Example, where the same property is inherited through 
+// the parent and directly through a protocol. If a property backing ivar is 
+// synthesized in the parent, let the parent invalidate it.
+
+ at protocol IDEBuildable <NSObject>
+ at property (readonly, strong) id <Invalidation2> ObjB;
+ at end
+
+ at interface Parent : NSObject <IDEBuildable, Invalidation2> {
+  Invalidation2Class *_ObjB; // Invalidation of ObjB happens in the parent.
+}
+ at end
+
+ at interface Child: Parent <Invalidation2, IDEBuildable> 
+ at end
+
+ at implementation Parent
+ at synthesize ObjB = _ObjB;
+- (void)invalidate{
+  _ObjB = ((void*)0);
+}
+ at end
+
+ at implementation Child
+- (void)invalidate{ 
+  // no-warning
+} 
+ at end





More information about the cfe-commits mailing list