[cfe-commits] r100028 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/SemaObjC/category-1.m test/SemaObjC/compare-qualified-id.m test/SemaObjC/method-arg-decay.m test/SemaObjC/method-undef-category-warn-1.m test/SemaObjC/method-undef-extension-warn-1.m test/SemaObjC/no-protocol-option-tests.m test/SemaObjC/undef-protocol-methods-1.m
Fariborz Jahanian
fjahanian at apple.com
Wed Mar 31 11:23:33 PDT 2010
Author: fjahanian
Date: Wed Mar 31 13:23:33 2010
New Revision: 100028
URL: http://llvm.org/viewvc/llvm-project?rev=100028&view=rev
Log:
Patch implements gcc's -Wno-protocol option to suppress warning
on unimplemented methods in protocols adopted by a class.
(radar 7056600).
Added:
cfe/trunk/test/SemaObjC/no-protocol-option-tests.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/category-1.m
cfe/trunk/test/SemaObjC/compare-qualified-id.m
cfe/trunk/test/SemaObjC/method-arg-decay.m
cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m
cfe/trunk/test/SemaObjC/method-undef-extension-warn-1.m
cfe/trunk/test/SemaObjC/undef-protocol-methods-1.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Mar 31 13:23:33 2010
@@ -116,6 +116,7 @@
def ReadOnlySetterAttrs : DiagGroup<"readonly-setter-attrs">;
def Reorder : DiagGroup<"reorder">;
def UndeclaredSelector : DiagGroup<"undeclared-selector">;
+def Protocol : DiagGroup<"protocol">;
def SuperSubClassMismatch : DiagGroup<"super-class-method-mismatch">;
def : DiagGroup<"variadic-macros">;
def VariadicMacros : DiagGroup<"variadic-macros">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 31 13:23:33 2010
@@ -367,6 +367,8 @@
InGroup<ReadOnlySetterAttrs>, DefaultIgnore;
def warn_undeclared_selector : Warning<
"undeclared selector %0">, InGroup<UndeclaredSelector>, DefaultIgnore;
+def warn_unimplemented_protocol_method : Warning<
+ "method in protocol not implemented">, InGroup<Protocol>;
// C++ declarations
def err_static_assert_expression_is_not_constant : Error<
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Mar 31 13:23:33 2010
@@ -1453,7 +1453,7 @@
void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AttrList);
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
- bool &IncompleteImpl);
+ bool &IncompleteImpl, unsigned DiagID);
void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
ObjCMethodDecl *IntfMethod);
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Mar 31 13:23:33 2010
@@ -719,12 +719,12 @@
}
void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
- bool &IncompleteImpl) {
+ bool &IncompleteImpl, unsigned DiagID) {
if (!IncompleteImpl) {
Diag(ImpLoc, diag::warn_incomplete_impl);
IncompleteImpl = true;
}
- Diag(method->getLocation(), diag::note_undef_method_impl)
+ Diag(method->getLocation(), DiagID)
<< method->getDeclName();
}
@@ -815,9 +815,12 @@
ObjCMethodDecl *MethodInClass =
IDecl->lookupInstanceMethod(method->getSelector());
if (!MethodInClass || !MethodInClass->isSynthesized()) {
- WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
- Diag(CDecl->getLocation(), diag::note_required_for_protocol_at) <<
- PDecl->getDeclName();
+ unsigned DIAG = diag::warn_unimplemented_protocol_method;
+ if (Diags.getDiagnosticLevel(DIAG) != Diagnostic::Ignored) {
+ WarnUndefinedMethod(ImpLoc, method, IncompleteImpl, DIAG);
+ Diag(CDecl->getLocation(), diag::note_required_for_protocol_at)
+ << PDecl->getDeclName();
+ }
}
}
}
@@ -829,9 +832,12 @@
if (method->getImplementationControl() != ObjCMethodDecl::Optional &&
!ClsMap.count(method->getSelector()) &&
(!Super || !Super->lookupClassMethod(method->getSelector()))) {
- WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
- Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) <<
- PDecl->getDeclName();
+ unsigned DIAG = diag::warn_unimplemented_protocol_method;
+ if (Diags.getDiagnosticLevel(DIAG) != Diagnostic::Ignored) {
+ WarnUndefinedMethod(ImpLoc, method, IncompleteImpl, DIAG);
+ Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) <<
+ PDecl->getDeclName();
+ }
}
}
// Check on this protocols's referenced protocols, recursively.
@@ -861,7 +867,8 @@
if (!(*I)->isSynthesized() &&
!InsMap.count((*I)->getSelector())) {
if (ImmediateClass)
- WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
+ WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl,
+ diag::note_undef_method_impl);
continue;
} else {
ObjCMethodDecl *ImpMethodDecl =
@@ -885,7 +892,8 @@
ClsMapSeen.insert((*I)->getSelector());
if (!ClsMap.count((*I)->getSelector())) {
if (ImmediateClass)
- WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
+ WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl,
+ diag::note_undef_method_impl);
} else {
ObjCMethodDecl *ImpMethodDecl =
IMPDecl->getClassMethod((*I)->getSelector());
Modified: cfe/trunk/test/SemaObjC/category-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/category-1.m?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/category-1.m (original)
+++ cfe/trunk/test/SemaObjC/category-1.m Wed Mar 31 13:23:33 2010
@@ -62,7 +62,7 @@
// <rdar://problem/7249233>
@protocol MultipleCat_P
--(void) im0; // expected-note {{method definition for 'im0' not found}}
+-(void) im0; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@end
@interface MultipleCat_I @end // expected-note {{required for direct or indirect protocol 'MultipleCat_P'}}
Modified: cfe/trunk/test/SemaObjC/compare-qualified-id.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/compare-qualified-id.m?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/compare-qualified-id.m (original)
+++ cfe/trunk/test/SemaObjC/compare-qualified-id.m Wed Mar 31 13:23:33 2010
@@ -5,7 +5,7 @@
typedef struct _NSZone NSZone;
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
@protocol NSObject - (BOOL)isEqual:(id)object; @end
- at protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end // expected-note {{method definition for 'copyWithZone:' not found}}
+ at protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
@interface NSObject <NSObject> {} @end
Modified: cfe/trunk/test/SemaObjC/method-arg-decay.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-arg-decay.m?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-arg-decay.m (original)
+++ cfe/trunk/test/SemaObjC/method-arg-decay.m Wed Mar 31 13:23:33 2010
@@ -56,7 +56,7 @@
@interface PBXProjectModule : PBXModule <PBXFindableText> {
}
@end @class PBXBookmark;
- at protocol PBXSelectionTarget - (NSObject <PBXSelectionTarget> *) performAction:(id)action withSelection:(NSArray *)selection; // expected-note {{method definition for 'performAction:withSelection:' not found}}
+ at protocol PBXSelectionTarget - (NSObject <PBXSelectionTarget> *) performAction:(id)action withSelection:(NSArray *)selection; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@end @class XCPropertyDictionary, XCPropertyCondition, XCPropertyConditionSet, XCMutablePropertyConditionSet;
extern NSMutableArray *XCFindPossibleKeyModules(PBXModule *module, BOOL useExposedModulesOnly);
@interface NSString (StringUtilities) - (NSString *) trimToLength:(NSInteger)length preserveRange:(NSRange)range;
Modified: cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m (original)
+++ cfe/trunk/test/SemaObjC/method-undef-category-warn-1.m Wed Mar 31 13:23:33 2010
@@ -4,8 +4,8 @@
@end
@protocol P
-- (void) Pmeth; // expected-note {{method definition for 'Pmeth' not found}}
-- (void) Pmeth1; // expected-note {{method definition for 'Pmeth1' not found}}
+- (void) Pmeth; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
+- (void) Pmeth1; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@end
@interface MyClass1(CAT) <P> // expected-note {{required for direct or indirect protocol 'P'}}
Modified: cfe/trunk/test/SemaObjC/method-undef-extension-warn-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-undef-extension-warn-1.m?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-undef-extension-warn-1.m (original)
+++ cfe/trunk/test/SemaObjC/method-undef-extension-warn-1.m Wed Mar 31 13:23:33 2010
@@ -5,7 +5,7 @@
@protocol P
- (void)Pmeth;
-- (void)Pmeth1; // expected-note {{method definition for 'Pmeth1' not found}}
+- (void)Pmeth1; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@end
// Class extension
Added: cfe/trunk/test/SemaObjC/no-protocol-option-tests.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/no-protocol-option-tests.m?rev=100028&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/no-protocol-option-tests.m (added)
+++ cfe/trunk/test/SemaObjC/no-protocol-option-tests.m Wed Mar 31 13:23:33 2010
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -Wno-protocol -verify %s
+// rdar: // 7056600
+
+ at protocol P
+- PMeth;
+ at end
+
+// Test1
+ at interface I <P> @end
+ at implementation I @end // no warning with -Wno-protocol
+
+// Test2
+ at interface C -PMeth; @end
+ at interface C (Category) <P> @end
+ at implementation C (Category) @end // no warning with -Wno-protocol
+
+// Test2
+ at interface super - PMeth; @end
+ at interface J : super <P>
+- PMeth; // expected-note {{ method definition for 'PMeth' not found}}
+ at end
+ at implementation J @end // expected-warning {{incomplete implementation}}
+
+// Test3
+ at interface K : super <P>
+ at end
+ at implementation K @end // no warning with -Wno-protocol
+
+// Test4
+ at interface Root @end
+ at interface L : Root<P> @end
+ at implementation L @end // no warning with -Wno-protocol
Modified: cfe/trunk/test/SemaObjC/undef-protocol-methods-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/undef-protocol-methods-1.m?rev=100028&r1=100027&r2=100028&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/undef-protocol-methods-1.m (original)
+++ cfe/trunk/test/SemaObjC/undef-protocol-methods-1.m Wed Mar 31 13:23:33 2010
@@ -1,25 +1,25 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
@protocol P1
-- (void) P1proto; // expected-note {{method definition for 'P1proto' not found}}
-+ (void) ClsP1Proto; // expected-note {{method definition for 'ClsP1Proto' not found}}
+- (void) P1proto; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
++ (void) ClsP1Proto; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
- (void) DefP1proto;
@end
@protocol P2
-- (void) P2proto; // expected-note {{method definition for 'P2proto' not found}}
-+ (void) ClsP2Proto; // expected-note {{method definition for 'ClsP2Proto' not found}}
+- (void) P2proto; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
++ (void) ClsP2Proto; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@end
@protocol P3<P2>
-- (void) P3proto; // expected-note {{method definition for 'P3proto' not found}}
-+ (void) ClsP3Proto; // expected-note {{method definition for 'ClsP3Proto' not found}}
+- (void) P3proto; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
++ (void) ClsP3Proto; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
+ (void) DefClsP3Proto;
@end
@protocol PROTO<P1, P3>
-- (void) meth; // expected-note {{method definition for 'meth' not found}}
-- (void) meth : (int) arg1; // expected-note {{method definition for 'meth:' not found}}
-+ (void) cls_meth : (int) arg1; // expected-note {{method definition for 'cls_meth:' not found}}
+- (void) meth; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
+- (void) meth : (int) arg1; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
++ (void) cls_meth : (int) arg1; // expected-warning {{method in protocol not implemented [-Wprotocol]}}
@end
@interface INTF <PROTO> // expected-note 3 {{required for direct or indirect protocol 'PROTO'}} \
More information about the cfe-commits
mailing list