[cfe-commits] r68976 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/ivar-sem-check-2.m

Fariborz Jahanian fjahanian at apple.com
Mon Apr 13 12:30:37 PDT 2009


Author: fjahanian
Date: Mon Apr 13 14:30:37 2009
New Revision: 68976

URL: http://llvm.org/viewvc/llvm-project?rev=68976&view=rev
Log:
In objc2's None-Fragile ABI, one cannot use the super class ivar for
setter/getter synthesis.

Added:
    cfe/trunk/test/SemaObjC/ivar-sem-check-2.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 13 14:30:37 2009
@@ -212,6 +212,8 @@
 
 def error_property_ivar_type : Error<
   "type of property %0 does not match type of ivar %1">;
+def error_ivar_in_superclass_use : Error<
+  "property %0 attempting to use ivar %1 declared in in super class %2">;
 def error_weak_property : Error<
   "existing ivar %1 for __weak property %0 must be __weak">;
 def error_strong_property : Error<

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 13 14:30:37 2009
@@ -1791,11 +1791,13 @@
   // Check that we have a valid, previously declared ivar for @synthesize
   if (Synthesize) {
     // @synthesize
+    bool NoExplicitPropertyIvar = (!PropertyIvar);
     if (!PropertyIvar)
       PropertyIvar = PropertyId;
     QualType PropType = Context.getCanonicalType(property->getType());
     // Check that this is a previously declared 'ivar' in 'IDecl' interface
-    Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar);
+    ObjCInterfaceDecl *ClassDeclared;
+    Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar, ClassDeclared);
     if (!Ivar) {
       if (getLangOptions().ObjCNonFragileABI) {
         Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc, 
@@ -1809,6 +1811,15 @@
         return DeclPtrTy();
       }
     }
+    else if (getLangOptions().ObjCNonFragileABI &&
+             NoExplicitPropertyIvar && ClassDeclared != IDecl) {
+      Diag(PropertyLoc, diag::error_ivar_in_superclass_use)
+        << property->getDeclName() << Ivar->getDeclName() 
+        << ClassDeclared->getDeclName();
+      Diag(Ivar->getLocation(), diag::note_previous_access_declaration)
+        << Ivar << Ivar->getNameAsCString();
+      // Note! I deliberately want it to fall thru so more errors are caught.
+    }
     QualType IvarType = Context.getCanonicalType(Ivar->getType());
     
     // Check that type of property and its ivar are type compatible.

Added: cfe/trunk/test/SemaObjC/ivar-sem-check-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-sem-check-2.m?rev=68976&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-sem-check-2.m (added)
+++ cfe/trunk/test/SemaObjC/ivar-sem-check-2.m Mon Apr 13 14:30:37 2009
@@ -0,0 +1,17 @@
+// RUN: clang-cc  -fsyntax-only -triple x86_64-apple-darwin10 -verify %s
+
+ at interface Super  {
+  id value; // expected-note {{previously declared 'value' here}}
+} 
+ at property(retain) id value;
+ at property(retain) id value1;
+ at end
+
+ at interface Sub : Super @end
+
+ at implementation Sub
+ at synthesize value; // expected-error {{property 'value' attempting to use ivar 'value' declared in in super class 'Super'}} // expected-note {{previous use is here}}
+ at synthesize value1=value; // expected-error {{synthesized properties 'value1' and 'value' both claim ivar 'value'}}
+ at end
+
+





More information about the cfe-commits mailing list