From 38b3bd8bf3c424e82b4dca0acaec84af28666656 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 9 Jul 2013 22:02:20 +0000 Subject: [PATCH] Objective-C: merge objc_requires_super attribute of 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 | 10 ++++++++- test/SemaObjC/super-dealloc-attribute.m | 30 ++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 87dfe10363..bbdf853fc8 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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()) + 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() && + !ObjCMethod->hasAttr()) { + // merge the attribute into implementation. + ObjCMethod->addAttr( + new (Context) ObjCRequiresSuperAttr(ObjCMethod->getLocation(), Context)); + } if (ObjCMethod->hasAttrs() && containsInvalidMethodImplAttribute(IMD, ObjCMethod->getAttrs())) { SourceLocation MethodLoc = IMD->getLocation(); diff --git a/test/SemaObjC/super-dealloc-attribute.m b/test/SemaObjC/super-dealloc-attribute.m index 35f6dac9bf..911de73266 100644 --- a/test/SemaObjC/super-dealloc-attribute.m +++ b/test/SemaObjC/super-dealloc-attribute.m @@ -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 @@ -85,3 +85,27 @@ } @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 -- 2.40.0