[cfe-commits] r170039 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/ARCMigrate/TransProperties.cpp lib/Sema/SemaObjCProperty.cpp test/SemaObjC/arc-property-lifetime.m test/SemaObjC/arc-property.m test/SemaObjC/warn-direct-ivar-access.m test/SemaObjC/weak-property.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Dec 12 14:48:25 PST 2012


Author: akirtzidis
Date: Wed Dec 12 16:48:25 2012
New Revision: 170039

URL: http://llvm.org/viewvc/llvm-project?rev=170039&view=rev
Log:
[objc] For the ARC error that is emitted when a synthesized property implementation
has inconsistent ownership with the backing ivar, point the error location to the
ivar.

Pointing to the ivar (instead of the @synthesize) is better since this is where a fix is needed.
Also provide the location of @synthesize via a note.

This also fixes the problem where an auto-synthesized property would emit an error without
any location.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/ARCMigrate/TransProperties.cpp
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/arc-property-lifetime.m
    cfe/trunk/test/SemaObjC/arc-property.m
    cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m
    cfe/trunk/test/SemaObjC/weak-property.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec 12 16:48:25 2012
@@ -684,6 +684,8 @@
   "class implementation">;
 def note_property_declare : Note<
   "property declared here">;
+def note_property_synthesize : Note<
+  "property synthesized here">;
 def error_synthesize_category_decl : Error<
   "@synthesize not allowed in a category's implementation">;
 def error_reference_property : Error<

Modified: cfe/trunk/lib/ARCMigrate/TransProperties.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransProperties.cpp?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransProperties.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransProperties.cpp Wed Dec 12 16:48:25 2012
@@ -226,8 +226,10 @@
 
     for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
       if (I->ImplD)
-        Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
-                                I->ImplD->getLocation());
+        Pass.TA.clearDiagnostic(diag::err_arc_strong_property_ownership,
+                                diag::err_arc_assign_property_ownership,
+                                diag::err_arc_inconsistent_property_ownership,
+                                I->IvarD->getLocation());
     }
   }
 
@@ -253,8 +255,10 @@
         }
       }
       if (I->ImplD)
-        Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
-                                I->ImplD->getLocation());
+        Pass.TA.clearDiagnostic(diag::err_arc_strong_property_ownership,
+                                diag::err_arc_assign_property_ownership,
+                                diag::err_arc_inconsistent_property_ownership,
+                                I->IvarD->getLocation());
     }
   }
 
@@ -276,8 +280,10 @@
                          canUseWeak ? "__weak " : "__unsafe_unretained ");
       }
       if (I->ImplD) {
-        Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
-                                I->ImplD->getLocation());
+        Pass.TA.clearDiagnostic(diag::err_arc_strong_property_ownership,
+                                diag::err_arc_assign_property_ownership,
+                                diag::err_arc_inconsistent_property_ownership,
+                                I->IvarD->getLocation());
         Pass.TA.clearDiagnostic(
                            diag::err_arc_objc_property_default_assign_on_object,
                            I->ImplD->getLocation());

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Dec 12 16:48:25 2012
@@ -577,20 +577,20 @@
 
   switch (propertyLifetime) {
   case Qualifiers::OCL_Strong:
-    S.Diag(propertyImplLoc, diag::err_arc_strong_property_ownership)
+    S.Diag(ivar->getLocation(), diag::err_arc_strong_property_ownership)
       << property->getDeclName()
       << ivar->getDeclName()
       << ivarLifetime;
     break;
 
   case Qualifiers::OCL_Weak:
-    S.Diag(propertyImplLoc, diag::error_weak_property)
+    S.Diag(ivar->getLocation(), diag::error_weak_property)
       << property->getDeclName()
       << ivar->getDeclName();
     break;
 
   case Qualifiers::OCL_ExplicitNone:
-    S.Diag(propertyImplLoc, diag::err_arc_assign_property_ownership)
+    S.Diag(ivar->getLocation(), diag::err_arc_assign_property_ownership)
       << property->getDeclName()
       << ivar->getDeclName()
       << ((property->getPropertyAttributesAsWritten() 
@@ -606,6 +606,8 @@
   }
 
   S.Diag(property->getLocation(), diag::note_property_declare);
+  if (propertyImplLoc.isValid())
+    S.Diag(propertyImplLoc, diag::note_property_synthesize);
 }
 
 /// setImpliedPropertyAttributeForReadOnlyProperty -

Modified: cfe/trunk/test/SemaObjC/arc-property-lifetime.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-property-lifetime.m?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-property-lifetime.m (original)
+++ cfe/trunk/test/SemaObjC/arc-property-lifetime.m Wed Dec 12 16:48:25 2012
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-default-synthesize-properties -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
 // rdar://9340606
 
 @interface Foo {
 @public
-    id __unsafe_unretained x;
-    id __weak y;
+    id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
+    id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
     id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
 }
 @property(strong) id x; // expected-note {{property declared here}}
@@ -13,15 +13,15 @@
 @end
 
 @implementation Foo
- at synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
- at synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
+ at synthesize x; // expected-note {{property synthesized here}}
+ at synthesize y; // expected-note {{property synthesized here}}
 @synthesize z; // suppressed
 @end
 
 @interface Bar {
 @public
-    id __unsafe_unretained x;
-    id __weak y;
+    id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
+    id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
     id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
 }
 @property(retain) id x; // expected-note {{property declared here}}
@@ -30,15 +30,15 @@
 @end
 
 @implementation Bar
- at synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
- at synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
+ at synthesize x; // expected-note {{property synthesized here}}
+ at synthesize y; // expected-note {{property synthesized here}}
 @synthesize z; // suppressed
 @end
 
 @interface Bas {
 @public
-    id __unsafe_unretained x;
-    id __weak y;
+    id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
+    id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
     id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
 }
 @property(copy) id x; // expected-note {{property declared here}}
@@ -47,8 +47,8 @@
 @end
 
 @implementation Bas
- at synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
- at synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
+ at synthesize x; // expected-note {{property synthesized here}}
+ at synthesize y; // expected-note {{property synthesized here}}
 @synthesize z; // suppressed
 @end
 
@@ -70,7 +70,7 @@
 // rdar://9341593
 @interface Gorf  {
    id __unsafe_unretained x;
-   id y;
+   id y; // expected-error {{existing instance variable 'y' for property 'y' with  assign attribute must be __unsafe_unretained}}
 }
 @property(assign) id __unsafe_unretained x;
 @property(assign) id y; // expected-note {{property declared here}}
@@ -79,13 +79,13 @@
 
 @implementation Gorf
 @synthesize x;
- at synthesize y; // expected-error {{existing instance variable 'y' for property 'y' with  assign attribute must be __unsafe_unretained}}
+ at synthesize y; // expected-note {{property synthesized here}}
 @synthesize z;
 @end
 
 @interface Gorf2  {
    id __unsafe_unretained x;
-   id y;
+   id y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}}
 }
 @property(unsafe_unretained) id __unsafe_unretained x;
 @property(unsafe_unretained) id y; // expected-note {{property declared here}}
