From: Iain Sandoe Date: Tue, 6 Oct 2020 17:47:26 +0000 (+0100) Subject: Objective-C, Darwin : Pick up super refs directly. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c28d91bf23ad5767265a1298be6fef0caa0a85f0;p=gcc.git Objective-C, Darwin : Pick up super refs directly. 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. 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. --- 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 *class_super_refs; static GTY (()) vec *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 *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