diff options
author | Pierre Habouzit <phabouzit@apple.com> | 2019-12-17 11:06:17 -0800 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2019-12-17 11:07:48 -0800 |
commit | a4e1819c16836dba928e646024a2406bb2eb3f94 (patch) | |
tree | 6580539c4eac5e07801e76c66a837799e43c0c7d | |
parent | 0412f518dcb05216d2321c28366eb760b65baebc (diff) | |
download | bcm5719-llvm-a4e1819c16836dba928e646024a2406bb2eb3f94.tar.gz bcm5719-llvm-a4e1819c16836dba928e646024a2406bb2eb3f94.zip |
[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
-rw-r--r-- | clang/lib/AST/DeclObjC.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/direct-method.m | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index fed76aecdaa..ca70afd9db2 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -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(), diff --git a/clang/test/CodeGenObjC/direct-method.m b/clang/test/CodeGenObjC/direct-method.m index 373bd22a84c..c42910c1676 100644 --- a/clang/test/CodeGenObjC/direct-method.m +++ b/clang/test/CodeGenObjC/direct-method.m @@ -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; |