Skip to content

[objc_direct] fix uniquing when re-declaring a readwrite-direct property #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion clang/lib/AST/DeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,10 +958,18 @@ ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
auto *CtxD = cast<Decl>(getDeclContext());

if (auto *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) {
if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
isInstanceMethod()))
return MD;
// readwrite properties may have been re-declared in an extension.
// look harder.
if (isPropertyAccessor())
for (auto *Ext : IFD->known_extensions())
if (ObjCMethodDecl *MD =
Ext->getMethod(getSelector(), isInstanceMethod()))
return MD;
}
} else if (auto *CImplD = dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CodeGenObjC/direct-method.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ int useRoot(Root *r) {
return [r getInt] + [r intProperty] + [r intProperty2];
}

int useFoo(Foo *f) {
// CHECK-LABEL: define i32 @useFoo
// CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]"
// CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]"
[f setGetDynamic_setDirect:1];
return [f getDirect_setDynamic];
}

__attribute__((objc_root_class))
@interface RootDeclOnly
@property(direct, readonly) int intProperty;
Expand Down