[tree-ssa mudflap] build/merge fixes

Frank Ch. Eigler fche@redhat.com
Thu Jun 5 17:28:00 GMT 2003


Hi -

The bulk of this commit is reworking the way the mudflap instrumentation
pass keeps track of what tree nodes it has processed.  It used to use
the TREE_BOUNDED flag from the old bounded-pointers code, but its recent
removal from mainline has been merged.  The new code uses an auxiliary
hash table instead.  I'm also regenerating the toplevel Makefile.in,
which restores libmudflap building.

BTW, there are a few interesting problems I'm working on:
On x86 and other hosts, a tree inlining-related bug is causing some local
variables to be registered in duplicate (fail27-frag, -O3).
On ia64, the synthetic function containing registration calls of static
objects is emitting wrong sorts of relocations (@gprel instead of @ltoffx)
for the synthetic decls, causing linking failures.
On amd64, we the threading test case crashes mysteriously.

- FChE


2003-06-05  Frank Ch. Eigler  <fche@redhat.com>

	* Makefile.in: Regenerated to activate libmudflap builds.

 	* tree-mudflap.c (mx_flag): Remove.  Update callers to use mf_mark.
	(TREE_MUDFLAPPED_P): Remove.  Update callers to use mf_marked_p.
 	(mf_mark, mf_marked_p): Replacement functions to replace old node
 	marking based on tree flag-bits.
 	(mf_mostly_copy_tree_r): Preserve markedness across copies.
 	* tree-mudflap.h: Add new decls
 	* c-mudflap.c (mx_flag): Remove.  Update callers to use mf_mark.

        * cp-mudflap.c (mx_flag): Remove.  Update callers to use mf_mark.

Index: c-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-mudflap.c,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 c-mudflap.c
--- c-mudflap.c	3 Jun 2003 16:50:30 -0000	1.1.2.4
+++ c-mudflap.c	5 Jun 2003 16:58:39 -0000
@@ -46,24 +46,6 @@ Software Foundation, 59 Temple Place - S
 
 /* ------------------------------------------------------------------------ */
 
-static tree mx_flag PARAMS ((tree));
-
-/* XXX: copied from tree-mudflap.c */
-static tree
-mx_flag (t)
-     tree t;
-{
-  if (!t)
-    abort ();
-#define MARK_TREE_MUDFLAPPED(tree)  do { TREE_VISITED (tree) = 1; } while (0)
-  MARK_TREE_MUDFLAPPED(t);
-  return t;
-}
-
-
-
-/* ------------------------------------------------------------------------ */
-
 
 /* Initialize the global tree nodes that correspond to mf-runtime.h
    declarations.  */
