[cfe-commits] r60598 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/SemaObjC/comptypes-a.m test/SemaObjC/method-typecheck-1.m

Fariborz Jahanian fjahanian at apple.com
Fri Dec 5 10:18:53 PST 2008


Author: fjahanian
Date: Fri Dec  5 12:18:52 2008
New Revision: 60598

URL: http://llvm.org/viewvc/llvm-project?rev=60598&view=rev
Log:
(instance/class) Method type checking between class and its implementation.
(instance/class) Method type checking between category and its implementation.
And a test case for all.


Added:
    cfe/trunk/test/SemaObjC/method-typecheck-1.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/comptypes-a.m

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Dec  5 12:18:52 2008
@@ -573,6 +573,8 @@
      "type of property %0 does not match type of accessor %1")
 DIAG(err_setter_type_void, ERROR,
      "type of setter must be void")
+DIAG(warn_conflicting_types, WARNING,
+     "conflicting types for %0")
 
 /// C++ parser diagnostics
 DIAG(err_expected_unqualified_id, ERROR,

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=60598&r1=60597&r2=60598&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Dec  5 12:18:52 2008
@@ -490,6 +490,8 @@
 
   void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
                            bool &IncompleteImpl);
+  void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
+                                   ObjCMethodDecl *IntfMethod);
 
   NamespaceDecl *GetStdNamespace();
                            

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Dec  5 12:18:52 2008
@@ -590,6 +590,32 @@
   Diag(ImpLoc, diag::warn_undef_method_impl) << method->getDeclName();
 }
 
+void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
+                                       ObjCMethodDecl *IntfMethodDecl) {
+  bool err = false;
+  QualType ImpMethodQType = 
+    Context.getCanonicalType(ImpMethodDecl->getResultType());
+  QualType IntfMethodQType = 
+    Context.getCanonicalType(IntfMethodDecl->getResultType());
+  if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType))
+    err = true;
+  else for (ObjCMethodDecl::param_iterator IM=ImpMethodDecl->param_begin(),
+            IF=IntfMethodDecl->param_begin(),
+            EM=ImpMethodDecl->param_end(); IM!=EM; ++IM, IF++) {
+    ImpMethodQType = Context.getCanonicalType((*IM)->getType());
+    IntfMethodQType = Context.getCanonicalType((*IF)->getType());
+    if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType)) {
+      err = true;
+      break;
+    }
+  }
+  if (err) {
+    Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_types) 
+    << ImpMethodDecl->getDeclName();
+    Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition);
+  }
+}
+
 /// FIXME: Type hierarchies in Objective-C can be deep. We could most
 /// likely improve the efficiency of selector lookups and type
 /// checking by associating with each protocol / interface / category
@@ -651,32 +677,12 @@
     if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector()))
       WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
     else if (!(*I)->isSynthesized()){
-      bool err = false;
       ObjCMethodDecl *ImpMethodDecl = 
         IMPDecl->getInstanceMethod((*I)->getSelector());
       ObjCMethodDecl *IntfMethodDecl = 
         IDecl->getInstanceMethod((*I)->getSelector());
-      QualType ImpMethodQType = 
-        Context.getCanonicalType(ImpMethodDecl->getResultType());
-      QualType IntfMethodQType = 
-        Context.getCanonicalType(IntfMethodDecl->getResultType());
-      if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType))
-        err = true;
-      else for (ObjCMethodDecl::param_iterator IM=ImpMethodDecl->param_begin(),
-                IF=IntfMethodDecl->param_begin(),
-                EM=ImpMethodDecl->param_end(); IM!=EM; ++IM, IF++) {
-        ImpMethodQType = Context.getCanonicalType((*IM)->getType());
-        IntfMethodQType = Context.getCanonicalType((*IF)->getType());
-        if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType)) {
-          err = true;
-          break;
-        }
-      }
-      if (err) {
-        Diag(ImpMethodDecl->getLocation(), diag::err_conflicting_types) 
-          << ImpMethodDecl->getDeclName();
-        Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition);
-      }
+      WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
+      
     }
       
   llvm::DenseSet<Selector> ClsMap;
