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]

Constify result of ggc_alloc_string (prep for string pool)


I'm going to take a break from the preprocessor, and do things that
have been stacked up in my neat-idea queue for awhile.  If there's
anyone with a cpp patch waiting for review - Neil? - please send it to
me at this new address; I don't have an archive for most of this
month.  I only have limited time to work on gcc, please be patient.

Anyway, this patch is preparation for future work.  The goal is to
allocate all strings uniquely from a string pool, rather than throw
them into the GC arena with everything else.  Strings have
unpredictable lengths which are usually not powers of two, so they
waste space in the GC arena.  Most of them are never deallocated, so
they waste time during GC mark phase.  And right now we may allocate
several copies of the same string, e.g. for internal symbols.  By
doing a special allocator just for strings, we can avoid all these
problems.  Note that this covers everything allocated by
ggc_alloc_string, not just language-level string constants.

In order to uniquize strings safely, we have to ensure that they are
never modified after they're created.  This patch tags the result of
ggc_alloc_string as constant and prohibits giving it a NULL first
argument.  Then it propagates the constification through the compiler
and fixes all the places that did modify allocated strings.  I believe
there was only one where we modified an "old" string; most of the
changes are to places where we allocated blank memory and filled it
in.

There should be no noticeable performance effect.  The only place
that's required to do lots more copying than before is
combine_strings, and only in the case where we have to concatenate
adjacent string constants; I believe this to be rare.

The patch has been bootstrapped and gets no regressions in any
testsuite on i386-linux.  Note the changes to target-specific files.
I have not tested or even compiled the changes to the non-i386
targets; that's alpha arm ia64 pa rs6000.

zw

	* ggc-common.c (ggc_add_string_root): First arg now const char **.
	(ggc_mark_string_ptr): Cast elt to const char **.
	(ggc_alloc_string): Returns const char *.  Return empty_string
	if passed the empty string.  Abort if contents is NULL.
	* ggc-page.c, ggc-simple.c (empty_string): Constify.
	(init_ggc): Don't use ggc_alloc_string to allocate empty_string.
	* ggc.h (empty_string): Constify.
	(ggc_add_string_root, ggc_alloc_string): Update declarations.
	* tree.h (struct tree_string): Constify pointer.

	* c-common.c (combine_strings), optabs.c (init_libfuncs),
	profile.c (init_edge_profiler, output_func_start_profiler),
	stmt.c (init_stmt): Generate strings in scratch buffers, then
	pass to ggc_alloc_string.

	* stmt.c (expand_asm_operands): If we have to modify a constraint
	string, copy it.

	* builtins.c, c-decl.c, c-lex.c, c-typeck.c, except.c,
	print-rtl.c, rtl.h, stmt.c, toplev.c, tree.c, varasm.c,
	i386.c, rs6000.c: Constify some char* variables or structure fields.
	* dbxout.c, dwarf2out.c: Remove cast to (char**) from call to
	ggc_add_string_root.

	* alpha.c, arm.c, i386.c, ia64.c, pa.c, rs6000.c: Generate
	special labels in scratch buffers.  Do not put special labels
	on an obstack.

	* pa/pa.c (hppa_encode_label): Remove now-unnecessary second arg.
	* pa/pa-protos.h, pa/elf.h, pa/som.h, pa/pa.h: Adjust to match.

ch:
	* grant.c: Constify a char *.
	* inout.c (scanformcont): Constify first and third args.
	Adjust callers to match.
cp:
	* lex.c: Constify some char* variables or structure fields.
java:
	* lex.c (java_lex): Rearrange code so TREE_STRING_POINTER(x)
	is not modified.
	* parse.y (build_dot_class_method_invocation,
	do_merge_string_cste): Likewise.

