[llvm-branch-commits] [cfe-branch] r71292 - in /cfe/branches/Apple/Dib: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp test/SemaObjC/property-typecheck-1.m

Mike Stump mrs at apple.com
Fri May 8 16:37:44 PDT 2009


Author: mrs
Date: Fri May  8 18:37:44 2009
New Revision: 71292

URL: http://llvm.org/viewvc/llvm-project?rev=71292&view=rev
Log:
Merge in 71243:

More type checking for properties, accessors and
use of dot-syntax expression. This is to match gcc's.

Modified:
    cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp
    cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp
    cfe/branches/Apple/Dib/test/SemaObjC/property-typecheck-1.m

Modified: cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticSemaKinds.td?rev=71292&r1=71291&r2=71292&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/Apple/Dib/include/clang/Basic/DiagnosticSemaKinds.td Fri May  8 18:37:44 2009
@@ -174,7 +174,7 @@
   "conflicting parameter types in implementation of %0: %1 vs %2">;
 
 def warn_multiple_method_decl : Warning<"multiple methods named %0 found">;
-def err_accessor_property_type_mismatch : Error<
+def warn_accessor_property_type_mismatch : Warning<
   "type of property %0 does not match type of accessor %1">;
 def note_declared_at : Note<"declared at">;
 def err_setter_type_void : Error<"type of setter must be void">;

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp?rev=71292&r1=71291&r2=71292&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp Fri May  8 18:37:44 2009
@@ -1315,11 +1315,17 @@
   
   if (GetterMethod &&
       GetterMethod->getResultType() != property->getType()) {
-    Diag(property->getLocation(), 
-         diag::err_accessor_property_type_mismatch) 
-      << property->getDeclName()
-      << GetterMethod->getSelector();
-    Diag(GetterMethod->getLocation(), diag::note_declared_at);
+    AssignConvertType result = Incompatible;
+    if (Context.isObjCObjectPointerType(property->getType()))
+      result = CheckAssignmentConstraints(property->getType(), 
+                                          GetterMethod->getResultType());
+    if (result != Compatible) {
+      Diag(property->getLocation(), 
+           diag::warn_accessor_property_type_mismatch) 
+        << property->getDeclName()
+        << GetterMethod->getSelector();
+      Diag(GetterMethod->getLocation(), diag::note_declared_at);
+    }
   }
   
   if (SetterMethod) {
@@ -1329,7 +1335,7 @@
     if (SetterMethod->param_size() != 1 ||
         ((*SetterMethod->param_begin())->getType() != property->getType())) {
       Diag(property->getLocation(), 
-           diag::err_accessor_property_type_mismatch) 
+           diag::warn_accessor_property_type_mismatch) 
         << property->getDeclName()
         << SetterMethod->getSelector();
       Diag(SetterMethod->getLocation(), diag::note_declared_at);

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp?rev=71292&r1=71291&r2=71292&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp Fri May  8 18:37:44 2009
@@ -2096,8 +2096,21 @@
       // Check whether we can reference this property.
       if (DiagnoseUseOfDecl(PD, MemberLoc))
         return ExprError();
-
-      return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
+      QualType ResTy = PD->getType();
+      Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
+      ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Context, Sel);
+      if (Getter) {
+        AssignConvertType result =
+          CheckAssignmentConstraints(PD->getType(), Getter->getResultType());
+        if (result != Compatible) {
+          Diag(MemberLoc, diag::warn_accessor_property_type_mismatch) 
+            << PD->getDeclName() << Sel;
+          Diag(Getter->getLocation(), diag::note_declared_at);
+          ResTy = Getter->getResultType();
+        }
+      }
+      
+      return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
                                                      MemberLoc, BaseExpr));
     }
 

Modified: cfe/branches/Apple/Dib/test/SemaObjC/property-typecheck-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/SemaObjC/property-typecheck-1.m?rev=71292&r1=71291&r2=71292&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/SemaObjC/property-typecheck-1.m (original)
+++ cfe/branches/Apple/Dib/test/SemaObjC/property-typecheck-1.m Fri May  8 18:37:44 2009
@@ -2,7 +2,7 @@
 
 @interface A
 -(float) x;	// expected-note {{declared at}}
- at property int x; // expected-error {{type of property 'x' does not match type of accessor 'x'}}
+ at property int x; // expected-warning {{type of property 'x' does not match type of accessor 'x'}}
 @end
 
 @interface A (Cat)
@@ -29,3 +29,73 @@
 @end
 
 
+ at class SSyncSet;
+
+ at interface SPeer
+  @property(nonatomic,readonly,retain) SSyncSet* syncSet;
+ at end
+
+ at class SSyncSet_iDisk;
+
+ at interface SPeer_iDisk_remote1 : SPeer
+- (SSyncSet_iDisk*) syncSet; // expected-note {{declared at}}
+ at end
+
+ at interface SPeer_iDisk_local
+- (SSyncSet_iDisk*) syncSet;
+ at end
+
+ at interface SSyncSet
+ at end
+
+ at interface SSyncSet_iDisk
+ at property(nonatomic,readonly,retain) SPeer_iDisk_local* localPeer;
+ at end
+
+ at interface SPeer_iDisk_remote1 (protected)
+ at end
+
+ at implementation SPeer_iDisk_remote1 (protected)
+- (id) preferredSource1
+{
+  return self.syncSet.localPeer; // expected-warning {{type of property 'syncSet' does not match type of accessor 'syncSet'}}
+}
+ at end
+
+ at interface NSArray @end
+
+ at interface NSMutableArray : NSArray
+ at end
+
+ at interface Class1 
+{
+ NSMutableArray* pieces;
+ NSArray* first;
+}
+
+ at property (readonly) NSArray* pieces;
+ at property (readonly) NSMutableArray* first; // expected-warning {{type of property 'first' does not match type of accessor 'first'}}
+
+- (NSMutableArray*) pieces;
+- (NSArray*) first;	// expected-note {{declared at}}  // expected-note {{declared at}}
+ at end
+
+ at interface Class2  {
+ Class1* container;
+}
+
+ at end
+
+ at implementation Class2
+
+- (id) lastPiece
+{
+ return container.pieces;
+}
+
+- (id)firstPeice
+{
+  return container.first; // expected-warning {{type of property 'first' does not match type of accessor 'first'}}
+}
+ at end
+





More information about the llvm-branch-commits mailing list