Author: fjahanian
Date: Fri Feb  4 17:19:27 2011
New Revision: 124909

URL: http://llvm.org/viewvc/llvm-project?rev=124909&view=rev
Log:
-Wselector should warn on implemented selectors only
when selector metadata is generated, which is triggered 
by at least on class implementation. This is to match gcc's
behavior. // rdar://8851684.

Added:
    cfe/trunk/test/SemaObjC/selector-2.m
Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/selector-1.m

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=124909&r1=124908&r2=124909&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Feb  4 17:19:27 2011
@@ -1381,6 +1381,11 @@
   /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none 
exists.
   ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
 
+  /// \brief returns true if there is at lease one @implementation in TU.
+  bool AnyObjCImplementation() {
+    return !ObjCImpls.empty();
+  }
+
   /// \brief Set the implementation of ObjCInterfaceDecl.
   void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
                              ObjCImplementationDecl *ImplD);

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=124909&r1=124908&r2=124909&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Feb  4 17:19:27 2011
@@ -1994,7 +1994,11 @@
 }
 
 void Sema::DiagnoseUseOfUnimplementedSelectors() {
-  if (ReferencedSelectors.empty())
+  // Warning will be issued only when selector table is
+  // generated (which means there is at lease one implementation
+  // in the TU). This is to match gcc's behavior.
+  if (ReferencedSelectors.empty() || 
+      !Context.AnyObjCImplementation())
     return;
   for (llvm::DenseMap<Selector, SourceLocation>::iterator S = 
         ReferencedSelectors.begin(),

Modified: cfe/trunk/test/SemaObjC/selector-1.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/selector-1.m?rev=124909&r1=124908&r2=124909&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/selector-1.m (original)
+++ cfe/trunk/test/SemaObjC/selector-1.m Fri Feb  4 17:19:27 2011
@@ -1,35 +1,29 @@
-// RUN: %clang_cc1 -verify %s 
+// RUN: %clang_cc1  -fsyntax-only -Wselector -verify %s
+// rdar://8851684
 
-@interface Lancelot @end
-@implementation Lancelot
+@interface Foo
+- (void) foo;
+- (void) bar;
+@end
 
-- (void):(int)x {}
-- (void)xx:(int)x :(int)y { }
+@implementation Foo
+- (void) bar
+{
+}
 
+- (void) foo
+{
+  SEL a,b,c;
+  a = @selector(b1ar);  // expected-warning {{unimplemented selector 'b1ar'}}
+  b = @selector(bar);
+}
 @end
 
 @interface I
-- (id) compare: (char) arg1;
+- length;
 @end
 
-@interface J
-- (id) compare: (id) arg1;
-@end
-
-SEL foo()
+SEL func()
 {
-       return @selector(compare:);     // Non warning on multiple selector 
found.
-}
-
-int main() {
- SEL s = @selector(retain);
- SEL s1 = @selector(meth1:);
- SEL s2 = @selector(retainArgument::);
- SEL s3 = @selector(retainArgument:::::);
- SEL s4 = @selector(retainArgument:with:);
- SEL s5 = @selector(meth1:with:with:);
- SEL s6 = @selector(getEnum:enum:bool:);
- SEL s7 = @selector(char:float:double:unsigned:short:long:);
-
- SEL s9 = @selector(:enum:bool:);
+    return  @selector(length);  // expected-warning {{unimplemented selector 
'length'}}
 }

Added: cfe/trunk/test/SemaObjC/selector-2.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/selector-2.m?rev=124909&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/selector-2.m (added)
+++ cfe/trunk/test/SemaObjC/selector-2.m Fri Feb  4 17:19:27 2011
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1  -fsyntax-only -Wselector -verify %s
+// rdar://8851684
+@interface  I
+- length;
+@end
+
+static inline SEL IsEmpty() {
+    return @selector(length);
+}
+
+int main (int argc, const char * argv[]) {
+    return 0;
+}
+


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to