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]

[trunk][patch] Don't print warnings in mangle_decl


mangle_decl is called lazily via DECL_ASSEMBLER_NAME. It should not
assume it knows the context it is called from. In particular, it
should not print warnings.

This patch changes mangle.c so that it only flags that a warning is
needed. The warning is then printed in a know context.

This patch is already is the LTO branch and is needed by a subsequent
patch to remove the comdat_group langhook.

Bootstrapped on linux x86-64. Running the tests now. OK for trunk if
the tests are OK?

2009-04-01  Rafael Avila de Espindola  <espindola@google.com>

        * cp-tree.h (lang_identifier): Add ABI_WARNING.
	(IDENTIFIER_EMIT_ABI_WARNING_P): New.
	* mangle.c (finish_mangling_internal): Don't print warning. Set
        ABI_WARNING if one is needed. Update all callers.
	* semantics.c (expand_or_defer_fn): Print warning for ABI changes.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 9878d9d..c1a3343 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -226,6 +226,7 @@ struct lang_identifier GTY(())
   cxx_binding *bindings;
   tree class_template_info;
   tree label_value;
+  bool abi_warning;
 };
 
 /* In an IDENTIFIER_NODE, nonzero if this identifier is actually a
@@ -394,6 +395,10 @@ typedef enum cp_id_kind
 #define IDENTIFIER_TEMPLATE(NODE)	\
   (LANG_IDENTIFIER_CAST (NODE)->class_template_info)
 
+/* True if we should emit an ABI warning for this identifier. */
+#define IDENTIFIER_EMIT_ABI_WARNING_P(NODE)	\
+  (LANG_IDENTIFIER_CAST (NODE)->abi_warning)
+
 /* The IDENTIFIER_BINDING is the innermost cxx_binding for the
     identifier.  It's PREVIOUS is the next outermost binding.  Each
     VALUE field is a DECL for the associated declaration.  Thus,
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 5f2ace0..3657908 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -210,12 +210,12 @@ static int discriminator_for_string_literal (tree, tree);
 static void write_discriminator (const int);
 static void write_local_name (const tree, const tree, const tree);
 static void dump_substitution_candidates (void);
-static tree mangle_decl_string (const tree);
+static tree mangle_decl_string (const tree, bool *);
 
 /* Control functions.  */
 
 static inline void start_mangling (const tree);
-static inline const char *finish_mangling (const bool);
+static inline const char *finish_mangling (bool *);
 static tree mangle_special_for_type (const tree, const char *);
 
 /* Foreign language functions.  */
@@ -2716,12 +2716,9 @@ start_mangling (const tree entity)
    warning.  */
 
 static void
