r185974 - Objective-C: merge objc_requires_super attribute of
Fariborz Jahanian
fjahanian at apple.com
Tue Jul 9 15:02:20 PDT 2013
Author: fjahanian
Date: Tue Jul 9 17:02:20 2013
New Revision: 185974
URL: http://llvm.org/viewvc/llvm-project?rev=185974&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/super-dealloc-attribute.m
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=185974&r1=185973&r2=185974&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Jul 9 17:02:20 2013
@@ -406,7 +406,9 @@ void Sema::ActOnStartOfObjCMethodDef(Sco
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();
Modified: cfe/trunk/test/SemaObjC/super-dealloc-attribute.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super-dealloc-attribute.m?rev=185974&r1=185973&r2=185974&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super-dealloc-attribute.m (original)
+++ cfe/trunk/test/SemaObjC/super-dealloc-attribute.m Tue Jul 9 17:02:20 2013
@@ -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)
+
+ at interface UIViewController @end
+
+ at interface ViewController : UIViewController
+- (void) someMethodRequiringSuper NS_REQUIRES_SUPER;
+- (IBAction) someAction;
+- (IBAction) someActionRequiringSuper NS_REQUIRES_SUPER;
+ at end
+
+
+ at 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}}
+ at end
More information about the cfe-commits
mailing list