@@ -690,6 +696,14 @@
        E = IDecl->classmeth_end(); I != E; ++I)
     if (!ClsMap.count((*I)->getSelector()))
       WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
+    else {
+      ObjCMethodDecl *ImpMethodDecl = 
+        IMPDecl->getClassMethod((*I)->getSelector());
+      ObjCMethodDecl *IntfMethodDecl = 
+        IDecl->getClassMethod((*I)->getSelector());
+      WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
+    }
+  
   
   // Check the protocol list for unimplemented methods in the @implementation
   // class.
@@ -717,6 +731,13 @@
        E = CatClassDecl->instmeth_end(); I != E; ++I)
     if (!InsMap.count((*I)->getSelector()))
       WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl);
+    else {
+      ObjCMethodDecl *ImpMethodDecl = 
+        CatImplDecl->getInstanceMethod((*I)->getSelector());
+      ObjCMethodDecl *IntfMethodDecl = 
+        CatClassDecl->getInstanceMethod((*I)->getSelector());
+      WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
+    }
 
   llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in category interface have been
@@ -730,7 +751,13 @@
        E = CatClassDecl->classmeth_end(); I != E; ++I)
     if (!ClsMap.count((*I)->getSelector()))
       WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl);
-  
+    else {
+      ObjCMethodDecl *ImpMethodDecl = 
+        CatImplDecl->getClassMethod((*I)->getSelector());
+      ObjCMethodDecl *IntfMethodDecl = 
+        CatClassDecl->getClassMethod((*I)->getSelector());
+      WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
+    }
   // Check the protocol list for unimplemented methods in the @implementation
   // class.
   for (ObjCCategoryDecl::protocol_iterator PI = CatClassDecl->protocol_begin(),

Modified: cfe/trunk/test/SemaObjC/comptypes-a.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/comptypes-a.m?rev=60598&r1=60597&r2=60598&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/comptypes-a.m (original)
+++ cfe/trunk/test/SemaObjC/comptypes-a.m Fri Dec  5 12:18:52 2008
@@ -23,7 +23,7 @@
 
 @implementation TedWantsToVerifyObjCDoesTheRightThing
 
-- compareThis:(id<PBXCompletionItem>)a withThat:(id<PBXCompletionItem>)b { // expected-error {{conflicting types for 'compareThis:withThat:'}}
+- compareThis:(id<PBXCompletionItem>)a withThat:(id<PBXCompletionItem>)b { // expected-warning {{conflicting types for 'compareThis:withThat:'}}
   return self;
 }
 

Added: cfe/trunk/test/SemaObjC/method-typecheck-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-typecheck-1.m?rev=60598&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/method-typecheck-1.m (added)
+++ cfe/trunk/test/SemaObjC/method-typecheck-1.m Fri Dec  5 12:18:52 2008
@@ -0,0 +1,33 @@
+ at interface A
+- (void) setMoo: (int) x;	//  expected-note {{previous definition is here}}
+- (int) setMoo1: (int) x;	//  expected-note {{previous definition is here}}
+- (int) setOk : (int) x : (double) d;
+ at end
+
+ at implementation A 
+-(void) setMoo: (float) x {}	//  expected-warning {{conflicting types for 'setMoo:'}}
+- (char) setMoo1: (int) x {}	//  expected-warning {{conflicting types for 'setMoo1:'}}
+- (int) setOk : (int) x : (double) d {}
+ at end
+
+
+
+ at interface C
++ (void) cMoo: (int) x;	//  expected-note {{previous definition is here}}
+ at end
+
+ at implementation C 
++(float) cMoo: (float) x {}	//  expected-warning {{conflicting types for 'cMoo:'}}
+ at end
+
+
+ at interface A(CAT)
+- (void) setCat: (int) x;	//  expected-note {{previous definition is here}}
++ (void) cCat: (int) x;	//  expected-note {{previous definition is here}}
+ at end
+
+ at implementation A(CAT) 
+-(float) setCat: (float) x {}	//  expected-warning {{conflicting types for 'setCat:'}}
++ (int) cCat: (int) x {}	//  expected-warning {{conflicting types for 'cCat:'}}
+ at end
+





More information about the cfe-commits mailing list