@@ -105,7 +87,7 @@ mflang_register_call (label, regsize, re
 
   /* See gcc-checker's c-bounds.c (declare_private_statics)  */
   decltype = build_array_type (char_type_node, build_index_type (integer_zero_node));
-  decl = mx_flag (build_decl (VAR_DECL, get_identifier (label), decltype));
+  decl = mudflap_mark (build_decl (VAR_DECL, get_identifier (label), decltype));
 
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
@@ -122,7 +104,7 @@ mflang_register_call (label, regsize, re
 
   call_params = tree_cons (NULL_TREE,
 			   convert (ptr_type_node, 
-				    mx_flag (build1 (ADDR_EXPR, 
+				    mudflap_mark (build1 (ADDR_EXPR, 
 						     build_pointer_type (TREE_TYPE (decl)),
 						     decl))),
 			   tree_cons (NULL_TREE, 
Index: tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.43
diff -u -p -r1.1.2.43 tree-mudflap.c
--- tree-mudflap.c	3 Jun 2003 16:50:51 -0000	1.1.2.43
+++ tree-mudflap.c	5 Jun 2003 16:58:39 -0000
@@ -55,7 +55,6 @@ static void mf_decl_clear_locals PARAMS 
 static tree mf_varname_tree PARAMS ((tree));
 static tree mf_file_function_line_tree PARAMS ((const char *, int));
 static tree mf_mostly_copy_tree_r PARAMS ((tree *, int *, void *));
-static tree mx_flag PARAMS ((tree));
 static tree mx_xfn_indirect_ref PARAMS ((tree *, int *, void *));
 static tree mx_xfn_xform_decls PARAMS ((tree *, int *, void *));
 
@@ -65,13 +64,45 @@ static tree mf_build_check_statement_for
 static void mx_register_decls PARAMS ((tree, tree *));
 
 
-/* These macros are used to mark tree nodes, so that they are not
-   repeatedly transformed.  */
+/* extern mudflap functions */
+
+
+
+
+static GTY ((param_is (union tree_node))) htab_t marked_trees = NULL;
+
+
+/* Mark and return the given tree node to prevent further mudflap
+   transforms.  */
+tree
+mudflap_mark (t)
+     tree t;
+{
+  void **slot;
+
+  if (marked_trees == NULL)
+    marked_trees = htab_create (31, htab_hash_pointer, htab_eq_pointer, NULL);
+
+  slot = htab_find_slot (marked_trees, t, INSERT);
+  *slot = t;
+  return t;
+}
+
+
+int
+mudflap_marked_p (t)
+     tree t;
+{
+  void *entry;
+
+  if (marked_trees == NULL)
+    return 0;
+
+  entry = htab_find (marked_trees, t);
+  return (entry != NULL);
+}
 
-#define MARK_TREE_MUDFLAPPED(tree)  do { TREE_VISITED (tree) = 1; } while (0)
-#define TREE_MUDFLAPPED_P(tree)  TREE_VISITED (tree)
 
-/* extern mudflap functions */
 
 /* Perform the mudflap tree transforms on the given function.  */
  
@@ -144,11 +175,11 @@ mf_init_extern_trees ()
   if (done) return;
 
   mf_uintptr_type = TREE_TYPE (mflang_lookup_decl ("uintptr_t"));
-  mf_cache_array_decl = mx_flag (mflang_lookup_decl ("__mf_lookup_cache"));
+  mf_cache_array_decl = mudflap_mark (mflang_lookup_decl ("__mf_lookup_cache"));
   mf_cache_struct_type = TREE_TYPE (TREE_TYPE (mf_cache_array_decl));
   mf_cache_structptr_type = build_pointer_type (mf_cache_struct_type);
-  mf_cache_shift_decl = mx_flag (mflang_lookup_decl ("__mf_lc_shift"));
-  mf_cache_mask_decl = mx_flag (mflang_lookup_decl ("__mf_lc_mask"));
+  mf_cache_shift_decl = mudflap_mark (mflang_lookup_decl ("__mf_lc_shift"));
+  mf_cache_mask_decl = mudflap_mark (mflang_lookup_decl ("__mf_lc_mask"));
   mf_check_fndecl = mflang_lookup_decl ("__mf_check");
   mf_register_fndecl = mflang_lookup_decl ("__mf_register");
   mf_unregister_fndecl = mflang_lookup_decl ("__mf_unregister");
@@ -169,13 +200,13 @@ mf_decl_cache_locals (body)
   tree init_exprs = NULL_TREE;
 
   /* Create the chain of VAR_DECL nodes.  */
-  mf_cache_shift_decl_l = mx_flag (build_decl (VAR_DECL,
+  mf_cache_shift_decl_l = mudflap_mark (build_decl (VAR_DECL,
 					       get_identifier ("__mf_lookup_shift_l"),
 					       TREE_TYPE (mf_cache_shift_decl)));
   DECL_ARTIFICIAL (mf_cache_shift_decl_l) = 1;
   DECL_CONTEXT (mf_cache_shift_decl_l) = current_function_decl;
 
-  mf_cache_mask_decl_l = mx_flag (build_decl (VAR_DECL,
+  mf_cache_mask_decl_l = mudflap_mark (build_decl (VAR_DECL,
 					      get_identifier ("__mf_lookup_mask_l"),
 					      TREE_TYPE (mf_cache_mask_decl)));
   DECL_ARTIFICIAL (mf_cache_mask_decl_l) = 1;
@@ -211,19 +242,6 @@ mf_decl_clear_locals ()
 
 
 
-/* Mark and return the given tree node to prevent further mudflap
-   transforms.  */
-static tree
-mx_flag (t)
-     tree t;
-{
-  if (!t)
-    abort ();
-  MARK_TREE_MUDFLAPPED (t);
-  return t;
-}
-
-
 
 /* A copy of c-simplify.c's mostly_copy_tree_r.  */
 static tree
@@ -232,11 +250,16 @@ mf_mostly_copy_tree_r (tp, walk_subtrees
      int *walk_subtrees;
      void *data;
 {
+  /* Retain mudflap marked-ness across copy.  */
+  int was_marked = mudflap_marked_p (*tp);
+
   if (TREE_CODE (*tp) == SAVE_EXPR)
     *walk_subtrees = 0;
   else
     copy_tree_r (tp, walk_subtrees, data);
 
+  if (was_marked) mudflap_mark (*tp);
+
   return NULL_TREE;
 }
 
@@ -334,7 +357,7 @@ mf_varname_tree (decl)
   result = fix_string_type (build_string (strlen (buf_contents) + 1, buf_contents));
   output_clear_message_text (buf);
 
-  return mx_flag (result);
+  return mudflap_mark (result);
 }
 
 
@@ -390,7 +413,7 @@ mf_file_function_line_tree (file, line)
   buf_contents = output_finalize_message (buf);
   result = fix_string_type (build_string (strlen (buf_contents) + 1, buf_contents));
 
-  return mx_flag (result);
+  return mudflap_mark (result);
 }
 
 
@@ -459,7 +482,7 @@ mf_offset_expr_of_array_ref (t, offset, 
 				 TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (t)))));
 
       /* Mark this node to inhibit further transformation.  */
-      mx_flag (t);
+      mudflap_mark (t);
       
       return
 	fold (build (PLUS_EXPR, integer_type_node, *offset, 
@@ -576,12 +599,12 @@ mf_build_check_statement_for (ptrvalue, 
     t1 = build (BIT_AND_EXPR, mf_uintptr_type, t0, 
 		(flag_mudflap > 1 ? mf_cache_mask_decl : mf_cache_mask_decl_l));
 
-    t2 = mx_flag (build (ARRAY_REF,
+    t2 = mudflap_mark (build (ARRAY_REF,
 			 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (mf_cache_array_decl))),
 			 mf_cache_array_decl,
 			 t1));
 
-    t3 = mx_flag (build1 (ADDR_EXPR, mf_cache_structptr_type, t2));
+    t3 = mudflap_mark (build1 (ADDR_EXPR, mf_cache_structptr_type, t2));
 
     bind_exprs = chainon (bind_exprs,
 			  build_stmt (EXPR_STMT,
@@ -603,14 +626,14 @@ mf_build_check_statement_for (ptrvalue, 
     tree t0, t1, t2;
 
     /* __mf_elem->low  */
-    t0 = mx_flag (build (COMPONENT_REF, mf_uintptr_type,
-			 mx_flag (build1 (INDIRECT_REF, mf_cache_struct_type,
+    t0 = mudflap_mark (build (COMPONENT_REF, mf_uintptr_type,
+			 mudflap_mark (build1 (INDIRECT_REF, mf_cache_struct_type,
 			                  t1_3_1)),
 			 TYPE_FIELDS (mf_cache_struct_type)));
 
     /* __mf_elem->high  */
-    t1 = mx_flag (build (COMPONENT_REF, mf_uintptr_type,
-			 mx_flag (build1 (INDIRECT_REF, mf_cache_struct_type,
+    t1 = mudflap_mark (build (COMPONENT_REF, mf_uintptr_type,
+			 mudflap_mark (build1 (INDIRECT_REF, mf_cache_struct_type,
 			                  t1_3_1)),
 		         TREE_CHAIN (TYPE_FIELDS (mf_cache_struct_type))));
 
@@ -801,7 +824,7 @@ mx_xfn_indirect_ref (t, continue_p, data
      instrumentation code.  NB: This check is done second, in case the
      same node is marked verboten as well as mudflapped.  The former
      takes priority, and is meant to prevent further traversal.  */
-  if (TREE_MUDFLAPPED_P (*t))
+  if (mudflap_marked_p (*t))
     return NULL_TREE;
 
   /* Process some node types.  */
@@ -839,9 +862,9 @@ mx_xfn_indirect_ref (t, continue_p, data
 	if (TREE_CODE (arg) == COMPONENT_REF
 	    && TREE_CODE (TREE_OPERAND (arg, 0)) == INDIRECT_REF)
 	  {
-	    mx_flag (TREE_OPERAND (arg, 0));
-	    mx_flag (arg);
-	    mx_flag (*t);
+	    mudflap_mark (TREE_OPERAND (arg, 0));
+	    mudflap_mark (arg);
+	    mudflap_mark (*t);
 	  }
       }
       break;
@@ -891,14 +914,14 @@ mx_xfn_indirect_ref (t, continue_p, data
 								integer_one_node,
 								offset_expr))))));
 
-	    mx_flag (TREE_OPERAND (base_array, 0));
-	    mx_flag (base_array);
+	    mudflap_mark (TREE_OPERAND (base_array, 0));
+	    mudflap_mark (base_array);
 	  }
 	else /* default: possibly a VAR_DECL */
 	  {
-	    check_ptr = mx_flag (build1 (ADDR_EXPR, 
+	    check_ptr = mudflap_mark (build1 (ADDR_EXPR, 
 					 base_ptr_type, 
-					 mx_flag (build (ARRAY_REF, 
+					 mudflap_mark (build (ARRAY_REF, 
 							 base_obj_type, 
 							 base_array,
 							 integer_zero_node))));
@@ -911,9 +934,9 @@ mx_xfn_indirect_ref (t, continue_p, data
 						   offset_expr))));
 	  }
 
-	value_ptr = mx_flag (build1 (ADDR_EXPR,
+	value_ptr = mudflap_mark (build1 (ADDR_EXPR,
 				     base_ptr_type,
-				     mx_flag (*t)));
+				     mudflap_mark (*t)));
 	walk_tree (& value_ptr, mf_mostly_copy_tree_r, NULL, NULL);
 
 	/* As an optimization, omit checking if the base object is
@@ -943,7 +966,7 @@ mx_xfn_indirect_ref (t, continue_p, data
 	    tmp = mf_build_check_statement_for (value_ptr, check_ptr, check_size,
 						tree_role, check_decls,
 						last_filename, last_lineno);
-	    *t = mx_flag (build1 (INDIRECT_REF, base_obj_type, tmp));
+	    *t = mudflap_mark (build1 (INDIRECT_REF, base_obj_type, tmp));
 	  }
       }
       break;
@@ -966,7 +989,7 @@ mx_xfn_indirect_ref (t, continue_p, data
 	/* Prevent this transform's reapplication to this tree node.
 	   Note that we do not prevent recusion in walk_tree toward
 	   subtrees of this node, in case of nested pointer expressions.  */
-      mx_flag (*t);
+      mudflap_mark (*t);
       break;
 
     case COMPONENT_REF:
@@ -994,8 +1017,8 @@ mx_xfn_indirect_ref (t, continue_p, data
 					  last_filename, last_lineno);
 	  
 	  /* Don't instrument the nested INDIRECT_REF. */ 
-	  mx_flag (TREE_OPERAND (*t, 0));
-	  mx_flag (*t);
+	  mudflap_mark (TREE_OPERAND (*t, 0));
+	  mudflap_mark (*t);
 	}
       break;
 
@@ -1021,8 +1044,8 @@ mx_xfn_indirect_ref (t, continue_p, data
 					  last_filename, last_lineno);
 	  
 	  /* Don't instrument the nested INDIRECT_REF. */ 
-	  mx_flag (TREE_OPERAND (*t, 0));
-	  mx_flag (*t);
+	  mudflap_mark (TREE_OPERAND (*t, 0));
+	  mudflap_mark (*t);
 	}
       break;
     }
@@ -1074,14 +1097,14 @@ mx_register_decls (decl, compound_expr)
 	  (! TREE_STATIC (decl)) && /* auto variable */
 	  (! DECL_EXTERNAL (decl)) && /* not extern variable */
 	  (COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (decl))) && /* complete type */
-	  (! TREE_MUDFLAPPED_P (decl)) && /* not already processed */
+	  (! mudflap_marked_p (decl)) && /* not already processed */
 	  (TREE_ADDRESSABLE (decl))) /* has address taken */
 	{
 	  /* (& VARIABLE, sizeof (VARIABLE)) */
 	  tree unregister_fncall_params =
 	    tree_cons (NULL_TREE,
 		       convert (ptr_type_node, 
-				mx_flag (build1 (ADDR_EXPR, 
+				mudflap_mark (build1 (ADDR_EXPR, 
 						 build_pointer_type (TREE_TYPE (decl)),
 						 decl))),
 		       tree_cons (NULL_TREE, 
@@ -1098,7 +1121,7 @@ mx_register_decls (decl, compound_expr)
 	  tree register_fncall_params =
 	    tree_cons (NULL_TREE,
 		   convert (ptr_type_node, 
-			    mx_flag (build1 (ADDR_EXPR, 
+			    mudflap_mark (build1 (ADDR_EXPR, 
 					     build_pointer_type (TREE_TYPE (decl)),
 					     decl))),
 		       tree_cons (NULL_TREE, 
@@ -1119,7 +1142,7 @@ mx_register_decls (decl, compound_expr)
 	  add_tree (register_fncall, & initially_stmts);
 	  add_tree (unregister_fncall, & finally_stmts);
 	  
-	  mx_flag (decl);
+	  mudflap_mark (decl);
 	}
 
       decl = TREE_CHAIN (decl);
@@ -1232,7 +1255,7 @@ mudflap_enqueue_decl (obj, label)
      tree obj;
      const char *label;
 {
-  if (TREE_MUDFLAPPED_P (obj))
+  if (mudflap_marked_p (obj))
     return;
 
   /* We don't need to process variable decls that are internally
@@ -1317,7 +1340,7 @@ mudflap_enqueue_constant (obj, label)
   tree call_stmt;
   tree object_size;
 
-  if (TREE_MUDFLAPPED_P (obj))
+  if (mudflap_marked_p (obj))
     return;
 
   object_size = (TREE_CODE (obj) == STRING_CST)
@@ -1344,11 +1367,11 @@ mudflap_enqueue_constant (obj, label)
     (TREE_CODE (obj) == STRING_CST)
     ? mflang_register_call (label, object_size,
 			    build_int_2 (4, 0), /* __MF_TYPE_STATIC */
-			    mx_flag (fix_string_type
+			    mudflap_mark (fix_string_type
 				     (build_string (15, "string literal"))))
     : mflang_register_call (label, object_size,
 			    build_int_2 (4, 0), /* __MF_TYPE_STATIC */
-			    mx_flag (fix_string_type
+			    mudflap_mark (fix_string_type
 				     (build_string (9, "constant"))));
     
   /* Link this call into the chain. */
Index: tree-mudflap.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.h,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 tree-mudflap.h
--- tree-mudflap.h	13 Jan 2003 23:14:44 -0000	1.1.2.3
+++ tree-mudflap.h	5 Jun 2003 16:58:39 -0000
@@ -22,10 +22,15 @@ Software Foundation, 59 Temple Place - S
 #ifndef TREE_MUDFLAP_H
 #define TREE_MUDFLAP_H
 
+/* Instrumentation. */
 extern void mudflap_c_function PARAMS ((tree));
 extern void mudflap_enqueue_decl PARAMS ((tree, const char *));
 extern void mudflap_enqueue_constant PARAMS ((tree, const char *));
 extern void mudflap_finish_file PARAMS ((void));
+
+/* Tree node marking. */
+extern int mudflap_marked_p PARAMS ((tree));
+extern tree mudflap_mark PARAMS ((tree));
 
 /* To be provided by a front-end interface module. */
 extern tree mflang_lookup_decl PARAMS ((const char *));
Index: cp/cp-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Attic/cp-mudflap.c,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 cp-mudflap.c
--- cp/cp-mudflap.c	3 Jun 2003 16:51:52 -0000	1.1.2.4
+++ cp/cp-mudflap.c	5 Jun 2003 16:58:39 -0000
@@ -45,24 +45,6 @@ Software Foundation, 59 Temple Place - S
 
 /* ------------------------------------------------------------------------ */
 
-static tree mx_flag PARAMS ((tree));
-
-/* XXX: copied from tree-mudflap.c */
-static tree
-mx_flag (t)
-     tree t;
-{
-  if (!t)
-    abort ();
-#define MARK_TREE_MUDFLAPPED(tree)  do { TREE_VISITED (tree) = 1; } while (0)
-  MARK_TREE_MUDFLAPPED(t);
-  return t;
-}
-
-
-
-/* ------------------------------------------------------------------------ */
-
 
 
 /* Initialize the global tree nodes that correspond to mf-runtime.h
@@ -105,7 +87,7 @@ mflang_register_call (label, regsize, re
 
   /* See gcc-checker's c-bounds.c (declare_private_statics)  */
   decltype = build_array_type (char_type_node, build_index_type (integer_zero_node));
-  decl = mx_flag (build_decl (VAR_DECL, get_identifier (label), decltype));
+  decl = mudflap_mark (build_decl (VAR_DECL, get_identifier (label), decltype));
 
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
@@ -122,7 +104,7 @@ mflang_register_call (label, regsize, re
 
   call_params = tree_cons (NULL_TREE,
 			   convert (ptr_type_node, 
-				    mx_flag (build1 (ADDR_EXPR, 
+				    mudflap_mark (build1 (ADDR_EXPR, 
 						     build_pointer_type (TREE_TYPE (decl)),
 						     decl))),
 			   tree_cons (NULL_TREE, 



More information about the Gcc-patches mailing list