r244386 - [analyzer] Don't issue alarm in ObjCSuperCallChecker for the super class itself.

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 18:31:52 PDT 2015


Author: dcoughlin
Date: Fri Aug  7 20:31:51 2015
New Revision: 244386

URL: http://llvm.org/viewvc/llvm-project?rev=244386&view=rev
Log:
[analyzer] Don't issue alarm in ObjCSuperCallChecker for the super class itself.

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.

rdar://problem/18416944

Differential Revision: http://reviews.llvm.org/D11842

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
    cfe/trunk/test/Analysis/superclass.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp?rev=244386&r1=244385&r2=244386&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCMissingSuperCallChecker.cpp Fri Aug  7 20:31:51 2015
@@ -88,7 +88,7 @@ private:
 /// \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();

Modified: cfe/trunk/test/Analysis/superclass.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/superclass.m?rev=244386&r1=244385&r2=244386&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/superclass.m (original)
+++ cfe/trunk/test/Analysis/superclass.m Fri Aug  7 20:31:51 2015
@@ -30,7 +30,7 @@ typedef enum UIViewAnimationOptions {
 - (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 @@ typedef enum UIViewAnimationOptions {
 - (void)encodeRestorableStateWithCoder:(NSCoder *)coder {}
 @end
 
+// Do not warn for the implementation in the superclass itself.
+ at 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 {}
+ at end
+
 // Warn if UIViewController is our superclass and we do not call super
 @interface TestB : UIViewController {}
 @end




More information about the cfe-commits mailing list