]> granicus.if.org Git - clang/commitdiff
[analyzer] Ivar invalidation: identify properties declared in protocols.
authorAnna Zaks <ganna@apple.com>
Thu, 18 Oct 2012 19:17:57 +0000 (19:17 +0000)
committerAnna Zaks <ganna@apple.com>
Thu, 18 Oct 2012 19:17:57 +0000 (19:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166211 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e52e3d42e25179c61032b7932618c9a8d0717170..bf256cd9fa454cc4ebeae7705213eb4b42d45cd6 100644 (file)
@@ -327,10 +327,13 @@ void IvarInvalidationChecker::checkASTDecl(const ObjCMethodDecl *D,
   MethToIvarMapTy PropGetterToIvarMap;
   PropToIvarMapTy PropertyToIvarMap;
   IvarToPropMapTy IvarToPopertyMap;
-  for (ObjCInterfaceDecl::prop_iterator
-      I = InterfaceD->prop_begin(),
-      E = InterfaceD->prop_end(); I != E; ++I) {
-    const ObjCPropertyDecl *PD = *I;
+
+  ObjCInterfaceDecl::PropertyMap PropMap;
+  InterfaceD->collectPropertiesToImplement(PropMap);
+
+  for (ObjCInterfaceDecl::PropertyMap::iterator
+      I = PropMap.begin(), E = PropMap.end(); I != E; ++I) {
+    const ObjCPropertyDecl *PD = I->second;
 
     const ObjCIvarDecl *ID = findPropertyBackingIvar(PD, InterfaceD, Ivars);
     if (!ID) {
@@ -386,7 +389,8 @@ void IvarInvalidationChecker::checkASTDecl(const ObjCMethodDecl *D,
         const ObjCPropertyDecl *PD = IvarToPopertyMap[IvarDecl];
         assert(PD &&
                "Do we synthesize ivars for something other than properties?");
-        os << "Property "<< PD->getName() << " needs to be invalidated";
+        os << "Property "<< PD->getName() <<
+              " needs to be invalidated or set to nil";
       } else {
         os << "Instance variable "<< IvarDecl->getName()
              << " needs to be invalidated or set to nil";
index 17b74e90c50ee6629b2474303ab4a463cee7bc2c..357c5e8f607aace7aac1430e30892fb4b20510a2 100644 (file)
@@ -63,6 +63,7 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
   SomeInvalidationImplementingObject *_Prop3; // property, invalidate via sending a message to a getter method
   SomeInvalidationImplementingObject *_Prop4; // property with @synthesize, invalidate via property
   SomeInvalidationImplementingObject *_Prop5; // property with @synthesize, invalidate via getter method
+  SomeInvalidationImplementingObject *_Prop8;
   
   // No warnings on these as they are not invalidatable.
   NSObject *NIvar1;
@@ -106,6 +107,7 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
 @synthesize Prop3 = _Prop3;
 @synthesize Prop5 = _Prop5;
 @synthesize Prop4 = _Prop4;
+@synthesize Prop8 = _Prop8;
 
 
 - (void) setProp1: (SomeInvalidationImplementingObject*) InObj {
@@ -133,6 +135,7 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
    [self setProp3:0];
    [[self Prop5] invalidate2];
    [self.Prop4 invalidate];
+   [self.Prop8 invalidate];
    self.Prop6 = 0;
    [[self Prop7] invalidate];
 
@@ -143,9 +146,8 @@ extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1,
 // expected-warning@-1 {{Instance variable Ivar1 needs to be invalidated}}
  // expected-warning@-2 {{Instance variable MultipleProtocols needs to be invalidated}}
  // expected-warning@-3 {{Instance variable MultInheritance needs to be invalidated}}
- // expected-warning@-4 {{Property SynthIvarProp needs to be invalidated}}
+ // expected-warning@-4 {{Property SynthIvarProp needs to be invalidated or set to nil}}
  // expected-warning@-5 {{Instance variable _Ivar3 needs to be invalidated}}
  // expected-warning@-6 {{Instance variable _Ivar4 needs to be invalidated}}
  // expected-warning@-7 {{Instance variable Ivar5 needs to be invalidated or set to nil}}
- // expected-warning@-8 {{Property Prop8 needs to be invalidated}}
 @end