diff options
author | Nathan Sidwell <nathan@acm.org> | 2019-05-28 13:31:16 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2019-05-28 13:31:16 +0000 |
commit | 7daef9aceb80787d9fd64b4e110b175b4d9e5a9e (patch) | |
tree | e8ff7e7170740fbcd3cf83d7662f6be7b2bf2ee0 /gcc/tree.c | |
parent | 3253d4f0266fb7aa4e70cf6afcfac9b690cfed4a (diff) | |
download | gcc-7daef9aceb80787d9fd64b4e110b175b4d9e5a9e.zip gcc-7daef9aceb80787d9fd64b4e110b175b4d9e5a9e.tar.gz gcc-7daef9aceb80787d9fd64b4e110b175b4d9e5a9e.tar.bz2 |
[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
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 60 |
1 files changed, 26 insertions, 34 deletions
@@ -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. |