From 87e3d7cfb5c5c9cf265e5ee803cce904f2a5a123 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 5 Oct 2017 12:10:55 +0000 Subject: [PATCH] [C++ PATCH] Kill IDENTIFIER_GLOBAL_VALUE https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00239.html Kill IDENTIFIER_GLOBAL_VALUE, SET_IDENTIFIER_GLOBAL_VALUE * cp-tree.h (IDENTIFIER_GLOBAL_VALUE, SET_IDENTIFIER_GLOBAL_VALUE): Delete. * name-lookup.h (set_global_binding): Remove NAME parm. (get_global_binding): New inline fn. * name-lookup.c (set_global_binding): Remove NAME parm. Adjust. (identifier_global_value): Move to ... * cp-objcp-common.c (identifier_global_value): ... here. * class.c (build_ctor_vtbl_group, build_vtbl_initializer): Adjust. * decl.c (record_builtin_type, expand_static_init, grokdeclarator): Adjust. * decl2.c (get_guard, get_local_tls_init_fn, get_tls_init_fn, get_tls_wrapper_fn, maybe_warn_sized_delete): Adjust. * except.c (declare_library_fn, build_throw): Adjust. * init.c (throw_bad_array_length): Adjust. * rtti.c (throw_bad_cast, throw_bad_typeid, get_tinfo_decl): Adjust. From-SVN: r253444 --- gcc/cp/ChangeLog | 17 +++++++++++++++++ gcc/cp/class.c | 4 ++-- gcc/cp/cp-objcp-common.c | 9 +++++++++ gcc/cp/cp-tree.h | 5 ----- gcc/cp/decl.c | 16 ++++++++-------- gcc/cp/decl2.c | 16 ++++++++-------- gcc/cp/except.c | 10 +++++----- gcc/cp/init.c | 2 +- gcc/cp/name-lookup.c | 32 +++++++++++--------------------- gcc/cp/name-lookup.h | 9 +++++---- gcc/cp/rtti.c | 8 ++++---- 11 files changed, 70 insertions(+), 58 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fcef8ef..7577846 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,22 @@ 2017-10-05 Nathan Sidwell + Kill IDENTIFIER_GLOBAL_VALUE, SET_IDENTIFIER_GLOBAL_VALUE + * cp-tree.h (IDENTIFIER_GLOBAL_VALUE, + SET_IDENTIFIER_GLOBAL_VALUE): Delete. + * name-lookup.h (set_global_binding): Remove NAME parm. + (get_global_binding): New inline fn. + * name-lookup.c (set_global_binding): Remove NAME parm. Adjust. + (identifier_global_value): Move to ... + * cp-objcp-common.c (identifier_global_value): ... here. + * class.c (build_ctor_vtbl_group, build_vtbl_initializer): Adjust. + * decl.c (record_builtin_type, expand_static_init, + grokdeclarator): Adjust. + * decl2.c (get_guard, get_local_tls_init_fn, get_tls_init_fn, + get_tls_wrapper_fn, maybe_warn_sized_delete): Adjust. + * except.c (declare_library_fn, build_throw): Adjust. + * init.c (throw_bad_array_length): Adjust. + * rtti.c (throw_bad_cast, throw_bad_typeid, get_tinfo_decl): Adjust. + * decl2.c (record_mangling): Fix spello and formatting from previous patch. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 0c4a7b3..a90b85f 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -8912,7 +8912,7 @@ build_ctor_vtbl_group (tree binfo, tree t) /* See if we've already created this construction vtable group. */ id = mangle_ctor_vtbl_for_type (t, binfo); - if (IDENTIFIER_GLOBAL_VALUE (id)) + if (get_global_binding (id)) return; gcc_assert (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)); @@ -9294,7 +9294,7 @@ build_vtbl_initializer (tree binfo, if (!dvirt_fn) { tree name = get_identifier ("__cxa_deleted_virtual"); - dvirt_fn = IDENTIFIER_GLOBAL_VALUE (name); + dvirt_fn = get_global_binding (name); if (!dvirt_fn) dvirt_fn = push_library_fn (name, diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index 267fcca..f251b05 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -400,6 +400,15 @@ cp_pushdecl (tree decl) return pushdecl (decl); } +/* Get the global value binding of NAME. Called directly from + c-common.c, not via a hook. */ + +tree +identifier_global_value (tree name) +{ + return get_global_binding (name); +} + /* Register c++-specific dumps. */ void diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 82ebc28..5f9874b 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -613,11 +613,6 @@ struct GTY(()) ptrmem_cst { }; typedef struct ptrmem_cst * ptrmem_cst_t; -#define IDENTIFIER_GLOBAL_VALUE(NODE) \ - get_namespace_binding (NULL_TREE, (NODE)) -#define SET_IDENTIFIER_GLOBAL_VALUE(NODE, VAL) \ - set_global_binding ((NODE), (VAL)) - #define CLEANUP_P(NODE) TREE_LANG_FLAG_0 (TRY_BLOCK_CHECK (NODE)) #define BIND_EXPR_TRY_BLOCK(NODE) \ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 99f0af2..2b4ed01 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3897,7 +3897,7 @@ make_unbound_class_template (tree context, tree name, tree parm_list, RID_POINTERS. NAME is the name used when looking up the builtin type. TYPE is the _TYPE node for the builtin type. - The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be + The calls to set_global_binding below should be eliminated. Built-in types should not be looked up name; their names are keywords that the parser can recognize. However, there is code in c-common.c that uses identifier_global_value to look up @@ -3915,7 +3915,7 @@ record_builtin_type (enum rid rid_index, tree tname = get_identifier (name); tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type); DECL_ARTIFICIAL (tdecl) = 1; - SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl); + set_global_binding (tdecl); decl = tdecl; } @@ -3925,7 +3925,7 @@ record_builtin_type (enum rid rid_index, { tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type); DECL_ARTIFICIAL (rdecl) = 1; - SET_IDENTIFIER_GLOBAL_VALUE (rname, rdecl); + set_global_binding (rdecl); if (!decl) decl = rdecl; } @@ -4509,7 +4509,7 @@ build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags) } /* Like build_library_fn, but also pushes the function so that we will - be able to find it via IDENTIFIER_GLOBAL_VALUE. Also, the function + be able to find it via get_global_binding. Also, the function may throw exceptions listed in RAISES. */ tree @@ -8055,9 +8055,9 @@ expand_static_init (tree decl, tree init) acquire_name = get_identifier ("__cxa_guard_acquire"); release_name = get_identifier ("__cxa_guard_release"); abort_name = get_identifier ("__cxa_guard_abort"); - acquire_fn = identifier_global_value (acquire_name); - release_fn = identifier_global_value (release_name); - abort_fn = identifier_global_value (abort_name); + acquire_fn = get_global_binding (acquire_name); + release_fn = get_global_binding (release_name); + abort_fn = get_global_binding (abort_name); if (!acquire_fn) acquire_fn = push_library_fn (acquire_name, build_function_type_list (integer_type_node, @@ -10126,7 +10126,7 @@ grokdeclarator (const cp_declarator *declarator, gcc_assert (flags == NO_SPECIAL); flags = TYPENAME_FLAG; sfk = sfk_conversion; - tree glob = IDENTIFIER_GLOBAL_VALUE (dname); + tree glob = get_global_binding (dname); if (glob && TREE_CODE (glob) == TYPE_DECL) name = identifier_to_locale (IDENTIFIER_POINTER (dname)); else diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 3aa2db5..ee4c800 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2985,7 +2985,7 @@ get_guard (tree decl) tree guard; sname = mangle_guard_variable (decl); - guard = IDENTIFIER_GLOBAL_VALUE (sname); + guard = get_global_binding (sname); if (! guard) { tree guard_type; @@ -3153,7 +3153,7 @@ static tree get_local_tls_init_fn (void) { tree sname = get_identifier ("__tls_init"); - tree fn = IDENTIFIER_GLOBAL_VALUE (sname); + tree fn = get_global_binding (sname); if (!fn) { fn = build_lang_decl (FUNCTION_DECL, sname, @@ -3163,7 +3163,7 @@ get_local_tls_init_fn (void) TREE_PUBLIC (fn) = false; DECL_ARTIFICIAL (fn) = true; mark_used (fn); - SET_IDENTIFIER_GLOBAL_VALUE (sname, fn); + set_global_binding (fn); } return fn; } @@ -3191,7 +3191,7 @@ get_tls_init_fn (tree var) return get_local_tls_init_fn (); tree sname = mangle_tls_init_fn (var); - tree fn = IDENTIFIER_GLOBAL_VALUE (sname); + tree fn = get_global_binding (sname); if (!fn) { fn = build_lang_decl (FUNCTION_DECL, sname, @@ -3225,7 +3225,7 @@ get_tls_init_fn (tree var) DECL_BEFRIENDING_CLASSES (fn) = var; - SET_IDENTIFIER_GLOBAL_VALUE (sname, fn); + set_global_binding (fn); } return fn; } @@ -3243,7 +3243,7 @@ get_tls_wrapper_fn (tree var) return NULL_TREE; tree sname = mangle_tls_wrapper_fn (var); - tree fn = IDENTIFIER_GLOBAL_VALUE (sname); + tree fn = get_global_binding (sname); if (!fn) { /* A named rvalue reference is an lvalue, so the wrapper should @@ -3282,7 +3282,7 @@ get_tls_wrapper_fn (tree var) DECL_BEFRIENDING_CLASSES (fn) = var; - SET_IDENTIFIER_GLOBAL_VALUE (sname, fn); + set_global_binding (fn); } return fn; } @@ -4427,7 +4427,7 @@ maybe_warn_sized_delete (enum tree_code code) tree sized = NULL_TREE; tree unsized = NULL_TREE; - for (ovl_iterator iter (IDENTIFIER_GLOBAL_VALUE (cp_operator_id (code))); + for (ovl_iterator iter (get_global_binding (cp_operator_id (code))); iter; ++iter) { tree fn = *iter; diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 2ee7e97..ecc8941 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -147,7 +147,7 @@ declare_library_fn (const char *name, tree rtype, tree ptype, int ecf, int tm_ecf) { tree ident = get_identifier (name); - tree res = IDENTIFIER_GLOBAL_VALUE (ident); + tree res = get_global_binding (ident); if (!res) { tree type = build_function_type_list (rtype, ptype, NULL_TREE); @@ -158,7 +158,7 @@ declare_library_fn (const char *name, tree rtype, tree ptype, char *tm_name = concat ("_ITM_", name + 2, NULL_TREE); tree tm_ident = get_identifier (tm_name); free (tm_name); - tree tm_fn = IDENTIFIER_GLOBAL_VALUE (tm_ident); + tree tm_fn = get_global_binding (tm_ident); if (!tm_fn) tm_fn = push_library_fn (tm_ident, type, except, ecf | tm_ecf); record_tm_replacement (res, tm_fn); @@ -609,7 +609,7 @@ build_throw (tree exp) if (!throw_fn) { tree name = get_identifier ("__cxa_throw"); - throw_fn = IDENTIFIER_GLOBAL_VALUE (name); + throw_fn = get_global_binding (name); if (!throw_fn) { /* Declare void __cxa_throw (void*, void*, void (*)(void*)). */ @@ -622,7 +622,7 @@ build_throw (tree exp) if (flag_tm) { tree itm_name = get_identifier ("_ITM_cxa_throw"); - tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name); + tree itm_fn = get_global_binding (itm_name); if (!itm_fn) itm_fn = push_throw_library_fn (itm_name, tmp); apply_tm_attr (itm_fn, get_identifier ("transaction_pure")); @@ -764,7 +764,7 @@ build_throw (tree exp) if (!rethrow_fn) { tree name = get_identifier ("__cxa_rethrow"); - rethrow_fn = IDENTIFIER_GLOBAL_VALUE (name); + rethrow_fn = get_global_binding (name); if (!rethrow_fn) /* Declare void __cxa_rethrow (void). */ rethrow_fn = push_throw_library_fn diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4bc0755..ad30f24 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2446,7 +2446,7 @@ throw_bad_array_new_length (void) { tree name = get_identifier ("__cxa_throw_bad_array_new_length"); - fn = IDENTIFIER_GLOBAL_VALUE (name); + fn = get_global_binding (name); if (!fn) fn = push_throw_library_fn (name, build_function_type_list (sizetype, NULL_TREE)); diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index c72a7f4..a20c603 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3774,16 +3774,6 @@ identifier_type_value (tree id) return ret; } - -/* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since - the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */ - -tree -identifier_global_value (tree t) -{ - return IDENTIFIER_GLOBAL_VALUE (t); -} - /* Push a definition of struct, union or enum tag named ID. into binding_level B. DECL is a TYPE_DECL for the type. We assume that the tag ID is not already defined. */ @@ -4839,32 +4829,32 @@ get_namespace_binding (tree ns, tree name) return ret; } -/* Set value binding of NAME in the global namespace to VAL. Does not - add it to the list of things in the namespace. */ +/* Push internal DECL into the global namespace. Does not do the + full overload fn handling and does not add it to the list of things + in the namespace. */ void -set_global_binding (tree name, tree val) +set_global_binding (tree decl) { bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - gcc_checking_assert (name == DECL_NAME (val)); - tree *slot = find_namespace_slot (global_namespace, name, true); + tree *slot = find_namespace_slot (global_namespace, DECL_NAME (decl), true); tree old = MAYBE_STAT_DECL (*slot); if (!old) - *slot = val; - else if (old == val) + *slot = decl; + else if (old == decl) ; else if (!STAT_HACK_P (*slot) - && TREE_CODE (val) == TYPE_DECL && DECL_ARTIFICIAL (val)) - *slot = stat_hack (old, val); + && TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl)) + *slot = stat_hack (old, decl); else if (!STAT_HACK_P (*slot) && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) - *slot = stat_hack (val, old); + *slot = stat_hack (decl, old); else /* The user's placed something in the implementor's namespace. */ - diagnose_name_conflict (val, old); + diagnose_name_conflict (decl, old); timevar_cond_stop (TV_NAME_LOOKUP, subtime); } diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 2e5539f..bf0bf85 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -178,9 +178,6 @@ struct GTY(()) cp_label_binding { CURRENT_BINDING_LEVEL. You should use lookup_name_current_level instead. */ -/* Note that the information in the `names' component of the global contour - is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ - struct GTY(()) cp_binding_level { /* A chain of _DECL nodes for all variables, constants, functions, and typedef types. These are in the reverse of the order @@ -303,7 +300,11 @@ extern tree lookup_name_prefer_type (tree, int); extern tree lookup_name_real (tree, int, int, bool, int, int); extern tree lookup_type_scope (tree, tag_scope); extern tree get_namespace_binding (tree ns, tree id); -extern void set_global_binding (tree id, tree val); +extern void set_global_binding (tree decl); +inline tree get_global_binding (tree id) +{ + return get_namespace_binding (NULL_TREE, id); +} extern tree lookup_qualified_name (tree, tree, int, bool, /*hidden*/bool = false); extern tree lookup_name_nonclass (tree); extern bool is_local_extern (tree); diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index a660cdd..5b2326c 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -52,7 +52,7 @@ along with GCC; see the file COPYING3. If not see type_info objects for static initialization. The type information VAR_DECL of a type is held on the - IDENTIFIER_GLOBAL_VALUE of the type's mangled name. That VAR_DECL + get_global_binding of the type's mangled name. That VAR_DECL will be the internal type. It will usually have the correct internal type reflecting the kind of type it represents (pointer, array, function, class, inherited class, etc). When the type it @@ -226,7 +226,7 @@ throw_bad_cast (void) if (!fn) { tree name = get_identifier ("__cxa_bad_cast"); - fn = IDENTIFIER_GLOBAL_VALUE (name); + fn = get_global_binding (name); if (!fn) fn = push_throw_library_fn (name, build_function_type_list (ptr_type_node, NULL_TREE)); @@ -245,7 +245,7 @@ throw_bad_typeid (void) if (!fn) { tree name = get_identifier ("__cxa_bad_typeid"); - fn = IDENTIFIER_GLOBAL_VALUE (name); + fn = get_global_binding (name); if (!fn) { tree t = build_reference_type (const_type_info_type_node); @@ -446,7 +446,7 @@ get_tinfo_decl (tree type) name = mangle_typeinfo_for_type (type); - d = IDENTIFIER_GLOBAL_VALUE (name); + d = get_global_binding (name); if (!d) { int ix = get_pseudo_ti_index (type); -- 2.7.4