r226338 - ObjC getters with names like "newItem" should still be linked to the @property.

Jordan Rose jordan_rose at apple.com
Fri Jan 16 15:04:26 PST 2015


Author: jrose
Date: Fri Jan 16 17:04:26 2015
New Revision: 226338

URL: http://llvm.org/viewvc/llvm-project?rev=226338&view=rev
Log:
ObjC getters with names like "newItem" should still be linked to the @property.

Two years ago I added a compile-time "optimization" to
ObjCMethodDecl::findPropertyDecl: exit early if the current method is part
of a special Objective-C method family (like 'new' or 'init'). However, if a
property (declared with @property) has a name that matches a method family,
the getter picks up that family despite being declared by the property. The
early exit then made ObjCMethodDecl::findPropertyDecl decide that there
was no associated property, despite the method itself being marked as an
accessor. This corrects that by removing the early exit.

This does /not/ change the fact that such a getter is considered to return a
value with a +1 retain count. The best way to eliminate this is by adding the
objc_method_family(none) attribute to the getter, but unlike the existing
ns_returns_not_retained that can't be applied directly to the property -- you
have to redeclare the getter instead.

(It'd be nice if @property just implied objc_method_family(none) for its
getter, but that would be a backwards-incompatible change.)

rdar://problem/19038838

Modified:
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m
    cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=226338&r1=226337&r2=226338&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Jan 16 17:04:26 2015
@@ -1101,7 +1101,7 @@ ObjCMethodDecl::findPropertyDecl(bool Ch
   if (NumArgs > 1)
     return nullptr;
 
-  if (!isInstanceMethod() || getMethodFamily() != OMF_None)
+  if (!isInstanceMethod())
     return nullptr;
 
   if (isPropertyAccessor()) {

Modified: cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m?rev=226338&r1=226337&r2=226338&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m Fri Jan 16 17:04:26 2015
@@ -59,3 +59,12 @@ P* fun();
          [self->obj count];
 }
 @end
+
+
+ at interface Rdar19038838
+ at property id newItem; // should be marked objc_method_family(none), but isn't.
+ at end
+
+id testRdar19038838(Rdar19038838 *obj) {
+  return [obj newItem];
+}

Modified: cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result?rev=226338&r1=226337&r2=226338&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property-dot-syntax.m.result Fri Jan 16 17:04:26 2015
@@ -59,3 +59,12 @@ P* fun();
          self->obj.count;
 }
 @end
+
+
+ at interface Rdar19038838
+ at property id newItem; // should be marked objc_method_family(none), but isn't.
+ at end
+
+id testRdar19038838(Rdar19038838 *obj) {
+  return obj.newItem;
+}





More information about the cfe-commits mailing list