This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: committed: fix MMIX misuse of ggc_alloc_string
- From: Richard Sandiford <rsandifo at nildram dot co dot uk>
- To: Hans-Peter Nilsson <hp at bitrange dot com>
- Cc: gcc-patches at gcc dot gnu dot org, tromey at redhat dot com
- Date: Fri, 23 Nov 2007 10:32:30 +0000
- Subject: Re: committed: fix MMIX misuse of ggc_alloc_string
- References: <20071122022029.K85484@dair.pair.com>
Hans-Peter Nilsson <hp@bitrange.com> writes:
> Index: config/mmix/mmix.c
> ===================================================================
> --- config/mmix/mmix.c (revision 130341)
> +++ config/mmix/mmix.c (working copy)
> @@ -1158,14 +1158,11 @@ mmix_encode_section_info (tree decl, rtx
>
> const char *str = XSTR (XEXP (rtl, 0), 0);
> int len = strlen (str);
> - char *newstr;
> -
> - /* Why is the return type of ggc_alloc_string const? */
> - newstr = CONST_CAST (char *, ggc_alloc_string ("", len + 1));
> -
> + char *newstr = alloca (len + 2);
> + newstr[0] = '@';
> strcpy (newstr + 1, str);
> *newstr = '@';
> - XSTR (XEXP (rtl, 0), 0) = newstr;
> + XSTR (XEXP (rtl, 0), 0) = ggc_alloc_string (newstr, len + 1);
> }
>
> /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
>
> brgds, H-P
FWIW -- and this is just an excuse to plug my favourite macro, so feel
free to ignore -- a more compact, though less efficient, way would be:
XSTR (XEXP (rtl, 0), 0)
= ggc_strdup (ACONCAT (("@", XSTR (XEXP (rtl, 0), 0), NULL)));
Richard