@@ -94,7 +94,7 @@
 
 @implementation Gorf2
 @synthesize x;
- at synthesize y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}}
+ at synthesize y; // expected-note {{property synthesized here}}
 @synthesize z;
 @end
 
@@ -173,3 +173,12 @@
 @interface Boom 
 @property (readonly) const void * innerPointer __attribute__((objc_returns_inner_pointer)); // expected-error {{'objc_returns_inner_pointer' attribute only applies to methods}}
 @end
+
+ at interface Foo2 {
+  id _prop; // expected-error {{existing instance variable '_prop' for property 'prop' with  assign attribute must be __unsafe_unretained}}
+}
+ at property (nonatomic, assign) id prop; // expected-note {{property declared here}}
+ at end
+
+ at implementation Foo2
+ at end

Modified: cfe/trunk/test/SemaObjC/arc-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-property.m?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-property.m (original)
+++ cfe/trunk/test/SemaObjC/arc-property.m Wed Dec 12 16:48:25 2012
@@ -2,11 +2,11 @@
 // rdar://9309489
 
 @interface MyClass {
-        id __weak myString;
+        id __weak myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}}
         id StrongIvar;
-        id __weak myString2;
+        id __weak myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}}
         id __weak myString3;
-        id StrongIvar5;
+        id StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}}
 }
 @property (strong) id myString; // expected-note {{property declared here}}
 @property (strong) id myString1;
@@ -18,21 +18,21 @@
 @end
 
 @implementation MyClass
- at synthesize myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}}
+ at synthesize myString; // expected-note {{property synthesized here}}
 @synthesize myString1 = StrongIvar; // OK
- at synthesize myString2 = myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}}
+ at synthesize myString2 = myString2; // expected-note {{property synthesized here}}
 //
 @synthesize myString3; // OK
 @synthesize myString4; // OK
- at synthesize myString5 = StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}}
+ at synthesize myString5 = StrongIvar5; // expected-note {{property synthesized here}}
 
 @end
 
 // rdar://9340692
 @interface Foo {
 @public
-    id __unsafe_unretained x;   // should be __weak
-    id __strong y;
+    id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
+    id __strong y;  // expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}}
     id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
 }
 @property(weak) id x; // expected-note {{property declared here}}
@@ -41,8 +41,8 @@
 @end
 
 @implementation Foo
- at synthesize x;	// expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
- at synthesize y;	// expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}}
+ at synthesize x; // expected-note {{property synthesized here}}
+ at synthesize y; // expected-note {{property synthesized here}}
 @synthesize z;  // suppressed
 @end
 

Modified: cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m (original)
+++ cfe/trunk/test/SemaObjC/warn-direct-ivar-access.m Wed Dec 12 16:48:25 2012
@@ -4,7 +4,7 @@
 __attribute__((objc_root_class)) @interface MyObject {
 @public
     id _myMaster;
-    id _isTickledPink;
+    id _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}}
     int _myIntProp;
 }
 @property(retain) id myMaster;
@@ -15,7 +15,7 @@
 @implementation MyObject
 
 @synthesize myMaster = _myMaster;
- at synthesize isTickledPink = _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}}
+ at synthesize isTickledPink = _isTickledPink; // expected-note {{property synthesized here}}
 @synthesize myIntProp = _myIntProp;
 
 - (void) doSomething {

Modified: cfe/trunk/test/SemaObjC/weak-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/weak-property.m?rev=170039&r1=170038&r2=170039&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/weak-property.m (original)
+++ cfe/trunk/test/SemaObjC/weak-property.m Wed Dec 12 16:48:25 2012
@@ -4,7 +4,7 @@
 @interface WeakPropertyTest {
     Class isa;
     __weak id value;
-    id x;
+    id x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
 }
 @property (weak) id value1;
 @property __weak id value;
@@ -19,6 +19,6 @@
 @end
 
 @implementation WeakPropertyTest
- at synthesize x;	// expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
+ at synthesize x; // expected-note {{property synthesized here}}
 @dynamic value1, value, value2, v1,v2,v3,v4;
 @end





More information about the cfe-commits mailing list