r203586 - Objective-C. Diagose use of undefined protocols
Fariborz Jahanian
fjahanian at apple.com
Tue Mar 11 10:10:51 PDT 2014
Author: fjahanian
Date: Tue Mar 11 12:10:51 2014
New Revision: 203586
URL: http://llvm.org/viewvc/llvm-project?rev=203586&view=rev
Log:
Objective-C. Diagose use of undefined protocols
when a class adopts a protocol that inherits from
undefined protocols. // rdar://16111182
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/Analysis/region-1.m
cfe/trunk/test/SemaObjC/category-1.m
cfe/trunk/test/SemaObjC/class-def-test-1.m
cfe/trunk/test/SemaObjC/class-proto-1.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=203586&r1=203585&r2=203586&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 11 12:10:51 2014
@@ -2485,6 +2485,8 @@ def warn_objc_requires_super_protocol :
InGroup<DiagGroup<"requires-super-attribute">>;
def note_protocol_decl : Note<
"protocol is declared here">;
+def note_protocol_decl_undefined : Note<
+ "protocol %0 has no definition">;
// objc_designated_initializer attribute diagnostics.
def warn_objc_designated_init_missing_super_call : Warning<
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=203586&r1=203585&r2=203586&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Mar 11 12:10:51 2014
@@ -760,6 +760,22 @@ Sema::ActOnStartProtocolInterface(Source
return ActOnObjCContainerStartDefinition(PDecl);
}
+static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
+ ObjCProtocolDecl *&UndefinedProtocol) {
+ if (!PDecl->hasDefinition() || PDecl->getDefinition()->isHidden()) {
+ UndefinedProtocol = PDecl;
+ return true;
+ }
+
+ for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
+ E = PDecl->protocol_end(); PI != E; ++PI)
+ if (NestedProtocolHasNoDefinition((*PI), UndefinedProtocol)) {
+ UndefinedProtocol = (*PI);
+ return true;
+ }
+ return false;
+}
+
/// FindProtocolDeclaration - This routine looks up protocols and
/// issues an error if they are not declared. It returns list of
/// protocol declarations in its 'Protocols' argument.
@@ -795,10 +811,15 @@ Sema::FindProtocolDeclaration(bool WarnO
// If this is a forward declaration and we are supposed to warn in this
// case, do it.
// FIXME: Recover nicely in the hidden case.
+ ObjCProtocolDecl *UndefinedProtocol;
+
if (WarnOnDeclarations &&
- (!PDecl->hasDefinition() || PDecl->getDefinition()->isHidden()))
+ NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) {
Diag(ProtocolId[i].second, diag::warn_undef_protocolref)
<< ProtocolId[i].first;
+ Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined)
+ << UndefinedProtocol;
+ }
Protocols.push_back(PDecl);
}
}
Modified: cfe/trunk/test/Analysis/region-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region-1.m?rev=203586&r1=203585&r2=203586&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/region-1.m (original)
+++ cfe/trunk/test/Analysis/region-1.m Tue Mar 11 12:10:51 2014
@@ -25,7 +25,7 @@ typedef unsigned int NSUInteger;
CK_UNRESTRICTED= 0, CK_READ_ONLY, CK_ADD_ONLY, CK_REMOVE_ONLY };
@protocol EcoClass <EcoBehavioredClassifier> - (NSArray *) ownedAttributes;
@end @protocol EcoNamespace;
- at protocol EcoType;
+ at protocol EcoType @end;
@protocol EcoClassifier <EcoNamespace,EcoType> - (NSArray *) features;
@end @protocol EcoComment;
@protocol EcoElement <NSObject> - (NSArray *) ownedElements;
Modified: cfe/trunk/test/SemaObjC/category-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/category-1.m?rev=203586&r1=203585&r2=203586&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/category-1.m (original)
+++ cfe/trunk/test/SemaObjC/category-1.m Tue Mar 11 12:10:51 2014
@@ -2,7 +2,8 @@
@interface MyClass1 @end
- at protocol p1,p2,p3;
+ at protocol p1,p2,p3; // expected-note {{protocol 'p1' has no definition}} \
+ // expected-note {{protocol 'p2' has no definition}}
@interface MyClass1 (Category1) <p1> // expected-warning {{cannot find protocol definition for 'p1'}} expected-note {{previous definition is here}}
@end
Modified: cfe/trunk/test/SemaObjC/class-def-test-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-def-test-1.m?rev=203586&r1=203585&r2=203586&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-def-test-1.m (original)
+++ cfe/trunk/test/SemaObjC/class-def-test-1.m Tue Mar 11 12:10:51 2014
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
- at protocol SUPER;
+ at protocol SUPER; // expected-note {{protocol 'SUPER' has no definition}}
@interface SUPER <SUPER> @end // expected-warning {{cannot find protocol definition for 'SUPER'}}
Modified: cfe/trunk/test/SemaObjC/class-proto-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-proto-1.m?rev=203586&r1=203585&r2=203586&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-proto-1.m (original)
+++ cfe/trunk/test/SemaObjC/class-proto-1.m Tue Mar 11 12:10:51 2014
@@ -2,7 +2,8 @@
@interface INTF1 @end
- at protocol p1,p2,p3;
+ at protocol p1,p2,p3; // expected-note {{protocol 'p2' has no definition}} \
+ // expected-note {{protocol 'p3' has no definition}}
@protocol p1;
@@ -34,3 +35,14 @@
@interface I4 : U2 <p1,p2>
@end
+
+// rdar://16111182
+ at interface NSObject @end
+
+ at protocol UndefinedParentProtocol; // expected-note {{protocol 'UndefinedParentProtocol' has no definition}}
+
+ at protocol UndefinedProtocol <UndefinedParentProtocol>
+ at end
+
+ at interface SomeObject : NSObject <UndefinedProtocol> // expected-warning {{cannot find protocol definition for 'UndefinedProtocol'}}
+ at end
More information about the cfe-commits
mailing list