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]

Resend: Patch for bogus uses of TREE_PERMANENT


tree.c decides whether to set TREE_PERMANENT based on whether the
current_obstack equals the permanent_obstack.  In a front end which
has been converted to use garbage collection, the current_obstack
pointer doesn't have anything to do with whether the tree node is
permanent, and therefore TREE_PERMANENT is likely to be incorrectly
set or not set at all.

This patch changes all the back-end references to TREE_PERMANENT to
check ggc_p also, and removes all references to TREE_PERMANENT from
the C and Fortran front ends.  There are no references in the C++
front end, and Java and Chill have not yet been converted.

To make these bugs show up immediately in future, the patch causes
TREE_PERMANENT never to be set if ggc_p is true.

I submitted this patch about three weeks ago, and discussion got
sidetracked onto debating when, if ever, we could throw the obstack
logic away.  The patch is independent of that issue and needs to go in
soon because the bogus TREE_PERMANENT values are causing serious
problems on platforms with dirty system headers.

Note I have not tested the Fortran changes.

zw

	* dwarfout.c: Include ggc.h.
	(output_type): Check ggc_p as well as TREE_PERMANENT.
	* print-tree.c (print_node): Don't examine TREE_PERMANENT if
	ggc_p is true.
	* tree.c (make_node, copy_node, make_tree_vec, tree_cons,
	build1): Set TREE_PERMANENT only if not ggc_p.
	* tree.h (TREE_PERMANENT): Update commentary.

	* tree.c (make_node): Set DECL_IN_SYSTEM_HEADER based only on
	in_system_header.
	* c-common.c (c_get_alias_set): Give all new types alias sets.
	* objc/objc-act.c (build_objc_string_object): Never copy the
	string.
	* f/com.c (ffecom_type_permanent_copy_): Delete unused function.
	(finish_decl): Don't set TREE_PERMANENT (DECL_INITIAL (decl)).

===================================================================
Index: c-common.c
--- c-common.c	2000/02/20 01:10:47	1.93
+++ c-common.c	2000/02/22 20:26:36
@@ -3490,18 +3490,9 @@ c_get_alias_set (t)
     }
 
   if (!TYPE_ALIAS_SET_KNOWN_P (type))
-    {
-      /* Types that are not global ('permanent') are not
-	 placed in the type hash table.  Thus, there can be multiple
-	 copies of identical types in local scopes.  In the long run,
-	 all types should be permanent.  */
-      if (! TREE_PERMANENT (type))
-	TYPE_ALIAS_SET (type) = 0;
-      else
-	/* TYPE is something we haven't seen before.  Put it in a new
-	   alias set.  */
-	TYPE_ALIAS_SET (type) = new_alias_set ();
-    }
+    /* TYPE is something we haven't seen before.  Put it in a new
+       alias set.  */
+    TYPE_ALIAS_SET (type) = new_alias_set ();
 
   return TYPE_ALIAS_SET (type);
 }
===================================================================
Index: dwarfout.c
--- dwarfout.c	2000/02/15 16:36:32	1.53
+++ dwarfout.c	2000/02/22 20:26:37
@@ -35,6 +35,7 @@ Boston, MA 02111-1307, USA.  */
 #include "dwarfout.h"
 #include "toplev.h"
 #include "tm_p.h"
+#include "ggc.h"
 
 #if defined(DWARF_TIMESTAMPS)
 #if !defined(POSIX)
@@ -4458,7 +4459,7 @@ output_type (type, containing_scope)
 	  {
 	    /* We can't do this for function-local types, and we don't need
                to.  */
-	    if (TREE_PERMANENT (type))
+	    if (ggc_p || TREE_PERMANENT (type))
 	      add_incomplete_type (type);
 	    return;	/* EARLY EXIT!  Avoid setting TREE_ASM_WRITTEN.  */
 	  }
===================================================================
Index: print-tree.c
--- print-tree.c	2000/02/20 01:10:48	1.22
+++ print-tree.c	2000/02/22 20:26:37
@@ -301,7 +301,7 @@ print_node (file, prefix, node, indent)
     fputs (" used", file);
   if (TREE_RAISES (node))
     fputs (" raises", file);
-  if (TREE_PERMANENT (node))
+  if (!ggc_p && TREE_PERMANENT (node))
     fputs (" permanent", file);
   if (TREE_PUBLIC (node))
     fputs (" public", file);
