From 7daef9aceb80787d9fd64b4e110b175b4d9e5a9e Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 28 May 2019 13:31:16 +0000 Subject: [PATCH] Commonize anon-name generation https://gcc.gnu.org/ml/gcc-patches/2019-05/msg01699.html * tree.h (IDENTIFIER_ANON_P): New. (anon_aggrname_format, anon_aggname_p): Don't declare. (make_anon_name): Declare. * lto-streamer-out.c (DFS::DFS_write_tree_body): Use IDENTIFIER_ANON_P. (hash_tree): Likewise. * tree-streamer-out.c (write_ts_decl_minimal_tree): Likewise. * tree.c (anon_aggrname_p, anon_aggrname_format): Delete. (anon_cnt, make_anon_name): New. gcc/cp/ * cp-tree.h (make_anon_name): Drop declaration. (TYPE_UNNAMED_P): Use IDENTIFIER_ANON_P. * cp-lang.c (cxx_dwarf_name): Likewise. * class.c (find_flexarrays): Likewise. * decl.c (name_unnamed_type, xref_tag_1): Likewise. * error.c (dump_aggr_type): Likewise. * pt.c (push_template_decl_real): Likewise. * name-lookup.c (consider_binding_level): Likewise. (anon_cnt, make_anon_name): Delete. gcc/d/ * types.cc (fixup_anonymous_offset): Use IDENTIFIER_ANON_P. (layout_aggregate_members): Use make_anon_name. From-SVN: r271702 --- gcc/tree.c | 60 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'gcc/tree.c') diff --git a/gcc/tree.c b/gcc/tree.c index 9a8f5e5..8ca7211 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -9747,40 +9747,32 @@ clean_symbol_name (char *p) *p = '_'; } -/* For anonymous aggregate types, we need some sort of name to - hold on to. In practice, this should not appear, but it should - not be harmful if it does. */ -bool -anon_aggrname_p(const_tree id_node) -{ -#ifndef NO_DOT_IN_LABEL - return (IDENTIFIER_POINTER (id_node)[0] == '.' - && IDENTIFIER_POINTER (id_node)[1] == '_'); -#else /* NO_DOT_IN_LABEL */ -#ifndef NO_DOLLAR_IN_LABEL - return (IDENTIFIER_POINTER (id_node)[0] == '$' \ - && IDENTIFIER_POINTER (id_node)[1] == '_'); -#else /* NO_DOLLAR_IN_LABEL */ -#define ANON_AGGRNAME_PREFIX "__anon_" - return (!strncmp (IDENTIFIER_POINTER (id_node), ANON_AGGRNAME_PREFIX, - sizeof (ANON_AGGRNAME_PREFIX) - 1)); -#endif /* NO_DOLLAR_IN_LABEL */ -#endif /* NO_DOT_IN_LABEL */ -} - -/* Return a format for an anonymous aggregate name. */ -const char * -anon_aggrname_format() -{ -#ifndef NO_DOT_IN_LABEL - return "._%d"; -#else /* NO_DOT_IN_LABEL */ -#ifndef NO_DOLLAR_IN_LABEL - return "$_%d"; -#else /* NO_DOLLAR_IN_LABEL */ - return "__anon_%d"; -#endif /* NO_DOLLAR_IN_LABEL */ -#endif /* NO_DOT_IN_LABEL */ +static GTY(()) unsigned anon_cnt = 0; /* Saved for PCH. */ + +/* Create a unique anonymous identifier. The identifier is still a + valid assembly label. */ + +tree +make_anon_name () +{ + const char *fmt = +#if !defined (NO_DOT_IN_LABEL) + "." +#elif !defined (NO_DOLLAR_IN_LABEL) + "$" +#else + "_" +#endif + "_anon_%d"; + + char buf[24]; + int len = snprintf (buf, sizeof (buf), fmt, anon_cnt++); + gcc_checking_assert (len < int (sizeof (buf))); + + tree id = get_identifier_with_length (buf, len); + IDENTIFIER_ANON_P (id) = true; + + return id; } /* Generate a name for a special-purpose function. -- cgit v1.1