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]

[lto-streamer, lto][patch] clear TREE_PURPOSE


This patch fixes the compilation of

-------------------
class A  {
};
void f( A owner = A())
{
}
-------------------

It is based on http://gcc.gnu.org/ml/gcc-patches/2008-03/msg00349.html,
but uses a langhook for doing the cleanup.

OK for lto and lto-streamer if bootstraps and tests are OK?

This small part looks safe. Should I try to port it to trunk?

cp part:

2008-06-09 Rafael Espindola  <espindola@google.com>
	based on http://gcc.gnu.org/ml/gcc-patches/2008-03/msg00349.html

	* cp-objcp-common.h (LANG_HOOKS_RESET_LANG_SPECIFICS): New.
	* cp-tree.h (cp_reset_lang_specifics): New.
	* tree.c (cp_reset_lang_specifics): New.


the rest:
2008-06-09 Rafael Espindola  <espindola@google.com>
	based on http://gcc.gnu.org/ml/gcc-patches/2008-03/msg00349.html

	* langhooks-def.h (LANG_HOOKS_RESET_LANG_SPECIFICS): New.
	(LANG_HOOKS_INITIALIZER): add LANG_HOOKS_RESET_LANG_SPECIFICS.
	* langhooks.h (reset_lang_specifics): New.
	* lto-section-out.c (produce_asm_for_decls): Call free_lang_specifics.
	* tree.c (uid2type_map): New.
	(insert_type_to_uid_type_map): New.
	(uid_type_map_eq): New.
	(uid_type_map_hash): New.
	(init_ttree): Initialize uid2type_map.
	(make_node_stat): Call insert_type_to_uid_type_map.
	(copy_node_stat): Call insert_type_to_uid_type_map.
	(reset_type_lang_specific): New.
	(free_lang_specifics): New.
	* tree.h (free_lang_specifics) New.

Cheers,
-- 
Rafael Avila de Espindola

Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland

Registered in Dublin, Ireland
Registration Number: 368047
diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h
index b2b8405..a12ed81 100644
--- a/gcc/cp/cp-objcp-common.h
+++ b/gcc/cp/cp-objcp-common.h
@@ -30,6 +30,8 @@ extern tree objcp_tsubst_copy_and_build (tree, tree, tsubst_flags_t,
    specific to C++ or ObjC++ go in cp/cp-lang.c and objcp/objcp-lang.c,
    respectively.  */
 
+#undef LANG_HOOKS_RESET_LANG_SPECIFICS
+#define LANG_HOOKS_RESET_LANG_SPECIFICS cp_reset_lang_specifics
 #undef LANG_HOOKS_TREE_SIZE
 #define LANG_HOOKS_TREE_SIZE cp_tree_size
 #undef LANG_HOOKS_FINISH
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 0c3d0dd..8e47225 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4684,6 +4684,7 @@ extern tree finish_decltype_type                (tree, bool);
 extern tree finish_trait_expr			(enum cp_trait_kind, tree, tree);
 
 /* in tree.c */
+void cp_reset_lang_specifics (tree t);
 extern void lang_check_failed			(const char *, int,
 						 const char *) ATTRIBUTE_NORETURN;
 extern tree stabilize_expr			(tree, tree *);
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index ff37220..688e9c3 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2748,6 +2748,22 @@ cast_valid_in_integral_constant_expression_p (tree type)
 	  || type == error_mark_node);
 }
 
+void
+cp_reset_lang_specifics (tree t)
+{
+  if (TREE_CODE (t) == METHOD_TYPE
+      || TREE_CODE (t) == FUNCTION_TYPE)
+    {
+      /* Default args are not interesting anymore.  */
+      tree argtypes = TYPE_ARG_TYPES (t);
+      while (argtypes)
+        {
+	  TREE_PURPOSE (argtypes) = 0;
+	  argtypes = TREE_CHAIN (argtypes);
+	}
+    }
+}
+
 
 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
 /* Complain that some language-specific thing hanging off a tree
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index aae4640..6a68663 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -109,6 +109,7 @@ extern void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *,
 #define LANG_HOOKS_DWARF_NAME		lhd_dwarf_name
 #define LANG_HOOKS_GET_CALLEE_FNDECL	lhd_return_null_const_tree
 #define LANG_HOOKS_EXPR_SIZE		lhd_expr_size
+#define LANG_HOOKS_RESET_LANG_SPECIFICS	lhd_do_nothing_t
 #define LANG_HOOKS_TREE_SIZE		lhd_tree_size
 #define LANG_HOOKS_TYPES_COMPATIBLE_P	lhd_types_compatible_p
 #define LANG_HOOKS_BUILTIN_FUNCTION	lhd_builtin_function
@@ -226,6 +227,7 @@ extern tree lhd_make_node (enum tree_code);
 #define LANG_HOOKS_INITIALIZER { \
   LANG_HOOKS_NAME, \
   LANG_HOOKS_IDENTIFIER_SIZE, \
+  LANG_HOOKS_RESET_LANG_SPECIFICS, \
   LANG_HOOKS_TREE_SIZE, \
   LANG_HOOKS_INIT_OPTIONS, \
   LANG_HOOKS_INITIALIZE_DIAGNOSTICS, \
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index 6a54b01..f37a41d 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -223,6 +223,9 @@ struct lang_hooks
      identifier nodes long enough for the language-specific slots.  */
   size_t identifier_size;
 