===================================================================
Index: tree.c
--- tree.c	2000/02/20 01:10:48	1.118
+++ tree.c	2000/02/22 20:26:38
@@ -892,6 +892,8 @@ init_tree_codes ()
 
 /* Return a newly allocated node of code CODE.
    Initialize the node's unique id and its TREE_PERMANENT flag.
+   Note that if garbage collection is in use, TREE_PERMANENT will
+   always be zero - we want to eliminate use of TREE_PERMANENT.
    For decl and type nodes, some other fields are initialized.
    The rest of the node is initialized to zero.
 
@@ -1040,6 +1042,8 @@ make_node (code)
     {
       t = (tree) obstack_alloc (obstack, length);
       memset ((PTR) t, 0, length);
+      if (obstack == &permanent_obstack)
+	TREE_PERMANENT (t) = 1;
     }
 
 #ifdef GATHER_STATISTICS
@@ -1048,8 +1052,6 @@ make_node (code)
 #endif
 
   TREE_SET_CODE (t, code);
-  if (obstack == &permanent_obstack)
-    TREE_PERMANENT (t) = 1;
 
   switch (type)
     {
@@ -1061,8 +1063,7 @@ make_node (code)
     case 'd':
       if (code != FUNCTION_DECL)
 	DECL_ALIGN (t) = 1;
-      DECL_IN_SYSTEM_HEADER (t)
-	= in_system_header && (obstack == &permanent_obstack);
+      DECL_IN_SYSTEM_HEADER (t) = in_system_header;
       DECL_SOURCE_LINE (t) = lineno;
       DECL_SOURCE_FILE (t) = 
 	(input_filename) ? input_filename : built_in_filename;
@@ -1215,7 +1216,7 @@ copy_node (node)
       TYPE_SYMTAB_ADDRESS (t) = 0;
     }
 
-  TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
+  TREE_PERMANENT (t) = (!ggc_p && current_obstack == &permanent_obstack);
 
   return t;
 }
@@ -1604,12 +1605,12 @@ make_tree_vec (len)
     {
       t = (tree) obstack_alloc (obstack, length);
       bzero ((PTR) t, length);
+      if (obstack == &permanent_obstack)
+	TREE_PERMANENT (t) = 1;
     }
 
   TREE_SET_CODE (t, TREE_VEC);
   TREE_VEC_LENGTH (t) = len;
-  if (obstack == &permanent_obstack)
-    TREE_PERMANENT (t) = 1;
 
   return t;
 }
@@ -2107,6 +2108,8 @@ tree_cons (purpose, value, chain)
     {
       node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
       memset (node, 0, sizeof (struct tree_common));
+      if (current_obstack == &permanent_obstack)
+	TREE_PERMANENT (node) = 1;
     }
 
 #ifdef GATHER_STATISTICS
@@ -2114,11 +2117,7 @@ tree_cons (purpose, value, chain)
   tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
 #endif
 
-
   TREE_SET_CODE (node, TREE_LIST);
-  if (current_obstack == &permanent_obstack)
-    TREE_PERMANENT (node) = 1;
-
   TREE_CHAIN (node) = chain;
   TREE_PURPOSE (node) = purpose;
   TREE_VALUE (node) = value;
@@ -3200,6 +3199,8 @@ build1 (code, type, node)
     {
       t = (tree) obstack_alloc (obstack, length);
       memset ((PTR) t, 0, length);
+      if (obstack == &permanent_obstack)
+	TREE_PERMANENT (t) = 1;
     }
 
 #ifdef GATHER_STATISTICS
@@ -3209,9 +3210,6 @@ build1 (code, type, node)
 
   TREE_TYPE (t) = type;
   TREE_SET_CODE (t, code);
-
-  if (obstack == &permanent_obstack)
-    TREE_PERMANENT (t) = 1;
 
   TREE_OPERAND (t, 0) = node;
   if (node && first_rtl_op (code) != 0)
===================================================================
Index: tree.h
--- tree.h	2000/02/20 01:10:48	1.124
+++ tree.h	2000/02/22 20:26:39
@@ -563,7 +563,9 @@ extern void tree_class_check_failed PARA
 
 /* Nonzero means permanent node;
    node will continue to exist for the entire compiler run.
-   Otherwise it will be recycled at the end of the function.  */
+   Otherwise it will be recycled at the end of the function.
+   This flag is always zero if garbage collection is in use.
+   Try not to use this.  */
 #define TREE_PERMANENT(NODE) ((NODE)->common.permanent_flag)
 
 /* In INTEGER_TYPE or ENUMERAL_TYPE nodes, means an unsigned type.
===================================================================
Index: objc/objc-act.c
--- objc/objc-act.c	2000/01/25 17:13:14	1.35
+++ objc/objc-act.c	2000/02/22 20:26:40
@@ -1354,13 +1354,6 @@ build_objc_string_object (strings)
   TREE_SET_CODE (string, STRING_CST);
   length = TREE_STRING_LENGTH (string) - 1;
 
-  if (! flag_next_runtime)
-    {
-      if (! TREE_PERMANENT (strings))
-	string = my_build_string (length + 1,
-				  TREE_STRING_POINTER (string));
-    }
-
   /* & ((NXConstantString) {0, string, length})  */
 
   initlist = build_tree_list (NULL_TREE, build_int_2 (0, 0));
