diff options
author | Nathan Sidwell <nathan@acm.org> | 2018-11-01 11:18:06 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2018-11-01 11:18:06 +0000 |
commit | 41f927f4a668aeb167a673f916cc5cbfb978a560 (patch) | |
tree | 9677b9701960270615e3bd8fae450f03f8400509 /gcc/cp/mangle.c | |
parent | 5de9d93189dd367bd3d2e1430d3aefdccab5cb72 (diff) | |
download | gcc-41f927f4a668aeb167a673f916cc5cbfb978a560.zip gcc-41f927f4a668aeb167a673f916cc5cbfb978a560.tar.gz gcc-41f927f4a668aeb167a673f916cc5cbfb978a560.tar.bz2 |
[ABI PATCH] static anonymous unions of function scope
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg02076.html
* cp-tree.h (struct lang_function): Delete x_local_names field.
(struct lang_decl_base): Rename u2sel to spare.
(struct lang_decl_min): Remove lang_decl_u2 union. Keep access
field.
(LANG_DECL_U2_CHECK): Delete.
(DECL_DISCRIMINATOR_P): Require function scope.
(DECL_DISCRIMINATOR): Adjust.
(DECL_DISCRIMINATOR_SET_P): Delete.
(DECL_CAPTURED_VARIABLE, DECL_ACCESS, THUnK_VIRTUAL_OFFSET): Adjust.
(local_classes): Don't declare.
(determine_local_discriminator): Declare.
* decl.c (push_local_name): Delete.
(local_entities, determina_local_discrminator): New.
(duplicate_decls): Copy DECL_ACCESS. Fix formatting.
(cp_finish_decl): Use determine_local_discriminator.
(save_function_data): Drop x_local_names.
(finish_function): Drop local_names.
* decl2.c (finish_anon_union): Use determine_local_disciminator.
* mangle.c (write_unnamed_type_name): Use
discriminator_for_local_entity.
(local_class_index): Delete.
(discriminator_for_local_entity): Reimplement.
(write_local_name): Adjust discriminator code.
* name-lookup.c (do_pushtag): Call determine_local_discrimiator.
* semantics.c (finish_omp_threadprivate): Drop DECL_DISCRIMINATOR
handling.
* class.c (local_classes): Delete.
(init_class_processing): Don't init it.
* g++.dg/abi/anon5.C: New.
From-SVN: r265714
Diffstat (limited to 'gcc/cp/mangle.c')
-rw-r--r-- | gcc/cp/mangle.c | 64 |
1 files changed, 17 insertions, 47 deletions
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 59a3111..690d0bb 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -233,7 +233,6 @@ static void write_discriminator (const int); static void write_local_name (tree, const tree, const tree); static void dump_substitution_candidates (void); static tree mangle_decl_string (const tree); -static int local_class_index (tree); static void maybe_check_abi_tags (tree, tree = NULL_TREE, int = 10); static bool equal_abi_tags (tree, tree); @@ -1642,7 +1641,7 @@ write_unnamed_type_name (const tree type) MANGLE_TRACE_TREE ("unnamed-type-name", type); if (TYPE_FUNCTION_SCOPE_P (type)) - discriminator = local_class_index (type); + discriminator = discriminator_for_local_entity (TYPE_NAME (type)); else if (TYPE_CLASS_SCOPE_P (type)) discriminator = nested_anon_class_index (type); else @@ -1913,58 +1912,25 @@ write_special_name_destructor (const tree dtor) } } -/* Scan the vector of local classes and return how many others with the - same name (or same no name) and context precede ENTITY. */ - -static int -local_class_index (tree entity) -{ - int ix, discriminator = 0; - tree name = (TYPE_UNNAMED_P (entity) ? NULL_TREE - : TYPE_IDENTIFIER (entity)); - tree ctx = TYPE_CONTEXT (entity); - for (ix = 0; ; ix++) - { - tree type = (*local_classes)[ix]; - if (type == entity) - return discriminator; - if (TYPE_CONTEXT (type) == ctx - && (name ? TYPE_IDENTIFIER (type) == name - : TYPE_UNNAMED_P (type))) - ++discriminator; - } - gcc_unreachable (); -} - /* Return the discriminator for ENTITY appearing inside - FUNCTION. The discriminator is the lexical ordinal of VAR among - entities with the same name in the same FUNCTION. */ + FUNCTION. The discriminator is the lexical ordinal of VAR or TYPE among + entities with the same name and kind in the same FUNCTION. */ static int discriminator_for_local_entity (tree entity) { - if (DECL_DISCRIMINATOR_P (entity)) + if (!DECL_LANG_SPECIFIC (entity)) { - if (DECL_DISCRIMINATOR_SET_P (entity)) - return DECL_DISCRIMINATOR (entity); - else - /* The first entity with a particular name doesn't get - DECL_DISCRIMINATOR set up. */ - return 0; - } - else if (TREE_CODE (entity) == TYPE_DECL) - { - /* Scan the list of local classes. */ - entity = TREE_TYPE (entity); - - /* Lambdas and unnamed types have their own discriminators. */ - if (LAMBDA_TYPE_P (entity) || TYPE_UNNAMED_P (entity)) - return 0; - - return local_class_index (entity); + /* Some decls, like __FUNCTION__, don't need a discriminator. */ + gcc_checking_assert (DECL_ARTIFICIAL (entity)); + return 0; } + else if (tree disc = DECL_DISCRIMINATOR (entity)) + return TREE_INT_CST_LOW (disc); else - gcc_unreachable (); + /* The first entity with a particular name doesn't get + DECL_DISCRIMINATOR set up. */ + return 0; } /* Return the discriminator for STRING, a string literal used inside @@ -2062,7 +2028,11 @@ write_local_name (tree function, const tree local_entity, from <local-name>, so it doesn't try to process the enclosing function scope again. */ write_name (entity, /*ignore_local_scope=*/1); - write_discriminator (discriminator_for_local_entity (local_entity)); + if (DECL_DISCRIMINATOR_P (local_entity) + && !(TREE_CODE (local_entity) == TYPE_DECL + && (LAMBDA_TYPE_P (TREE_TYPE (local_entity)) + || TYPE_UNNAMED_P (TREE_TYPE (local_entity))))) + write_discriminator (discriminator_for_local_entity (local_entity)); } } |