===================================================================
Index: builtins.c
--- builtins.c	2000/09/24 09:50:30	1.59
+++ builtins.c	2000/09/29 23:15:35
@@ -202,7 +202,7 @@ c_strlen (src)
 {
   tree offset_node;
   int offset, max;
-  char *ptr;
+  const char *ptr;
 
   src = string_constant (src, &offset_node);
   if (src == 0)
===================================================================
Index: c-common.c
--- c-common.c	2000/09/25 17:04:45	1.162
+++ c-common.c	2000/09/29 23:15:36
@@ -355,7 +355,7 @@ combine_strings (strings)
       if (wide_flag)
 	length = length * wchar_bytes + wide_length;
 
-      p = ggc_alloc_string (NULL, length);
+      p = alloca (length);
 
       /* Copy the individual strings into the new combined string.
 	 If the combined string is wide, convert the chars to ints
@@ -394,9 +394,7 @@ combine_strings (strings)
       else
 	*q = 0;
 
-      value = make_node (STRING_CST);
-      TREE_STRING_POINTER (value) = p;
-      TREE_STRING_LENGTH (value) = length;
+      value = build_string (length, p);
     }
   else
     {
===================================================================
Index: c-decl.c
--- c-decl.c	2000/09/20 19:35:10	1.161
+++ c-decl.c	2000/09/29 23:15:38
@@ -3588,7 +3588,7 @@ finish_decl (decl, init, asmspec_tree)
 {
   register tree type = TREE_TYPE (decl);
   int was_incomplete = (DECL_SIZE (decl) == 0);
-  char *asmspec = 0;
+  const char *asmspec = 0;
 
   /* If a name was specified, get the string.   */
   if (asmspec_tree)
===================================================================
Index: c-lex.c
--- c-lex.c	2000/09/22 17:59:46	1.104
+++ c-lex.c	2000/09/29 23:15:38
@@ -439,7 +439,7 @@ process_directive ()
   int saw_line;
   enum { act_none, act_push, act_pop } action;
   int action_number, l;
-  char *new_file;
+  const char *new_file;
 #ifndef NO_IMPLICIT_EXTERN_C
   int entering_c_header = 0;
 #endif
===================================================================
Index: c-typeck.c
--- c-typeck.c	2000/09/19 14:26:38	1.92
+++ c-typeck.c	2000/09/29 23:15:39
@@ -4891,7 +4891,7 @@ static int constructor_incremental;
 static tree constructor_decl;
 
 /* start_init saves the ASMSPEC arg here for really_start_incremental_init.  */
-static char *constructor_asmspec;
+static const char *constructor_asmspec;
 
 /* Nonzero if this is an initializer for a top-level decl.  */
 static int constructor_top_level;
@@ -4937,7 +4937,7 @@ struct initializer_stack
 {
   struct initializer_stack *next;
   tree decl;
-  char *asmspec;
+  const char *asmspec;
   struct constructor_stack *constructor_stack;
   tree elements;
   struct spelling *spelling;
@@ -4963,7 +4963,7 @@ start_init (decl, asmspec_tree, top_leve
   const char *locus;
   struct initializer_stack *p
     = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
-  char *asmspec = 0;
+  const char *asmspec = 0;
 
   if (asmspec_tree)
     asmspec = TREE_STRING_POINTER (asmspec_tree);
===================================================================
Index: dbxout.c
--- dbxout.c	2000/09/25 11:23:43	1.65
+++ dbxout.c	2000/09/29 23:15:40
@@ -455,7 +455,7 @@ dbxout_init (asm_file, input_file_name, 
 
   dbxout_typedefs (syms);
 
-  ggc_add_string_root ((char **) &lastfile, 1);
+  ggc_add_string_root (&lastfile, 1);
 }
 
 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
===================================================================
Index: dwarf2out.c
--- dwarf2out.c	2000/09/25 11:23:43	1.207
+++ dwarf2out.c	2000/09/29 23:15:41
@@ -10667,7 +10667,7 @@ dwarf2out_line (filename, line)
 	  if (lastfile == 0 || strcmp (filename, lastfile))
 	    {
 	      if (lastfile == 0)
-		ggc_add_string_root ((char **) &lastfile, 1);
+		ggc_add_string_root (&lastfile, 1);
 
 	      fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
 	      lastfile = filename;
===================================================================
Index: except.c
--- except.c	2000/09/17 12:45:49	1.135
+++ except.c	2000/09/29 23:15:42
@@ -500,7 +500,7 @@ create_rethrow_ref (region_num)
      int region_num;
 {
   rtx def;
-  char *ptr;
+  const char *ptr;
   char buf[60];
 
   push_obstacks_nochange ();
===================================================================
Index: ggc-common.c
--- ggc-common.c	2000/08/29 20:57:11	1.31
+++ ggc-common.c	2000/09/29 23:20:54
@@ -141,10 +141,10 @@ ggc_add_tree_hash_table_root (base, nelt
 
 void
 ggc_add_string_root (base, nelt)
-     char **base;
+     const char **base;
      int nelt;
 {
-  ggc_add_root (base, nelt, sizeof (char *), ggc_mark_string_ptr);
+  ggc_add_root (base, nelt, sizeof (const char *), ggc_mark_string_ptr);
 }
 
 /* Remove the previously registered GC root at BASE.  */
@@ -558,31 +558,37 @@ static void
 ggc_mark_string_ptr (elt)
      void *elt;
 {
-  ggc_mark_string (*(char **) elt);
+  ggc_mark_string (*(const char **) elt);
 }
 
-/* Allocate a gc-able string.  If CONTENTS is null, then the memory will
-   be uninitialized.  If LENGTH is -1, then CONTENTS is assumed to be a
-   null-terminated string and the memory sized accordingly.  Otherwise,
-   the memory is filled with LENGTH bytes from CONTENTS.  */
+/* Allocate a gc-able string.  If LENGTH is -1, then CONTENTS is
+   assumed to be a null-terminated string and the memory sized
+   accordingly.  Otherwise, the memory is filled with LENGTH bytes
+   from CONTENTS.  */
 
-char *
+const char *
 ggc_alloc_string (contents, length)
      const char *contents;
      int length;
 {
   char *string;
 
-  if (length < 0)
-    {
-      if (contents == NULL)
-	return NULL;
-      length = strlen (contents);
-    }
+  if (length == 0)
+    return empty_string;
+
+#ifdef ENABLE_GC_CHECKING
+  if (contents == NULL)
+    abort ();
+#endif
+
+  if (contents[0] == 0)
+    return empty_string;
+
+  if (length == -1)
+    length = strlen (contents);
 
   string = (char *) ggc_alloc (length + 1);
-  if (contents != NULL)
-    memcpy (string, contents, length);
+  memcpy (string, contents, length);
   string[length] = 0;
 
   return string;
===================================================================
Index: ggc-page.c
--- ggc-page.c	2000/08/29 20:57:11	1.30
+++ ggc-page.c	2000/09/29 23:15:42
@@ -100,7 +100,7 @@ Boston, MA 02111-1307, USA.  */
 #endif
 
 /* The "" allocated string.  */
-char *empty_string;
+const char *empty_string;
 
 /* A two-level tree is used to look up the page-entry for a given
    pointer.  Two chunks of the pointer's bits are extracted to index
@@ -840,8 +840,12 @@ init_ggc ()
   }
 #endif
 
-  empty_string = ggc_alloc_string ("", 0);
-  ggc_add_string_root (&empty_string, 1);
+  {
+    char *s = ggc_alloc (1);
+    s[0] = 0;
+    empty_string = s;
+    ggc_add_string_root (&empty_string, 1);
+  }
 }
 
 /* Increment the `GC context'.  Objects allocated in an outer context
===================================================================
Index: ggc-simple.c
--- ggc-simple.c	2000/08/29 20:57:11	1.35
+++ ggc-simple.c	2000/09/29 23:15:42
@@ -54,7 +54,7 @@
 
 /* Constants for general use.  */
 
-char *empty_string;
+const char *empty_string;
 
 #ifndef HOST_BITS_PER_PTR
 #define HOST_BITS_PER_PTR  HOST_BITS_PER_LONG
@@ -373,10 +373,12 @@ ggc_collect ()
 void 
 init_ggc ()
 {
-  G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED;
-
-  empty_string = ggc_alloc_string ("", 0);
+  char *s = ggc_alloc (1);
+  s[0] = 0;
+  empty_string = s;
   ggc_add_string_root (&empty_string, 1);
+  
+  G.allocated_last_gc = GGC_MIN_LAST_ALLOCATED;
 }
 
 /* Start a new GGC context.  Memory allocated in previous contexts
===================================================================
Index: ggc.h
--- ggc.h	2000/08/29 20:57:11	1.29
+++ ggc.h	2000/09/29 23:15:42
@@ -44,7 +44,7 @@ union  tree_node;
 struct varasm_status;
 
 /* Constants for general use.  */
-extern char *empty_string;
+extern const char *empty_string;
 
 /* Trees that have been marked, but whose children still need marking.  */
 extern varray_type ggc_pending_trees;
@@ -53,7 +53,7 @@ extern varray_type ggc_pending_trees;
 void ggc_add_root PARAMS ((void *base, int nelt, int size, void (*)(void *)));
 void ggc_add_rtx_root PARAMS ((struct rtx_def **, int nelt));
 void ggc_add_tree_root PARAMS ((union tree_node **, int nelt));
-void ggc_add_string_root PARAMS ((char **, int nelt));
+void ggc_add_string_root PARAMS ((const char **, int nelt));
 void ggc_add_rtx_varray_root PARAMS ((struct varray_head_tag **, int nelt));
 void ggc_add_tree_varray_root PARAMS ((struct varray_head_tag **, int nelt));
 void ggc_add_tree_hash_table_root PARAMS ((struct hash_table **, int nelt));
@@ -142,7 +142,7 @@ void *ggc_alloc_cleared PARAMS ((size_t)
 
 #define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH))
 
-char *ggc_alloc_string PARAMS ((const char *contents, int length));
+const char *ggc_alloc_string PARAMS ((const char *contents, int length));
 
 /* Invoke the collector.  This is really just a hint, but in the case of
    the simple collector, the only time it will happen.  */
===================================================================
Index: optabs.c
--- optabs.c	2000/09/18 09:46:51	1.82
+++ optabs.c	2000/09/29 23:15:43
@@ -4419,8 +4419,7 @@ init_libfuncs (optable, first_mode, last
     {
       register const char *mname = GET_MODE_NAME(mode);
       register unsigned mname_len = strlen (mname);
-      register char *libfunc_name
-	= ggc_alloc_string (NULL, 2 + opname_len + mname_len + 1 + 1);
+      register char *libfunc_name = alloca (2 + opname_len + mname_len + 1 + 1);
       register char *p;
       register const char *q;
 
@@ -4432,10 +4431,11 @@ init_libfuncs (optable, first_mode, last
       for (q = mname; *q; q++)
 	*p++ = TOLOWER (*q);
       *p++ = suffix;
-      *p++ = '\0';
+      *p = '\0';
 
       optable->handlers[(int) mode].libfunc
-	= gen_rtx_SYMBOL_REF (Pmode, libfunc_name);
+	= gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (libfunc_name,
+						       p - libfunc_name));
     }
 }
 
===================================================================
Index: print-rtl.c
--- print-rtl.c	2000/09/13 19:34:05	1.60
+++ print-rtl.c	2000/09/29 23:15:43
@@ -58,7 +58,7 @@ static void print_rtx		PARAMS ((rtx));
 /* String printed at beginning of each RTL when it is dumped.
    This string is set to ASM_COMMENT_START when the RTL is dumped in
    the assembly output file.  */
-char *print_rtx_head = "";
+const char *print_rtx_head = "";
 
 /* Nonzero means suppress output of instruction numbers and line number
    notes in debugging dumps.
===================================================================
Index: profile.c
--- profile.c	2000/09/11 01:50:46	1.46
+++ profile.c	2000/09/29 23:15:43
@@ -1025,9 +1025,9 @@ static void
 init_edge_profiler ()
 {
   /* Generate and save a copy of this so it can be shared.  */
-  char *name = ggc_alloc_string (NULL, 20);
-  ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
-  profiler_label = gen_rtx_SYMBOL_REF (Pmode, name);
+  char buf[20];
+  ASM_GENERATE_INTERNAL_LABEL (buf, "LPBX", 2);
+  profiler_label = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (buf, -1));
   ggc_add_rtx_root (&profiler_label, 1);
 }
 
@@ -1066,6 +1066,7 @@ output_func_start_profiler ()
 {
   tree fnname, fndecl;
   char *name;
+  char buf[20];
   const char *cfnname;
   rtx table_address;
   enum machine_mode mode = mode_for_size (LONG_TYPE_SIZE, MODE_INT, 0);
@@ -1122,9 +1123,10 @@ output_func_start_profiler ()
   expand_function_start (fndecl, 0);
 
   /* Actually generate the code to call __bb_init_func. */
-  name = ggc_alloc_string (NULL, 20);
-  ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 0);
-  table_address = force_reg (Pmode, gen_rtx_SYMBOL_REF (Pmode, name));
+  ASM_GENERATE_INTERNAL_LABEL (buf, "LPBX", 0);
+  table_address = force_reg (Pmode,
+			     gen_rtx_SYMBOL_REF (Pmode,
+						 ggc_alloc_string (buf, -1)));
   emit_library_call (gen_rtx_SYMBOL_REF 
 		     (Pmode, ggc_alloc_string ("__bb_init_func", 14)), 0,
 		     mode, 1, table_address, Pmode);
===================================================================
Index: rtl.h
--- rtl.h	2000/09/29 11:24:12	1.226
+++ rtl.h	2000/09/29 23:15:43
@@ -1753,7 +1753,7 @@ extern void schedule_insns		PARAMS ((FIL
 extern void fix_sched_param		PARAMS ((const char *, const char *));
 
 /* In print-rtl.c */
-extern char *print_rtx_head;
+extern const char *print_rtx_head;
 extern void debug_rtx			PARAMS ((rtx));
 extern void debug_rtx_list		PARAMS ((rtx, int));
 extern void debug_rtx_range		PARAMS ((rtx, rtx));
===================================================================
Index: stmt.c
--- stmt.c	2000/09/22 18:07:47	1.170
+++ stmt.c	2000/09/29 23:15:44
@@ -394,7 +394,7 @@ struct stmt_status
 static int using_eh_for_cleanups_p = 0;
 
 /* Character strings, each containing a single decimal digit.  */
-static char *digit_strings[10];
+static const char *digit_strings[10];
 
 static int n_occurrences		PARAMS ((int, const char *));
 static void expand_goto_internal	PARAMS ((tree, rtx, rtx));
@@ -595,13 +595,15 @@ void
 init_stmt ()
 {
   int i;
+  char buf[2];
 
   gcc_obstack_init (&stmt_obstack);
 
+  buf[1] = 0;
   for (i = 0; i < 10; i++)
     {
-      digit_strings[i] = ggc_alloc_string (NULL, 1);
-      digit_strings[i][0] = '0' + i;
+      buf[0] = '0' + i;
+      digit_strings[i] = ggc_alloc_string (buf, 1);
     }
   ggc_add_string_root (digit_strings, 10);
 }
@@ -1405,7 +1407,7 @@ expand_asm_operands (string, outputs, in
     {
       tree val = TREE_VALUE (tail);
       tree type = TREE_TYPE (val);
-      char *constraint;
+      const char *constraint;
       char *p;
       int c_len;
       int j;
@@ -1422,8 +1424,8 @@ expand_asm_operands (string, outputs, in
 	 the worst that happens if we get it wrong is we issue an error
 	 message.  */
 
-      c_len = strlen (TREE_STRING_POINTER (TREE_PURPOSE (tail)));
       constraint = TREE_STRING_POINTER (TREE_PURPOSE (tail));
+      c_len = strlen (constraint);
 
       /* Allow the `=' or `+' to not be at the beginning of the string,
 	 since it wasn't explicitly documented that way, and there is a
@@ -1440,19 +1442,25 @@ expand_asm_operands (string, outputs, in
 	  error ("output operand constraint lacks `='");
 	  return;
 	}
+      j = p - constraint;
+      is_inout = *p == '+';
 
-      if (p != constraint)
+      if (j || is_inout)
 	{
-	  j = *p;
-	  bcopy (constraint, constraint+1, p-constraint);
-	  *constraint = j;
-
-	  warning ("output constraint `%c' for operand %d is not at the beginning", j, i);
+	  /* Have to throw away this constraint string and get a new one.  */
+	  char *buf = alloca (c_len + 1);
+	  buf[0] = '=';
+	  if (j)
+	    memcpy (buf + 1, constraint, j);
+	  memcpy (buf + 1 + j, p + 1, c_len - j);  /* not -j-1 - copy null */
+	  constraint = ggc_alloc_string (buf, c_len);
+
+	  if (j)
+	    warning (
+		"output constraint `%c' for operand %d is not at the beginning",
+		*p, i);
 	}
 
-      is_inout = constraint[0] == '+';
-      /* Replace '+' with '='.  */
-      constraint[0] = '=';
       /* Make sure we can specify the matching operand.  */
       if (is_inout && i > 9)
 	{
@@ -1608,7 +1616,7 @@ expand_asm_operands (string, outputs, in
     {
       int j;
       int allows_reg = 0, allows_mem = 0;
-      char *constraint, *orig_constraint;
+      const char *constraint, *orig_constraint;
       int c_len;
       rtx op;
 
@@ -1626,8 +1634,8 @@ expand_asm_operands (string, outputs, in
 	  return;
 	}
 
-      c_len = strlen (TREE_STRING_POINTER (TREE_PURPOSE (tail)));
       constraint = TREE_STRING_POINTER (TREE_PURPOSE (tail));
+      c_len = strlen (constraint);
       orig_constraint = constraint;
 
       /* Make sure constraint has neither `=', `+', nor '&'.  */
@@ -1688,8 +1696,8 @@ expand_asm_operands (string, outputs, in
 		for (j = constraint[j] - '0'; j > 0; --j)
 		  o = TREE_CHAIN (o);
 
-		c_len = strlen (TREE_STRING_POINTER (TREE_PURPOSE (o)));
 		constraint = TREE_STRING_POINTER (TREE_PURPOSE (o));
+		c_len = strlen (constraint);
 		j = 0;
 		break;
 	      }
===================================================================
Index: toplev.c
--- toplev.c	2000/09/25 22:54:04	1.383
+++ toplev.c	2000/09/29 23:15:45
@@ -4085,7 +4085,7 @@ decode_f_option (arg)
   else if ((option_value
 	    = skip_leading_substring (arg, "stack-limit-symbol=")))
     {
-      char *nm;
+      const char *nm;
       if (ggc_p)
 	nm = ggc_alloc_string (option_value, strlen (option_value));
       else
===================================================================
Index: tree.c
--- tree.c	2000/09/19 18:19:43	1.160
+++ tree.c	2000/09/29 23:15:45
@@ -297,7 +297,7 @@ void (*lang_unsave_expr_now) PARAMS ((tr
    built-in tree nodes.  The variable, which is dynamically allocated,
    should be used; the macro is only used to initialize it.  */
 
-static char *built_in_filename;
+static const char *built_in_filename;
 #define BUILT_IN_FILENAME ("<built-in>")
 
 tree global_trees[TI_MAX];
===================================================================
Index: tree.h
--- tree.h	2000/09/19 18:19:43	1.199
+++ tree.h	2000/09/29 23:15:45
@@ -721,7 +721,7 @@ struct tree_string
   struct rtx_def *rtl;	/* acts as link to register transfer language
 				   (rtl) info */
   int length;
-  char *pointer;
+  const char *pointer;
 };
 
 /* In a COMPLEX_CST node.  */
===================================================================
Index: varasm.c
--- varasm.c	2000/09/25 11:23:44	1.135
+++ varasm.c	2000/09/29 23:15:46
@@ -211,7 +211,7 @@ static enum in_section { no_section, in_
 #endif
      
 /* Text of section name when in_section == in_named.  */
-static char *in_named_name;
+static const char *in_named_name;
 
 /* Define functions like text_section for any extra sections.  */
 #ifdef EXTRA_SECTION_FUNCTIONS
@@ -1796,7 +1796,7 @@ assemble_static_space (size)
      int size;
 {
   char name[12];
-  char *namestring;
+  const char *namestring;
   rtx x;
 
 #if 0
@@ -2326,7 +2326,7 @@ decode_addr_const (exp, value)
 struct constant_descriptor
 {
   struct constant_descriptor *next;
-  char *label;
+  const char *label;
   rtx rtl;
   unsigned char contents[1];
 };
@@ -3238,7 +3238,7 @@ struct pool_constant
 
 struct pool_sym
 {
-  char *label;
+  const char *label;
   struct pool_constant *pool;
   struct pool_sym *next;
 };
@@ -3546,7 +3546,7 @@ force_const_mem (mode, x)
   register int hash;
   register struct constant_descriptor *desc;
   char label[256];
-  char *found = 0;
+  const char *found = 0;
   rtx def;
 
   /* If we want this CONST_DOUBLE in the same mode as it is in memory
===================================================================
Index: ch/grant.c
--- ch/grant.c	2000/05/09 19:55:48	1.15
+++ ch/grant.c	2000/09/29 23:15:46
@@ -67,7 +67,7 @@ typedef struct
 } MYSTRING;
 
 /* structure used for handling multiple grant files */
-char	*grant_file_name;
+const char	*grant_file_name;
 MYSTRING	*gstring = NULL;
 MYSTRING        *selective_gstring = NULL;
 
===================================================================
Index: ch/inout.c
--- ch/inout.c	2000/08/29 21:39:45	1.14
+++ ch/inout.c	2000/09/29 23:15:46
@@ -3841,8 +3841,9 @@ typedef enum {
   NormalEnd, EndAtParen, TextFailEnd 
 } formatexit_t;
 
-static formatexit_t scanformcont	PARAMS ((char *, int, char **, int *,
-						tree, tree *, int, int *));
+static formatexit_t scanformcont	PARAMS ((const char *, int,
+						 const char **, int *,
+						 tree, tree *, int, int *));
 
 /* NOTE: varibale have to be set to False before calling check_format_string */
 static Boolean empty_printed;
@@ -3912,9 +3913,9 @@ check_exprlist (code, exprlist, argnum, 
 static formatexit_t
 scanformcont (fcs, len, fcsptr, lenptr, exprlist, exprptr,
 	      firstargnum, nextargnum)
-     char *fcs;
+     const char *fcs;
      int len;
-     char **fcsptr;
+     const char **fcsptr;
      int *lenptr;
      tree exprlist;
      tree *exprptr;
@@ -3998,7 +3999,7 @@ scanformcont (fcs, len, fcsptr, lenptr, 
 	    {
 	      unsigned long times = repetition;
 	      int  cntlen;
-	      char* cntfcs;
+	      const char* cntfcs;
 	      tree cntexprlist;
 	      int nextarg;
 
@@ -4237,7 +4238,7 @@ check_format_string (format_str, exprlis
      tree exprlist;
      int firstargnum;
 {
-  char *x;
+  const char *x;
   int y, yy;
   tree z = NULL_TREE;
 
===================================================================
Index: config/alpha/alpha.c
--- config/alpha/alpha.c	2000/09/25 12:08:01	1.145
+++ config/alpha/alpha.c	2000/09/29 23:15:47
@@ -6228,12 +6228,12 @@ alpha_need_linkage (name, is_local)
   /* Construct a SYMBOL_REF for us to call.  */
   {
     size_t name_len = strlen (name);
-    char *linksym = ggc_alloc_string (NULL, name_len + 6);
-
+    char *linksym = alloca (name_len + 6);
     linksym[0] = '$';
     memcpy (linksym + 1, name, name_len);
     memcpy (linksym + 1 + name_len, "..lk", 5);
-    al->linkage = gen_rtx_SYMBOL_REF (Pmode, linksym);
+    al->linkage = gen_rtx_SYMBOL_REF (Pmode,
+				      ggc_alloc_string (linksym, name_len + 5));
   }
 
   splay_tree_insert (alpha_links, (splay_tree_key) name,
===================================================================
Index: config/arm/arm.c
--- config/arm/arm.c	2000/09/08 14:26:29	1.107
+++ config/arm/arm.c	2000/09/29 23:15:47
@@ -1717,14 +1717,12 @@ arm_encode_call_attribute (decl, flag)
   /* Do not allow weak functions to be treated as short call.  */
   if (DECL_WEAK (decl) && flag == SHORT_CALL_FLAG_CHAR)
     return;
-  
-  if (ggc_p)
-    newstr = ggc_alloc_string (NULL, len + 2);
-  else
-    newstr = permalloc (len + 2);
 
-  sprintf (newstr, "%c%s", flag, str);
+  newstr = alloca (len + 2);
+  newstr[0] = flag;
+  strcpy (newstr + 1, str);
 
+  newstr = ggc_alloc_string (newstr, len + 1);
   XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
 }
 
===================================================================
Index: config/i386/i386.c
--- config/i386/i386.c	2000/09/29 11:40:24	1.182
+++ config/i386/i386.c	2000/09/29 23:15:48
@@ -1675,9 +1675,9 @@ ix86_can_use_return_insn_p ()
   return tsize == 0 && nregs == 0;
 }
 
-static char *pic_label_name;
+static const char *pic_label_name;
 static int pic_label_output;
-static char *global_offset_table_name;
+static const char *global_offset_table_name;
 
 /* This function generates code for -fpic that loads %ebx with
    the return address of the caller and then returns.  */
@@ -1733,9 +1733,10 @@ load_pic_register ()
     {
       if (pic_label_name == NULL)
 	{
-	  pic_label_name = ggc_alloc_string (NULL, 32);
+	  char buf[32];
+	  ASM_GENERATE_INTERNAL_LABEL (buf, "LPR", 0);
+	  pic_label_name = ggc_alloc_string (buf, -1);
 	  ggc_add_string_root (&pic_label_name, 1);
-	  ASM_GENERATE_INTERNAL_LABEL (pic_label_name, "LPR", 0);
 	}
       pclab = gen_rtx_MEM (QImode, gen_rtx_SYMBOL_REF (Pmode, pic_label_name));
     }
===================================================================
Index: config/ia64/ia64.c
--- config/ia64/ia64.c	2000/09/25 22:06:29	1.53
+++ config/ia64/ia64.c	2000/09/29 23:15:48
@@ -4640,16 +4640,12 @@ ia64_encode_section_info (decl)
 	       && symbol_str[0] != SDATA_NAME_FLAG_CHAR)
 	{
 	  size_t len = strlen (symbol_str);
-	  char *newstr;
+	  char *newstr = alloca (len + 1);
 
-	  if (ggc_p)
-	    newstr = ggc_alloc_string (NULL, len + 1);
-	  else
-	    newstr = obstack_alloc (saveable_obstack, len + 2);
-
 	  *newstr = SDATA_NAME_FLAG_CHAR;
 	  memcpy (newstr + 1, symbol_str, len + 1);
-
+	  
+	  newstr = ggc_alloc_string (newstr, len);
 	  XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
 	}
     }
===================================================================
Index: config/pa/elf.h
--- config/pa/elf.h	2000/05/01 17:30:35	1.7
+++ config/pa/elf.h	2000/09/29 23:15:49
@@ -84,7 +84,7 @@ do {  \
 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
   do { fputs ("\t.IMPORT ", FILE);					\
        if (!function_label_operand (RTL, VOIDmode))			\
-	 hppa_encode_label (RTL, 1);					\
+	 hppa_encode_label (RTL);					\
        assemble_name (FILE, XSTR ((RTL), 0));		       		\
        fputs (",ENTRY\n", FILE);					\
      } while (0)
===================================================================
Index: config/pa/pa-protos.h
--- config/pa/pa-protos.h	2000/04/11 20:02:45	1.3
+++ config/pa/pa-protos.h	2000/09/29 23:15:49
@@ -61,7 +61,7 @@ extern void output_global_address PARAMS
 extern void print_operand PARAMS ((FILE *, rtx, int));
 extern rtx legitimize_pic_address PARAMS ((rtx, enum machine_mode, rtx));
 extern struct rtx_def *gen_cmp_fp PARAMS ((enum rtx_code, rtx, rtx));
-extern void hppa_encode_label PARAMS ((rtx, int));
+extern void hppa_encode_label PARAMS ((rtx));
 extern int arith11_operand PARAMS ((rtx, enum machine_mode));
 extern int symbolic_expression_p PARAMS ((rtx));
 extern int hppa_address_cost PARAMS ((rtx));
===================================================================
Index: config/pa/pa.c
--- config/pa/pa.c	2000/07/28 02:17:25	1.79
+++ config/pa/pa.c	2000/09/29 23:15:49
@@ -5949,33 +5949,22 @@ output_call (insn, call_dest, sibcall)
 /* In HPUX 8.0's shared library scheme, special relocations are needed
    for function labels if they might be passed to a function
    in a shared library (because shared libraries don't live in code
-   space), and special magic is needed to construct their address.
+   space), and special magic is needed to construct their address.  */
 
-   For reasons too disgusting to describe storage for the new name
-   is allocated as a ggc string, or as a string on the saveable_obstack
-   (released at function exit) or on the permanent_obstack for things
-   that can never change (libcall names for example). */
-
 void
-hppa_encode_label (sym, permanent)
+hppa_encode_label (sym)
      rtx sym;
-     int permanent;
 {
   const char *str = XSTR (sym, 0);
   int len = strlen (str);
-  char *newstr;
-
-  if (ggc_p)
-    newstr = ggc_alloc_string (NULL, len + 1);
-  else
-    newstr = obstack_alloc ((permanent ? &permanent_obstack : saveable_obstack),
-			  len + 2);
+  char *newstr = alloca (len + 1);
 
   if (str[0] == '*')
     *newstr++ = *str++;
   strcpy (newstr + 1, str);
   *newstr = '@';
-  XSTR (sym,0) = newstr;
+
+  XSTR (sym,0) = ggc_alloc_string (newstr, len);
 }
 
 int
===================================================================
Index: config/pa/pa.h
--- config/pa/pa.h	2000/09/25 10:11:22	1.93
+++ config/pa/pa.h	2000/09/29 23:15:49
@@ -1494,7 +1494,7 @@ do							\
 	  _rtl = TREE_CST_RTL (DECL);			\
 	SYMBOL_REF_FLAG (XEXP (_rtl, 0)) = 1;		\
 	if (TREE_CODE (DECL) == FUNCTION_DECL)		\
-	  hppa_encode_label (XEXP (DECL_RTL (DECL), 0), 0);\
+	  hppa_encode_label (XEXP (DECL_RTL (DECL), 0));\
       }							\
   }							\
 while (0)
===================================================================
Index: config/pa/som.h
--- config/pa/som.h	2000/06/30 18:14:05	1.12
+++ config/pa/som.h	2000/09/29 23:15:49
@@ -352,7 +352,7 @@ DTORS_SECTION_FUNCTION
 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, RTL) \
   do { fputs ("\t.IMPORT ", FILE);					\
        if (!function_label_operand (RTL, VOIDmode))			\
-	 hppa_encode_label (RTL, 1);					\
+	 hppa_encode_label (RTL);					\
        assemble_name (FILE, XSTR ((RTL), 0));		       		\
        fputs (",CODE\n", FILE);						\
      } while (0)
===================================================================
Index: config/rs6000/rs6000.c
--- config/rs6000/rs6000.c	2000/09/11 06:00:52	1.149
+++ config/rs6000/rs6000.c	2000/09/29 23:15:50
@@ -5609,7 +5609,7 @@ rs6000_emit_prologue()
     {
       int i;
       char rname[30];
-      char *alloc_rname;
+      const char *alloc_rname;
       rtvec p;
       p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
       
@@ -6061,7 +6061,7 @@ rs6000_emit_epilogue(sibcall)
 	{
 	  int i;
 	  char rname[30];
-	  char *alloc_rname;
+	  const char *alloc_rname;
 
 	  sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, 
 		   info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
@@ -7584,18 +7584,13 @@ rs6000_encode_section_info (decl)
 	{
 	  size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
 	  size_t len2 = strlen (XSTR (sym_ref, 0));
-	  char *str;
+	  char *str = alloca (len1 + len2 + 1);
 
-	  if (ggc_p)
-	    str = ggc_alloc_string (NULL, len1 + len2);
-	  else
-	    str = permalloc (len1 + len2 + 1);
-
 	  str[0] = '.';
 	  str[1] = '.';
 	  memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
 
-	  XSTR (sym_ref, 0) = str;
+	  XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
 	}
     }
   else if (rs6000_sdata != SDATA_NONE
@@ -7635,16 +7630,11 @@ rs6000_encode_section_info (decl)
 	{
 	  rtx sym_ref = XEXP (DECL_RTL (decl), 0);
 	  size_t len = strlen (XSTR (sym_ref, 0));
-	  char *str;
+	  char *str = alloca (len + 1);
 
-	  if (ggc_p)
-	    str = ggc_alloc_string (NULL, len + 1);
-	  else
-	    str = permalloc (len + 2);
 	  str[0] = '@';
 	  memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
-
-	  XSTR (sym_ref, 0) = str;
+	  XSTR (sym_ref, 0) = ggc_alloc_string (str, len);
 	}
     }
 }
===================================================================
Index: cp/lex.c
--- cp/lex.c	2000/09/14 23:44:47	1.216
+++ cp/lex.c	2000/09/29 23:15:50
@@ -131,7 +131,7 @@ extern int *token_count;
 
 struct impl_files
 {
-  char *filename;
+  const char *filename;
   struct impl_files *next;
 };
 
@@ -140,7 +140,7 @@ static struct impl_files *impl_file_chai
 /* The string used to represent the filename of internally generated
    tree nodes.  The variable, which is dynamically allocated, should
    be used; the macro is only used to initialize it.  */
-static char *internal_filename;
+static const char *internal_filename;
 #define INTERNAL_FILENAME ("<internal>")
 
 /* Return something to represent absolute declarators containing a *.
===================================================================
Index: java/lex.c
--- java/lex.c	2000/09/12 22:23:59	1.42
+++ java/lex.c	2000/09/29 23:15:50
@@ -1082,11 +1082,13 @@ java_lex (java_lval)
 	java_lval->node = error_mark_node; /* Requires futher testing FIXME */
       else
 	{
+	  size_t len = strlen (string);
+	  char *buf = obstack_alloc (expression_obstack, len+1);
 	  tree s = make_node (STRING_CST);
-	  TREE_STRING_LENGTH (s) = strlen (string);
-	  TREE_STRING_POINTER (s) = 
-	    obstack_alloc (expression_obstack, TREE_STRING_LENGTH (s)+1);
-	  strcpy (TREE_STRING_POINTER (s), string);
+
+	  strcpy (buf, string);
+	  TREE_STRING_LENGTH (s) = len;
+	  TREE_STRING_POINTER (s) = buf;
 	  java_lval->node = s;
 	}
 #endif
===================================================================
Index: java/parse.y
--- java/parse.y	2000/09/29 20:14:53	1.211
+++ java/parse.y	2000/09/29 23:15:52
@@ -8417,6 +8417,7 @@ build_dot_class_method_invocation (type)
      tree type;
 {
   tree sig_id, s;
+  char *buf;
 
   if (TYPE_ARRAY_P (type))
     sig_id = build_java_signature (type);
@@ -8424,10 +8425,10 @@ build_dot_class_method_invocation (type)
     sig_id = DECL_NAME (TYPE_NAME (type));
 
   s = make_node (STRING_CST);
+  buf = obstack_alloc (expression_obstack, IDENTIFIER_LENGTH (sig_id) + 1);
+  strcpy (buf, IDENTIFIER_POINTER (sig_id));
+  TREE_STRING_POINTER (s) = buf;
   TREE_STRING_LENGTH (s) = IDENTIFIER_LENGTH (sig_id);
-  TREE_STRING_POINTER (s) = obstack_alloc (expression_obstack,
-					   TREE_STRING_LENGTH (s)+1);
-  strcpy (TREE_STRING_POINTER (s), IDENTIFIER_POINTER (sig_id));
   return build_method_invocation (build_wfl_node (get_identifier ("class$")),
 				  build_tree_list (NULL_TREE, s));
 }
@@ -13000,7 +13001,7 @@ do_merge_string_cste (cste, string, stri
   
   cste = make_node (STRING_CST);
   TREE_STRING_LENGTH (cste) = len;
-  new = TREE_STRING_POINTER (cste) = obstack_alloc (expression_obstack, len+1);
+  TREE_STRING_POINTER (cste) = new = obstack_alloc (expression_obstack, len+1);
 
   if (after)
     {

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