[cfe-commits] r60610 - in /cfe/trunk: include/clang/AST/DeclObjC.h include/clang/Basic/DiagnosticKinds.def lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp test/CodeGenObjC/property.m test/SemaObjC/property-impl-misuse.m

Fariborz Jahanian fjahanian at apple.com
Fri Dec 5 14:32:48 PST 2008


Author: fjahanian
Date: Fri Dec  5 16:32:48 2008
New Revision: 60610

URL: http://llvm.org/viewvc/llvm-project?rev=60610&view=rev
Log:
This test checks for duplicate implementation of the same 
property. It also checks for duplicate use of the same ivar
in two different iproperty implementations. It also caught
an error for a test case used in CodeGen :).

Added:
    cfe/trunk/test/SemaObjC/property-impl-misuse.m
Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/CodeGenObjC/property.m

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=60610&r1=60609&r2=60610&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Dec  5 16:32:48 2008
@@ -1005,6 +1005,9 @@
     PropertyImplementations.push_back(property);
   }
 
+  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
+  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
+  
   unsigned getNumPropertyImplementations() const
   { return PropertyImplementations.size(); }
   
@@ -1101,6 +1104,10 @@
   void addPropertyImplementation(ObjCPropertyImplDecl *property) {
     PropertyImplementations.push_back(property);
   } 
+
+  ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId) const;
+  ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
+
   typedef llvm::SmallVector<ObjCPropertyImplDecl*, 8>::const_iterator
   propimpl_iterator;
   propimpl_iterator propimpl_begin() const { 

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Dec  5 16:32:48 2008
@@ -575,6 +575,10 @@
      "type of setter must be void")
 DIAG(warn_conflicting_types, WARNING,
      "conflicting types for %0")
+DIAG(error_property_implemented, ERROR,
+     "property %0 is already implemented")
+DIAG(error_duplicate_ivar_use, ERROR,
+     "synthesized properties %0 and %1 both claim ivar %2")
 
 /// C++ parser diagnostics
 DIAG(err_expected_unqualified_id, ERROR,

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=60610&r1=60609&r2=60610&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Dec  5 16:32:48 2008
@@ -716,6 +716,60 @@
   return NULL;
 }
 
+/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
+/// added to the list of those properties @synthesized/@dynamic in this
+/// @implementation block.
+///
+ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplDecl(IdentifierInfo *Id) const {
+  for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) {
+    ObjCPropertyImplDecl *PID = *i;
+    if (PID->getPropertyDecl()->getIdentifier() == Id)
+      return PID;
+  }
+  return 0;
+}
+
+/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
+/// properties implemented in this @implementation block and returns it if 
+/// found.
+///
+ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
+  for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) {
+    ObjCPropertyImplDecl *PID = *i;
+    if (PID->getPropertyIvarDecl() &&
+        PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
+      return PID;
+  }
+  return 0;
+}
+
+/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
+/// properties implemented in this category @implementation block and returns it if 
+/// found.
+///
+ObjCPropertyImplDecl *ObjCCategoryImplDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
+  for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) {
+    ObjCPropertyImplDecl *PID = *i;
+    if (PID->getPropertyIvarDecl() &&
+        PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
+      return PID;
+  }
+  return 0;
+}
+
+/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
+/// added to the list of those properties @synthesized/@dynamic in this
+/// category @implementation block.
+///
+ObjCPropertyImplDecl *ObjCCategoryImplDecl::FindPropertyImplDecl(IdentifierInfo *Id) const {
+  for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) {
+    ObjCPropertyImplDecl *PID = *i;
+    if (PID->getPropertyDecl()->getIdentifier() == Id)
+      return PID;
+  }
+  return 0;
+}
+
 // lookupInstanceMethod - This method returns an instance method by looking in
 // the class implementation. Unlike interfaces, we don't look outside the
 // implementation.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Dec  5 16:32:48 2008
@@ -1506,10 +1506,41 @@
                                   ObjCPropertyImplDecl::Synthesize 
                                   : ObjCPropertyImplDecl::Dynamic),
                                  Ivar);
-  if (IC)
+  if (IC) {
+    if (Synthesize)
+      if (ObjCPropertyImplDecl *PPIDecl = 
+          IC->FindPropertyImplIvarDecl(PropertyIvar)) {
+        Diag(PropertyLoc, diag::error_duplicate_ivar_use) 
+          << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() 
+          << PropertyIvar;
+        Diag(PPIDecl->getLocation(), diag::note_previous_use);
+      }
+    
+    if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplDecl(PropertyId)) {
+      Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
+      Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
+      return 0;
+    }
     IC->addPropertyImplementation(PIDecl);
-  else
+  }
+  else {
+    if (Synthesize)
+      if (ObjCPropertyImplDecl *PPIDecl = 
+          CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
+        Diag(PropertyLoc, diag::error_duplicate_ivar_use) 
+          << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() 
+          << PropertyIvar;
+        Diag(PPIDecl->getLocation(), diag::note_previous_use);
+      }
+    
+    if (ObjCPropertyImplDecl *PPIDecl = 
+          CatImplClass->FindPropertyImplDecl(PropertyId)) {
+      Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
+      Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
+      return 0;
+    }    
     CatImplClass->addPropertyImplementation(PIDecl);
+  }
     
   return PIDecl;
 }

Modified: cfe/trunk/test/CodeGenObjC/property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/property.m?rev=60610&r1=60609&r2=60610&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/property.m (original)
+++ cfe/trunk/test/CodeGenObjC/property.m Fri Dec  5 16:32:48 2008
@@ -9,6 +9,7 @@
 
 @interface A : Root {
   int x;
+  int y, ro, z;
   id ob0, ob1, ob2, ob3, ob4;
 }
 @property int x;
@@ -24,10 +25,9 @@
 
 @implementation A
 @dynamic x;
- at synthesize x;
- at synthesize y = x;
- at synthesize z = x;
- at synthesize ro = x;
+ at synthesize y;
+ at synthesize z = z;
+ at synthesize ro;
 @synthesize ob0;
 @synthesize ob1;
 @synthesize ob2;

Added: cfe/trunk/test/SemaObjC/property-impl-misuse.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-impl-misuse.m?rev=60610&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/property-impl-misuse.m (added)
+++ cfe/trunk/test/SemaObjC/property-impl-misuse.m Fri Dec  5 16:32:48 2008
@@ -0,0 +1,16 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface I {
+  int Y;
+}
+ at property int X;
+ at property int Y;
+ at property int Z;
+ at end
+
+ at implementation I
+ at dynamic X; // expected-note {{previous declaration is here}}
+ at dynamic X; // expected-error {{property 'X' is already implemented}}
+ at synthesize Y; // expected-note {{previous use is here}}
+ at synthesize Z=Y; // expected-error {{synthesized properties 'Z' and 'Y' both claim ivar 'Y'}}
+ at end





More information about the cfe-commits mailing list