[PATCH] D71588: [objc_direct] fix uniquing when re-declaring a readwrite-direct property

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 17 11:16:09 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4e1819c1683: [objc_direct] fix uniquing when re-declaring a readwrite-direct property (authored by MadCoder, committed by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D71588?vs=234215&id=234346#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71588/new/

https://reviews.llvm.org/D71588

Files:
  clang/lib/AST/DeclObjC.cpp
  clang/test/CodeGenObjC/direct-method.m


Index: clang/test/CodeGenObjC/direct-method.m
===================================================================
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -191,6 +191,14 @@
   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;
Index: clang/lib/AST/DeclObjC.cpp
===================================================================
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -958,10 +958,18 @@
   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(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71588.234346.patch
Type: text/x-patch
Size: 1769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191217/4dfafa8b/attachment.bin>


More information about the cfe-commits mailing list