===================================================================
Index: f/com.c
--- f/com.c	2000/02/20 01:10:50	1.76
+++ f/com.c	2000/02/22 20:40:33
@@ -444,9 +444,6 @@ static tree ffecom_type_localvar_ (ffesy
 				   ffeinfoBasictype bt,
 				   ffeinfoKindtype kt);
 static tree ffecom_type_namelist_ (void);
-#if 0
-static tree ffecom_type_permanent_copy_ (tree t);
-#endif
 static tree ffecom_type_vardesc_ (void);
 static tree ffecom_vardesc_ (ffebld expr);
 static tree ffecom_vardesc_array_ (ffesymbol s);
@@ -9502,41 +9499,6 @@ ffecom_type_namelist_ ()
 
 #endif
 
-/* Make a copy of a type, assuming caller has switched to the permanent
-   obstacks and that the type is for an aggregate (array) initializer.  */
-
-#if FFECOM_targetCURRENT == FFECOM_targetGCC && 0	/* Not used now. */
-static tree
-ffecom_type_permanent_copy_ (tree t)
-{
-  tree domain;
-  tree max;
-
-  assert (TREE_TYPE (t) != NULL_TREE);
-
-  domain = TYPE_DOMAIN (t);
-
-  assert (TREE_CODE (t) == ARRAY_TYPE);
-  assert (TREE_PERMANENT (TREE_TYPE (t)));
-  assert (TREE_PERMANENT (TREE_TYPE (domain)));
-  assert (TREE_PERMANENT (TYPE_MIN_VALUE (domain)));
-
-  max = TYPE_MAX_VALUE (domain);
-  if (!TREE_PERMANENT (max))
-    {
-      assert (TREE_CODE (max) == INTEGER_CST);
-
-      max = build_int_2 (TREE_INT_CST_LOW (max), TREE_INT_CST_HIGH (max));
-      TREE_TYPE (max) = TREE_TYPE (TYPE_MIN_VALUE (domain));
-    }
-
-  return build_array_type (TREE_TYPE (t),
-			   build_range_type (TREE_TYPE (domain),
-					     TYPE_MIN_VALUE (domain),
-					     max));
-}
-#endif
-
 /* Build Vardesc type.  */
 
 #if FFECOM_targetCURRENT == FFECOM_targetGCC
@@ -14095,9 +14057,6 @@ finish_decl (tree decl, tree init, bool 
 				0);
     }
 
-  /* This test used to include TREE_PERMANENT, however, we have the same
-     problem with initializers at the function level.  Such initializers get
-     saved until the end of the function on the momentary_obstack.  */
   if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
       && temporary
   /* DECL_INITIAL is not defined in PARM_DECLs, since it shares space with
@@ -14121,11 +14080,6 @@ finish_decl (tree decl, tree init, bool 
 	  if (TREE_READONLY (decl))
 	    {
 	      preserve_initializer ();
-	      /* Hack?  Set the permanent bit for something that is
-		 permanent, but not on the permenent obstack, so as to
-		 convince output_constant_def to make its rtl on the
-		 permanent obstack.  */
-	      TREE_PERMANENT (DECL_INITIAL (decl)) = 1;
 
 	      /* The initializer and DECL must have the same (or equivalent
 		 types), but if the initializer is a STRING_CST, its type

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