-finish_mangling_internal (const bool warn)
+finish_mangling_internal (bool *abi_warning)
 {
-  if (warn_abi && warn && G.need_abi_warning)
-    warning (OPT_Wabi, "the mangled name of %qD will change in a future "
-	     "version of GCC",
-	     G.entity);
+  *abi_warning = G.need_abi_warning;
 
   /* Clear all the substitutions.  */
   VEC_truncate (tree, G.substitutions, 0);
@@ -2734,18 +2731,18 @@ finish_mangling_internal (const bool warn)
 /* Like finish_mangling_internal, but return the mangled string.  */
 
 static inline const char *
-finish_mangling (const bool warn)
+finish_mangling (bool *abi_warning)
 {
-  finish_mangling_internal (warn);
+  finish_mangling_internal (abi_warning);
   return (const char *) obstack_finish (mangle_obstack);
 }
 
 /* Like finish_mangling_internal, but return an identifier.  */
 
 static tree
-finish_mangling_get_identifier (const bool warn)
+finish_mangling_get_identifier (bool *abi_warning)
 {
-  finish_mangling_internal (warn);
+  finish_mangling_internal (abi_warning);
   /* Don't obstack_finish here, and the next start_mangling will
      remove the identifier.  */
   return get_identifier ((const char *) name_base);
@@ -2773,7 +2770,7 @@ init_mangle (void)
 /* Generate the mangled name of DECL.  */
 
 static tree
-mangle_decl_string (const tree decl)
+mangle_decl_string (const tree decl, bool *abi_warning)
 {
   tree result;
 
@@ -2784,7 +2781,7 @@ mangle_decl_string (const tree decl)
   else
     write_mangled_name (decl, true);
 
-  result = finish_mangling_get_identifier (/*warn=*/true);
+  result = finish_mangling_get_identifier (abi_warning);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_decl_string = '%s'\n\n",
 	     IDENTIFIER_POINTER (result));
@@ -2796,9 +2793,11 @@ mangle_decl_string (const tree decl)
 void
 mangle_decl (const tree decl)
 {
-  tree id = mangle_decl_string (decl);
+  bool abi_warning;
+  tree id = mangle_decl_string (decl, &abi_warning);
   id = targetm.mangle_decl_assembler_name (decl, id);
   SET_DECL_ASSEMBLER_NAME (decl, id);
+  IDENTIFIER_EMIT_ABI_WARNING_P (DECL_ASSEMBLER_NAME (decl)) = abi_warning;
 }
 
 /* Generate the mangled representation of TYPE.  */
@@ -2807,10 +2806,11 @@ const char *
 mangle_type_string (const tree type)
 {
   const char *result;
+  bool abi_warning;
 
   start_mangling (type);
   write_type (type);
-  result = finish_mangling (/*warn=*/false);
+  result = finish_mangling (&abi_warning);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
   return result;
@@ -2824,6 +2824,7 @@ static tree
 mangle_special_for_type (const tree type, const char *code)
 {
   tree result;
+  bool abi_warning;
 
   /* We don't have an actual decl here for the special component, so
      we can't just process the <encoded-name>.  Instead, fake it.  */
@@ -2835,7 +2836,7 @@ mangle_special_for_type (const tree type, const char *code)
 
   /* Add the type.  */
   write_type (type);
-  result = finish_mangling_get_identifier (/*warn=*/false);
+  result = finish_mangling_get_identifier (&abi_warning);
 
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_special_for_type = %s\n\n",
@@ -2896,6 +2897,7 @@ tree
 mangle_ctor_vtbl_for_type (const tree type, const tree binfo)
 {
   tree result;
+  bool abi_warning;
 
   start_mangling (type);
 
@@ -2906,7 +2908,7 @@ mangle_ctor_vtbl_for_type (const tree type, const tree binfo)
   write_char ('_');
   write_type (BINFO_TYPE (binfo));
 
-  result = finish_mangling_get_identifier (/*warn=*/false);
+  result = finish_mangling_get_identifier (&abi_warning);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n",
 	     IDENTIFIER_POINTER (result));
@@ -2953,6 +2955,7 @@ mangle_thunk (tree fn_decl, const int this_adjusting, tree fixed_offset,
 	      tree virtual_offset)
 {
   tree result;
+  bool abi_warning;
 
   start_mangling (fn_decl);
 
@@ -2985,7 +2988,7 @@ mangle_thunk (tree fn_decl, const int this_adjusting, tree fixed_offset,
   /* Scoped name.  */
   write_encoding (fn_decl);
 
-  result = finish_mangling_get_identifier (/*warn=*/false);
+  result = finish_mangling_get_identifier (&abi_warning);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_thunk = %s\n\n", IDENTIFIER_POINTER (result));
   return result;
@@ -3060,6 +3063,7 @@ mangle_conv_op_name_for_type (const tree type)
 tree
 mangle_guard_variable (const tree variable)
 {
+  bool abi_warning;
   start_mangling (variable);
   write_string ("_ZGV");
   if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
@@ -3068,7 +3072,7 @@ mangle_guard_variable (const tree variable)
     write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
   else
     write_name (variable, /*ignore_local_scope=*/0);
-  return finish_mangling_get_identifier (/*warn=*/false);
+  return finish_mangling_get_identifier (&abi_warning);
 }
 
 /* Return an identifier for the name of a temporary variable used to
@@ -3078,10 +3082,11 @@ mangle_guard_variable (const tree variable)
 tree
 mangle_ref_init_variable (const tree variable)
 {
+  bool abi_warning;
   start_mangling (variable);
   write_string ("_ZGR");
   write_name (variable, /*ignore_local_scope=*/0);
-  return finish_mangling_get_identifier (/*warn=*/false);
+  return finish_mangling_get_identifier (&abi_warning);
 }
 
 
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 038715b..de603e3 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3260,6 +3260,11 @@ expand_or_defer_fn (tree fn)
   /* Expand or defer, at the whim of the compilation unit manager.  */
   cgraph_finalize_function (fn, function_depth > 1);
 
+  if (warn_abi && IDENTIFIER_EMIT_ABI_WARNING_P (DECL_ASSEMBLER_NAME (fn)))
+    warning (OPT_Wabi, "the mangled name of %qD will change in a future "
+	     "version of GCC",
+	     fn);
+
   function_depth--;
 }
 

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