Avoid unnecessarily numbered clone symbols

Michael Ploujnikov michael.ploujnikov@oracle.com
Sun Oct 21 08:06:00 GMT 2018


On 2018-10-20 07:39 AM, Bernhard Reutner-Fischer wrote:
> On 20 October 2018 00:26:15 CEST, Michael Ploujnikov <michael.ploujnikov@oracle.com> wrote:
>> While working on
>> https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00228.html I've
>> accumulated a few easy patches.
> 
>  
> +/* Return decl name IDENTIFIER with string SUFFIX appended.  */
> +
> +tree
> +suffixed_function_name (tree identifier, const char *suffix)
> +{
> +  const char *name = IDENTIFIER_POINTER (identifier);
> +  size_t len = strlen (name);
> +  char *prefix;
> +
> +  prefix = XALLOCAVEC (char, len + strlen (suffix) + 2);
> +  memcpy (prefix, name, len);
> +  prefix[len] = symbol_table::symbol_suffix_separator ();
> +  strcpy (prefix + len + 1, suffix);
> +  return get_identifier (prefix);
> +}
> +
> 
> FWIW I think I would phrase this as
> 
> char *str = concat (
>   IDENTIFIER_POINTER (identifier),
>   symbol_table::symbol_suffix_separator (),
>   suffix);
>   tree ret = get_identifier (str);
>   free (str);
>   return ret;
> 

Thanks for the suggestion Bernhard. I also found that the last
argument to concat has to be NULL and I can use ACONCAT to avoid the
explicit free and since symbol_table::symbol_suffix_separator returns
just one char I need to first put it into a string.

I also looked into re-writing numbered_clone_function_name in a
similar way, but before I got too far I found a small issue with my
suffixed_function_name: If I'm going to write an exact replacement for
numbered_clone_function_name then I need to also copy the
double-underscore prefixing behaviour done by ASM_PN_FORMAT (right?)
which is used by ASM_FORMAT_PRIVATE_NAME and write it as:

  char *separator = XALLOCAVEC (char, 2);
  separator[0] = symbol_table::symbol_suffix_separator ();
  separator[1] = 0;
  return get_identifier (ACONCAT ((
#if defined (NO_DOT_IN_LABEL) && defined (NO_DOLLAR_IN_LABEL)
    "__",
#endif
    IDENTIFIER_POINTER (identifier),
    separator,
    suffix,
    NULL)));

(I'm not sure if the formatting is correct)

However, then it's not exactly the same as the code that I'm also
trying to replace in cgraph_node::create_virtual_clone because it
doesn't add a double underscore if neither NO_DOT_IN_LABEL nor
NO_DOLLAR_IN_LABEL is defined. Is this just an omission that I should
fix by with my new function or was it indended that way and shouldn't
be changed?

Suggestions anyone?


- Michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20181021/b28d5a7d/attachment.sig>


More information about the Gcc-patches mailing list