From: Jordan Rose Date: Fri, 16 Jan 2015 23:04:26 +0000 (+0000) Subject: ObjC getters with names like "newItem" should still be linked to the @property. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f7e4c8e18953516e772ceee748f66ed7b2cb096;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226338 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index ed5367514c..91b7ed6964 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -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()) { diff --git a/test/ARCMT/objcmt-property-dot-syntax.m b/test/ARCMT/objcmt-property-dot-syntax.m index 0e25abcb89..aaa3ea1981 100644 --- a/test/ARCMT/objcmt-property-dot-syntax.m +++ b/test/ARCMT/objcmt-property-dot-syntax.m @@ -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]; +} diff --git a/test/ARCMT/objcmt-property-dot-syntax.m.result b/test/ARCMT/objcmt-property-dot-syntax.m.result index 6822d44ac0..44b7cf1075 100644 --- a/test/ARCMT/objcmt-property-dot-syntax.m.result +++ b/test/ARCMT/objcmt-property-dot-syntax.m.result @@ -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; +}