[cfe-commits] r65974 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaExprObjC.cpp test/SemaObjC/conditional-expr.m test/SemaObjC/warn-selector-selection.m

Fariborz Jahanian fjahanian at apple.com
Tue Mar 3 14:19:16 PST 2009


Author: fjahanian
Date: Tue Mar  3 16:19:15 2009
New Revision: 65974

URL: http://llvm.org/viewvc/llvm-project?rev=65974&view=rev
Log:
Implement an important missing warning when a selector
is searched for in the global pool. It already uncovered 
a clang bug in message selection.


Added:
    cfe/trunk/test/SemaObjC/warn-selector-selection.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/conditional-expr.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=65974&r1=65973&r2=65974&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Tue Mar  3 16:19:15 2009
@@ -1454,3 +1454,5 @@
      "instance variable %0 is private")
 DIAG(error_protected_ivar_access, ERROR,
      "instance variable %0 is protected")
+DIAG(warn_maynot_respond, WARNING,
+     "%0  may not respond to %1")

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=65974&r1=65973&r2=65974&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Mar  3 16:19:15 2009
@@ -450,16 +450,28 @@
     }
     if (!Method) {
       // If we have an implementation in scope, check "private" methods.
-      if (ClassDecl)
+      if (ClassDecl) {
         if (ObjCImplementationDecl *ImpDecl = 
               ObjCImplementations[ClassDecl->getIdentifier()])
           Method = ImpDecl->getInstanceMethod(Sel);
-          // If we still haven't found a method, look in the global pool. This
-          // behavior isn't very desirable, however we need it for GCC
-          // compatibility. FIXME: should we deviate??
-          if (!Method && OCIType->qual_empty())
-            Method = LookupInstanceMethodInGlobalPool(
-                                 Sel, SourceRange(lbrac,rbrac));
+        // Look through local category implementations associated with the class.
+        if (!Method) {
+          for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
+            if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
+              Method = ObjCCategoryImpls[i]->getInstanceMethod(Sel);
+          }
+        }
+      }
+      // If we still haven't found a method, look in the global pool. This
+      // behavior isn't very desirable, however we need it for GCC
+      // compatibility. FIXME: should we deviate??
+      if (!Method && OCIType->qual_empty()) {
+        Method = LookupInstanceMethodInGlobalPool(
+                             Sel, SourceRange(lbrac,rbrac));
+        if (Method && !OCIType->getDecl()->isForwardDecl())
+          Diag(lbrac, diag::warn_maynot_respond) 
+            << OCIType->getDecl()->getIdentifier()->getName() << Sel;
+      }
     }
     if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
       return true;

Modified: cfe/trunk/test/SemaObjC/conditional-expr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/conditional-expr.m?rev=65974&r1=65973&r2=65974&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/conditional-expr.m (original)
+++ cfe/trunk/test/SemaObjC/conditional-expr.m Tue Mar  3 16:19:15 2009
@@ -36,7 +36,7 @@
 // No @interface declaration for DTFilterOutputStream3
 @implementation DTFilterOutputStream3 // expected-warning {{cannot find interface declaration for 'DTFilterOutputStream3'}}
 - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
-  id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
+  id <DTOutputStreams> nextOutputStream = [self nextOutputStream]; // expected-warning {{DTFilterOutputStream3  may not respond to 'nextOutputStream'}}
   // GCC warns about both of these as well (no errors).
   self = nextOutputStream; // expected-warning {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream3 *'}}
   return nextOutputStream ? nextOutputStream : self;

Added: cfe/trunk/test/SemaObjC/warn-selector-selection.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-selector-selection.m?rev=65974&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/warn-selector-selection.m (added)
+++ cfe/trunk/test/SemaObjC/warn-selector-selection.m Tue Mar  3 16:19:15 2009
@@ -0,0 +1,14 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface Object 
+- (void)foo;
+ at end
+
+ at interface Class1
+- (void)setWindow:(Object *)wdw;
+ at end
+
+void foo(void) {
+  Object *obj;
+  [obj setWindow:0]; // expected-warning{{Object  may not respond to 'setWindow:'}}
+}





More information about the cfe-commits mailing list