]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix a false positive in the ivar invalidation checker.
authorAnna Zaks <ganna@apple.com>
Mon, 7 Jan 2013 19:12:56 +0000 (19:12 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 7 Jan 2013 19:12:56 +0000 (19:12 +0000)
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)

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

lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
test/Analysis/objc_invalidation.m

index d326067e535cd1948221f509e2f8e97af2c2046c..d2f27f53e710495e67cbaa3dd6e73fc79cf1119c 100644 (file)
@@ -271,7 +271,9 @@ const ObjCIvarDecl *IvarInvalidationChecker::findPropertyBackingIvar(
 
   // 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;
     }
index 357c5e8f607aace7aac1430e30892fb4b20510a2..cf6bcd5aa37ab36d9309d38d9fb105ddd89eebae 100644 (file)
@@ -151,3 +151,32 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
  // expected-warning@-6 {{Instance variable _Ivar4 needs to be invalidated}}
  // expected-warning@-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.
+
+@protocol IDEBuildable <NSObject>
+@property (readonly, strong) id <Invalidation2> ObjB;
+@end
+
+@interface Parent : NSObject <IDEBuildable, Invalidation2> {
+  Invalidation2Class *_ObjB; // Invalidation of ObjB happens in the parent.
+}
+@end
+
+@interface Child: Parent <Invalidation2, IDEBuildable> 
+@end
+
+@implementation Parent
+@synthesize ObjB = _ObjB;
+- (void)invalidate{
+  _ObjB = ((void*)0);
+}
+@end
+
+@implementation Child
+- (void)invalidate{ 
+  // no-warning
+} 
+@end