+  /* Remove any parts of the tree that are used only by the FE. */
+  void (*reset_lang_specifics) (tree);
+
   /* Determines the size of any language-specific tcc_constant or
      tcc_exceptional nodes.  Since it is called from make_node, the
      only information available is the tree code.  Expected to die
diff --git a/gcc/lto-section-out.c b/gcc/lto-section-out.c
index 8095f37..d68c761 100644
--- a/gcc/lto-section-out.c
+++ b/gcc/lto-section-out.c
@@ -585,6 +585,8 @@ produce_asm_for_decls (void)
   section *decl_section = lto_get_section (LTO_section_decls, NULL);
   struct output_block *ob = create_output_block (LTO_section_decls);
 
+  free_lang_specifics ();
+
   ob->global = true;
   ob->main_hash_table = htab_create (37, lto_hash_global_slot_node,
 				     lto_eq_global_slot_node, free);
diff --git a/gcc/tree.c b/gcc/tree.c
index bfede06..011a9e7 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -110,6 +110,9 @@ static GTY(()) int next_decl_uid;
 /* Unique id for next type created.  */
 static GTY(()) int next_type_uid = 1;
 
+static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
+     htab_t uid2type_map;
+
 /* Since we cannot rehash a type after it is in the table, we have to
    keep the hash code.  */
 
@@ -209,6 +212,39 @@ const char * const omp_clause_code_name[] =
 
 /* Init tree.c.  */
 
+static void
+insert_type_to_uid_type_map (tree node)
+{
+  void **slot;
+  struct tree_type key;
+
+  key.uid = TYPE_UID (node);
+  slot = htab_find_slot_with_hash (uid2type_map,
+				   &key, TYPE_UID (node), INSERT);
+
+#if 1
+  gcc_assert (!*slot);
+#endif
+
+  *(tree *)slot = node;
+}
+
+static int
+uid_type_map_eq (const void *va, const void *vb)
+{
+  const_tree a = (const_tree) va;
+  const_tree b = (const_tree) vb;
+  return (a->type.uid == b->type.uid);
+}
+
+/* Hash a tree in a uid_decl_map.  */
+
+static unsigned int
+uid_type_map_hash (const void *item)
+{
+  return ((const_tree)item)->type.uid;
+}
+
 void
 init_ttree (void)
 {
@@ -231,6 +267,9 @@ init_ttree (void)
   
   int_cst_node = make_node (INTEGER_CST);
 
+  uid2type_map = htab_create_ggc (4093, uid_type_map_hash,
+				  uid_type_map_eq, NULL);
+
   tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
   tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
   tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
@@ -612,6 +651,7 @@ make_node_stat (enum tree_code code MEM_STAT_DECL)
 
       /* We have not yet computed the alias set for this type.  */
       TYPE_ALIAS_SET (t) = -1;
+      insert_type_to_uid_type_map (t);
       break;
 
     case tcc_constant:
@@ -716,6 +756,7 @@ copy_node_stat (tree node MEM_STAT_DECL)
 	  TYPE_CACHED_VALUES_P (t) = 0;
 	  TYPE_CACHED_VALUES (t) = NULL_TREE;
 	}
+      insert_type_to_uid_type_map (t);
     }
 
   return t;
@@ -3733,6 +3774,20 @@ build_type_attribute_variant (tree ttype, tree attribute)
 					    TYPE_QUALS (ttype));
 }
 
+static int
+reset_type_lang_specific (void **slot, void *unused ATTRIBUTE_UNUSED)
+{
+  tree decl = *(tree*)slot;
+  lang_hooks.reset_lang_specifics (decl);
+  return 1;
+}
+
+void
+free_lang_specifics (void)
+{
+  htab_traverse (uid2type_map, reset_type_lang_specific, NULL);
+}
+
 /* Return nonzero if IDENT is a valid name for attribute ATTR,
    or zero if not.
 
diff --git a/gcc/tree.h b/gcc/tree.h
index 4b091d6..c78c2e6 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4713,6 +4713,7 @@ function_args_iter_next (function_args_iterator *i)
 
 
 /* In tree.c */
+extern void free_lang_specifics (void);
 extern unsigned crc32_string (unsigned, const char *);
 extern void clean_symbol_name (char *);
 extern tree get_file_function_name (const char *);

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