diff options
author | Anna Zaks <ganna@apple.com> | 2012-10-18 19:17:57 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-10-18 19:17:57 +0000 |
commit | c3c26b7390bc4ac3ad122f557a10ba17ab871216 (patch) | |
tree | 1251b877f828ace5b1df666136bba81ce85287d2 | |
parent | b36ea375e20f71df19c101fa2399b7ea3a607e04 (diff) |
[analyzer] Ivar invalidation: identify properties declared in protocols.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166211 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp | 14 | ||||
-rw-r--r-- | test/Analysis/objc_invalidation.m | 6 |
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index e52e3d42e2..bf256cd9fa 100644 --- a/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -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"; diff --git a/test/Analysis/objc_invalidation.m b/test/Analysis/objc_invalidation.m index 17b74e90c5..357c5e8f60 100644 --- a/test/Analysis/objc_invalidation.m +++ b/test/Analysis/objc_invalidation.m @@ -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 |