dcoughlin created this revision.
dcoughlin added reviewers: zaks.anna, jordan_rose, xazax.hun.
dcoughlin added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

The ObjCSuperCallChecker issues alarms for various Objective-C APIs that require
a subclass to call to its superclass's version of a method when overriding it.
So, for example, it raises an alarm when the -viewDidLoad method in a subclass 
of UIViewController does not call [super viewDidLoad].

This patch fixes a false alarm where the analyzer erroneously required the
implementation of the superclass itself (e.g., UIViewController) to call
super.

http://reviews.llvm.org/D11842

Files:
  lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
  test/Analysis/superclass.m

Index: test/Analysis/superclass.m
===================================================================
--- test/Analysis/superclass.m
+++ test/Analysis/superclass.m
@@ -30,7 +30,7 @@
 - (void)didReceiveMemoryWarning;
 - (void)removeFromParentViewController;
 - (void)transitionFromViewController:(UIViewController *)fromViewController
-  toViewController:(UIViewController *)toViewController 
+  toViewController:(UIViewController *)toViewController
   duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options
   animations:(void (^)(void))animations
   completion:(void (^)(BOOL finished))completion;
@@ -69,6 +69,25 @@
 - (void)encodeRestorableStateWithCoder:(NSCoder *)coder {}
 @end
 
+// Do not warn for the implementation in the superclass itself.
+@implementation UIViewController
+- (void)addChildViewController:(UIViewController *)childController {}
+- (void)viewDidAppear:(BOOL)animated {}
+- (void)viewDidDisappear:(BOOL)animated {}
+- (void)viewDidUnload {}
+- (void)viewDidLoad {}
+- (void)viewWillUnload {}
+- (void)viewWillAppear:(BOOL)animated {}
+- (void)viewWillDisappear:(BOOL)animated {}
+- (void)didReceiveMemoryWarning {}
+- (void)removeFromParentViewController {}
+- (void)transitionFromViewController:(UIViewController *)fromViewController
+  toViewController:(UIViewController *)toViewController
+  duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options
+  animations:(void (^)(void))animations
+  completion:(void (^)(BOOL finished))completion {}
+@end
+
 // Warn if UIViewController is our superclass and we do not call super
 @interface TestB : UIViewController {}
 @end
Index: lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
@@ -88,7 +88,7 @@
 /// \param[out] SuperclassName On return, the found superclass name.
 bool ObjCSuperCallChecker::isCheckableClass(const ObjCImplementationDecl *D,
                                             StringRef &SuperclassName) const {
-  const ObjCInterfaceDecl *ID = D->getClassInterface();
+  const ObjCInterfaceDecl *ID = D->getClassInterface()->getSuperClass();
   for ( ; ID ; ID = ID->getSuperClass())
   {
     SuperclassName = ID->getIdentifier()->getName();


Index: test/Analysis/superclass.m
===================================================================
--- test/Analysis/superclass.m
+++ test/Analysis/superclass.m
@@ -30,7 +30,7 @@
 - (void)didReceiveMemoryWarning;
 - (void)removeFromParentViewController;
 - (void)transitionFromViewController:(UIViewController *)fromViewController
-  toViewController:(UIViewController *)toViewController 
+  toViewController:(UIViewController *)toViewController
   duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options
   animations:(void (^)(void))animations
   completion:(void (^)(BOOL finished))completion;
@@ -69,6 +69,25 @@
 - (void)encodeRestorableStateWithCoder:(NSCoder *)coder {}
 @end
 
+// Do not warn for the implementation in the superclass itself.
+@implementation UIViewController
+- (void)addChildViewController:(UIViewController *)childController {}
+- (void)viewDidAppear:(BOOL)animated {}
+- (void)viewDidDisappear:(BOOL)animated {}
+- (void)viewDidUnload {}
+- (void)viewDidLoad {}
+- (void)viewWillUnload {}
+- (void)viewWillAppear:(BOOL)animated {}
+- (void)viewWillDisappear:(BOOL)animated {}
+- (void)didReceiveMemoryWarning {}
+- (void)removeFromParentViewController {}
+- (void)transitionFromViewController:(UIViewController *)fromViewController
+  toViewController:(UIViewController *)toViewController
+  duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options
+  animations:(void (^)(void))animations
+  completion:(void (^)(BOOL finished))completion {}
+@end
+
 // Warn if UIViewController is our superclass and we do not call super
 @interface TestB : UIViewController {}
 @end
Index: lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
@@ -88,7 +88,7 @@
 /// \param[out] SuperclassName On return, the found superclass name.
 bool ObjCSuperCallChecker::isCheckableClass(const ObjCImplementationDecl *D,
                                             StringRef &SuperclassName) const {
-  const ObjCInterfaceDecl *ID = D->getClassInterface();
+  const ObjCInterfaceDecl *ID = D->getClassInterface()->getSuperClass();
   for ( ; ID ; ID = ID->getSuperClass())
   {
     SuperclassName = ID->getIdentifier()->getName();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to