]> granicus.if.org Git - clang/commitdiff
Objective-C: merge objc_requires_super attribute of
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 9 Jul 2013 22:02:20 +0000 (22:02 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 9 Jul 2013 22:02:20 +0000 (22:02 +0000)
method declaration into its implementation to
prevent a bogus warning about mismatched attributes.
then make sure the warning about missing call to super comes out
of the method implementation. // rdar://14251387

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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/super-dealloc-attribute.m

index 87dfe10363015a6a9f12777baa1f8777d56dc38a..bbdf853fc8a140b0c581373f6146de8fbeb11a81 100644 (file)
@@ -406,7 +406,9 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
         if (Context.getLangOpts().getGC() != LangOptions::NonGC)
           getCurFunction()->ObjCShouldCallSuper = true;
         
-      } else {
+      } else if (MDecl->hasAttr<ObjCRequiresSuperAttr>())
+        getCurFunction()->ObjCShouldCallSuper = true;
+      else {
         const ObjCMethodDecl *SuperMethod =
           SuperClass->lookupMethod(MDecl->getSelector(),
                                    MDecl->isInstanceMethod());
@@ -3200,6 +3202,12 @@ Decl *Sema::ActOnMethodDeclaration(
     if (ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface())
       IMD = IDecl->lookupMethod(ObjCMethod->getSelector(), 
                                 ObjCMethod->isInstanceMethod());
+    if (IMD && IMD->hasAttr<ObjCRequiresSuperAttr>() &&
+        !ObjCMethod->hasAttr<ObjCRequiresSuperAttr>()) {
+      // merge the attribute into implementation.
+      ObjCMethod->addAttr(
+        new (Context) ObjCRequiresSuperAttr(ObjCMethod->getLocation(), Context));
+    }
     if (ObjCMethod->hasAttrs() &&
         containsInvalidMethodImplAttribute(IMD, ObjCMethod->getAttrs())) {
       SourceLocation MethodLoc = IMD->getLocation();
index 35f6dac9bf42e006b76b9607312a6e457f1c972a..911de732668921dcc0caf418ca72bc6fb9f1ea4d 100644 (file)
@@ -40,9 +40,9 @@
   [super MyDealloc];
 } // expected-warning {{method possibly missing a [super XXX] call}}
 
-- (void) MyDeallocMeth {} // No warning here.
+- (void) MyDeallocMeth {} // expected-warning {{method possibly missing a [super MyDeallocMeth] call}}
 - (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
-- (void) AnnotMeth{}; // No warning here. Annotation is in its class.
+- (void) AnnotMeth{}; // expected-warning {{method possibly missing a [super AnnotMeth] call}}
 
 + (void)registerClass:(id)name {} // expected-warning {{method possibly missing a [super registerClass:] call}}
 @end
@@ -66,7 +66,7 @@
 - (void) AnnotMyDeallocMeth{} // expected-warning {{method possibly missing a [super AnnotMyDeallocMeth] call}}
 - (void) AnnotMeth{};  // expected-warning {{method possibly missing a [super AnnotMeth] call}}
 - (void) AnnotMyDeallocMethCAT{}; // expected-warning {{method possibly missing a [super AnnotMyDeallocMethCAT] call}}
-- (void) AnnotMethCAT {};
+- (void) AnnotMethCAT {}; // expected-warning {{method possibly missing a [super AnnotMethCAT] call}}
 @end
 
 
 }
 
 @end
+
+// rdar://14251387
+#define IBAction void)__attribute__((ibaction)
+
+@interface UIViewController @end
+
+@interface ViewController : UIViewController
+- (void) someMethodRequiringSuper NS_REQUIRES_SUPER;
+- (IBAction) someAction;
+- (IBAction) someActionRequiringSuper NS_REQUIRES_SUPER;
+@end
+
+
+@implementation ViewController
+- (void) someMethodRequiringSuper
+{
+} // expected-warning {{method possibly missing a [super someMethodRequiringSuper] call}}
+- (IBAction) someAction
+{
+}
+- (IBAction) someActionRequiringSuper
+{
+} // expected-warning {{method possibly missing a [super someActionRequiringSuper] call}}
+@end