PATCH: dynamically allocate string constant "<built-in>"

Alex Samuel samuelATcodesourcery.com
Fri Sep 17 15:25:00 GMT 1999


This patch replaces the string constant "<built-in>" with a
dynamically allocated replacement.  This string is referred to by tree
nodes and therefore will confuse GCs if statically allocated.

Alex Samuel
CodeSourcery, LLC


Thu Sep 16 23:43:34 1999  Alex Samuel  <samuel@codesourcery.com>

	* tree.c (built_in_filename): New variable.
	(BUILT_IN_FILENAME): New macro.
	(init_tree_codes): Allocate built_in_filename.
	(make_node): Use built_in_filename instead of string constant.



Index: tree.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/tree.c,v
retrieving revision 1.90
diff -c -r1.90 tree.c
*** tree.c	1999/09/14 18:19:08	1.90
--- tree.c	1999/09/17 21:52:55
***************
*** 277,282 ****
--- 277,289 ----
  /* If non-null, a language specific helper for unsave_expr_now. */
  
  void (*lang_unsave_expr_now) PROTO((tree));
+ 
+ /* The string used as a placeholder instead of a source file name for
+    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;
+ #define BUILT_IN_FILENAME ("<built-in>")
  
  tree global_trees[TI_MAX];
  
***************
*** 866,872 ****
  void
  init_tree_codes ()
  {
!   
  }
  
  /* Return a newly allocated node of code CODE.
--- 873,881 ----
  void
  init_tree_codes ()
  {
!   built_in_filename = 
!     ggc_alloc_string (BUILT_IN_FILENAME, sizeof (BUILT_IN_FILENAME));
!   ggc_add_string_root (&built_in_filename, 1);
  }
  
  /* Return a newly allocated node of code CODE.
***************
*** 1043,1049 ****
        DECL_IN_SYSTEM_HEADER (t)
  	= in_system_header && (obstack == &permanent_obstack);
        DECL_SOURCE_LINE (t) = lineno;
!       DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
        DECL_UID (t) = next_decl_uid++;
        /* Note that we have not yet computed the alias set for this
  	 declaration.  */
--- 1052,1059 ----
        DECL_IN_SYSTEM_HEADER (t)
  	= in_system_header && (obstack == &permanent_obstack);
        DECL_SOURCE_LINE (t) = lineno;
!       DECL_SOURCE_FILE (t) = 
! 	(input_filename) ? input_filename : built_in_filename;
        DECL_UID (t) = next_decl_uid++;
        /* Note that we have not yet computed the alias set for this
  	 declaration.  */


More information about the Gcc-patches mailing list