Skip to content

Commit 48c9109

Browse files
committed
[objc_direct] fix uniquing when re-declaring a readwrite-direct property
ObjCMethodDecl::getCanonicalDecl() for re-declared readwrite properties, only looks in the ObjCInterface for the declaration of the setter method, which it won't find. When the method is a property accessor, we must look in extensions for a possible redeclaration. Radar-Id: rdar://problem/57991337 Differential Revision: https://reviews.llvm.org/D71588
1 parent 2263ce7 commit 48c9109

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/AST/DeclObjC.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,18 @@ ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
958958
auto *CtxD = cast<Decl>(getDeclContext());
959959

960960
if (auto *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
961-
if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
961+
if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) {
962962
if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
963963
isInstanceMethod()))
964964
return MD;
965+
// readwrite properties may have been re-declared in an extension.
966+
// look harder.
967+
if (isPropertyAccessor())
968+
for (auto *Ext : IFD->known_extensions())
969+
if (ObjCMethodDecl *MD =
970+
Ext->getMethod(getSelector(), isInstanceMethod()))
971+
return MD;
972+
}
965973
} else if (auto *CImplD = dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
966974
if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
967975
if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),

clang/test/CodeGenObjC/direct-method.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ int useRoot(Root *r) {
191191
return [r getInt] + [r intProperty] + [r intProperty2];
192192
}
193193

194+
int useFoo(Foo *f) {
195+
// CHECK-LABEL: define i32 @useFoo
196+
// CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]"
197+
// CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]"
198+
[f setGetDynamic_setDirect:1];
199+
return [f getDirect_setDynamic];
200+
}
201+
194202
__attribute__((objc_root_class))
195203
@interface RootDeclOnly
196204
@property(direct, readonly) int intProperty;

0 commit comments

Comments
 (0)