]> granicus.if.org Git - clang/commitdiff
ObjC getters with names like "newItem" should still be linked to the @property.
authorJordan Rose <jordan_rose@apple.com>
Fri, 16 Jan 2015 23:04:26 +0000 (23:04 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 16 Jan 2015 23:04:26 +0000 (23:04 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226338 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclObjC.cpp
test/ARCMT/objcmt-property-dot-syntax.m
test/ARCMT/objcmt-property-dot-syntax.m.result

index ed5367514c300135c365daebe0a0e9456402aad0..91b7ed6964901d9212a3649a38e970ecfa1a8b2e 100644 (file)
@@ -1101,7 +1101,7 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
   if (NumArgs > 1)
     return nullptr;
 
-  if (!isInstanceMethod() || getMethodFamily() != OMF_None)
+  if (!isInstanceMethod())
     return nullptr;
 
   if (isPropertyAccessor()) {
index 0e25abcb89ecc4380ffb91487abac3e72cd77d71..aaa3ea19818370dd0818b21c7095a9b636eed6c4 100644 (file)
@@ -59,3 +59,12 @@ P* fun();
          [self->obj count];
 }
 @end
+
+
+@interface Rdar19038838
+@property id newItem; // should be marked objc_method_family(none), but isn't.
+@end
+
+id testRdar19038838(Rdar19038838 *obj) {
+  return [obj newItem];
+}
index 6822d44ac0a542c0b86ac2f4c8b18cbb52167c90..44b7cf107592bf03a1d231810cce371f9e790a9a 100644 (file)
@@ -59,3 +59,12 @@ P* fun();
          self->obj.count;
 }
 @end
+
+
+@interface Rdar19038838
+@property id newItem; // should be marked objc_method_family(none), but isn't.
+@end
+
+id testRdar19038838(Rdar19038838 *obj) {
+  return obj.newItem;
+}