public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] Objective-C, Darwin : Compute super refs directly.
@ 2020-10-10 16:34 Iain Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain Sandoe @ 2020-10-10 16:34 UTC (permalink / raw)
  To: GCC Patches

Hi,

The current code assumed that super refs could be computed
indirectly, i.e. that the metadata generated by the compiler
was immutable by the runtime. This does not always hold
(it depends on the NeXT runtime version).  So, compute super
refs directly.

tested across the Darwin supported range, and on x86_64-linux
pushed to master,
thanks
Iain

gcc/objc/ChangeLog:

	* objc-next-runtime-abi-02.c
	(objc_get_superclass_ref_decl): Split this code out.
	(next_runtime_abi_02_get_class_super_ref): Compute
	super refs using the objc_get_superclass_ref_decl().
	(next_runtime_abi_02_get_category_super_ref): Likewise.
---
 gcc/objc/objc-next-runtime-abi-02.c | 76 ++++++++++++++---------------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index 6d1badc5f36..57604255065 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -1439,13 +1439,12 @@ build_v2_superclass_ref_decl (tree ident, bool inst)
 static GTY (()) vec<ident_data_tuple, va_gc> *class_super_refs;
 static GTY (()) vec<ident_data_tuple, va_gc> *metaclass_super_refs;
 
+/* Find or build a superclass reference decl for class NAME.  */
+
 static tree
-next_runtime_abi_02_get_class_super_ref (location_t loc ATTRIBUTE_UNUSED,
-					 struct imp_entry *imp, bool inst_meth)
+objc_get_superclass_ref_decl (tree name, bool inst_meth)
 {
   tree decl;
-  ident_data_tuple e;
-  tree id = CLASS_NAME (imp->imp_context);
   vec<ident_data_tuple, va_gc> *list = inst_meth  ? class_super_refs
 						: metaclass_super_refs;
 
@@ -1455,10 +1454,10 @@ next_runtime_abi_02_get_class_super_ref (location_t loc ATTRIBUTE_UNUSED,
       ident_data_tuple *ref;
       FOR_EACH_VEC_ELT (*list, count, ref)
 	{
-	  if (ref->ident == id)
+	  if (ref->ident == name)
 	    {
 	      if (!ref->data)
-		ref->data = build_v2_superclass_ref_decl (id, inst_meth);
+		ref->data = build_v2_superclass_ref_decl (name, inst_meth);
 	      return ref->data;
 	    }
 	}
@@ -1479,48 +1478,49 @@ next_runtime_abi_02_get_class_super_ref (location_t loc ATTRIBUTE_UNUSED,
     }
   /* We come here if we don't find the entry - or if the table was yet
      to be created.  */
-  decl = build_v2_superclass_ref_decl (id, inst_meth);
-  e.ident = id;
+  decl = build_v2_superclass_ref_decl (name, inst_meth);
+  ident_data_tuple e;
+  e.ident = name;
   e.data = decl;
   vec_safe_push (list, e);
   return decl;
 }
 
+/* Get a reference to the superclass for IMP.  */
+
 static tree
-next_runtime_abi_02_get_category_super_ref (location_t loc ATTRIBUTE_UNUSED,
-					   struct imp_entry *imp, bool inst_meth)
+next_runtime_abi_02_get_class_super_ref (location_t loc ATTRIBUTE_UNUSED,
+					 struct imp_entry *imp, bool inst_meth)
 {
-  /* ??? is this OK when zero-link = true?  */
-  tree super_name = CLASS_SUPER_NAME (imp->imp_template);
-  tree super_class;
+  tree name = CLASS_NAME (imp->imp_context);
+  return objc_get_superclass_ref_decl (name, inst_meth);
+}
 
-  if (!flag_zero_link)
+/* Get a reference to the superclass for category IMP.  */
+
+static tree
+next_runtime_abi_02_get_category_super_ref (location_t loc ATTRIBUTE_UNUSED,
+					    struct imp_entry *imp,
+					    bool inst_meth)
+{
+  if (flag_zero_link)
     {
-      super_class = objc_get_class_reference (CLASS_NAME (imp->imp_template));
-
-      if (!inst_meth)
-
-	/* If we are in a class method, we must retrieve the
-	   _metaclass_ for the current class, pointed at by the
-	   class's "isa" pointer.  The following assumes that "isa" is
-	   the first ivar in a class (which it must be).  */
-	   super_class =
-		build_indirect_ref (input_location,
-				    build_c_cast (input_location,
-					build_pointer_type (objc_class_type),
-					super_class),
-				    RO_UNARY_STAR);
-      return super_class;
+      /* Do it the slow way.  */
+      tree get_cl_fn = inst_meth ? objc_get_class_decl
+				 : objc_get_meta_class_decl;
+      tree super_name = CLASS_SUPER_NAME (imp->imp_template);
+      super_name = my_build_string_pointer (IDENTIFIER_LENGTH (super_name) + 1,
+					    IDENTIFIER_POINTER (super_name));
+      /* super_class = objc_get{Meta}Class("CLASS_SUPER_NAME"); */
+      return build_function_call (input_location, get_cl_fn,
+				  build_tree_list (NULL_TREE, super_name));
     }
-  /* ??? Do we need to add the class ref anway for zero-link?  */
-  /* else do it the slow way.  */
-  super_class = (inst_meth ? objc_get_class_decl : objc_get_meta_class_decl);
-  super_name = my_build_string_pointer (IDENTIFIER_LENGTH (super_name) + 1,
-					IDENTIFIER_POINTER (super_name));
-  /* super_class = objc_get{Meta}Class("CLASS_SUPER_NAME"); */
-  return build_function_call (input_location,
-			      super_class,
-			      build_tree_list (NULL_TREE, super_name));
+
+  /* This is the 'usual' path.  */
+  tree cls_name = CLASS_NAME (imp->imp_template);
+  if (!inst_meth)
+    return objc_get_superclass_ref_decl (cls_name, inst_meth);
+  return objc_get_class_reference (cls_name);
 }
 
 static tree
-- 
2.24.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-10 16:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10 16:34 [pushed] Objective-C, Darwin : Compute super refs directly Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).