This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

committed: fix MMIX misuse of ggc_alloc_string


Tom Tromey pointed out that the MMIX port was violating the
gcc_alloc_string API and sent a patch to fix it (thanks).
I hope he doesn't mind I wrote a ChangeLog entry. :)

I don't know why I wrote it this way, unless perhaps it seemed
cleaner to form the string directly in-place and "for
efficiency", but the read-only part of the API was there already
in the 46746 commit (says svn blame) of the of the original code
and I should have looked there to find the answer to the
question.  Whatever: now we play nicely like the other kids and
the GGC machinery is free to actually implement the read-only
and re-use-strings part.  Tested the obvious way.

2007-11-22  Tom Tromey  <tromey@redhat.com>

	* config/mmix/mmix.c (mmix_encode_section_info): Use alloca to
	avoid writing into string allocated by ggc_alloc_string.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]