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]

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


> I will take another look to see if cp_finish_decl is a good place.

It works. I also tested this patch with


extern int a;
void f(void);
int b;
int g(int c)
{
  f();
  b = c;
  return a;
}

and a hack to always print the warning. We print warnings for a, b,f and g.

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

	* cp-tree.h (lang_identifier): Add ABI_WARNING.
	(IDENTIFIER_EMIT_ABI_WARNING_P): New.
	* decl.c (cp_finish_decl): Print warning for ABI changes.
	* 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.


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

	* g++.dg/abi/mangle32.C: New.

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 849fdc7..397bb7e 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/decl.c b/gcc/cp/decl.c
index 707bd33..9a5b81f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5807,6 +5807,11 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 	    TREE_READONLY (decl) = 1;
 	}
 
+      if (warn_abi
+	  && IDENTIFIER_EMIT_ABI_WARNING_P (DECL_ASSEMBLER_NAME (decl)))
+	warning (OPT_Wabi, "the mangled name of %qD will change in a future "
+		 "version of GCC", decl);
+
       make_rtl_for_nonlocal_decl (decl, init, asmspec);
 
       /* Check for abstractness of the type. Notice that there is no
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 5f2ace0..739ab42 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,10 @@ 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);
+  if (abi_warning)
+    *abi_warning = G.need_abi_warning;
 
   /* Clear all the substitutions.  */
   VEC_truncate (tree, G.substitutions, 0);
@@ -2734,18 +2732,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 +2771,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 +2782,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 +2794,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.  */
@@ -2810,7 +2810,7 @@ mangle_type_string (const tree type)
 
   start_mangling (type);
   write_type (type);
-  result = finish_mangling (/*warn=*/false);
+  result = finish_mangling (NULL);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
   return result;
@@ -2835,7 +2835,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 (NULL);
 
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_special_for_type = %s\n\n",
@@ -2906,7 +2906,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 (NULL);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n",
 	     IDENTIFIER_POINTER (result));
@@ -2985,7 +2985,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 (NULL);
   if (DEBUG_MANGLE)
     fprintf (stderr, "mangle_thunk = %s\n\n", IDENTIFIER_POINTER (result));
   return result;
@@ -3068,7 +3068,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 (NULL);
 }
 
 /* Return an identifier for the name of a temporary variable used to
@@ -3081,7 +3081,7 @@ mangle_ref_init_variable (const tree variable)
   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 (NULL);
 }
 
 
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 337b637..4800941 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3281,6 +3281,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--;
 }
 
diff --git a/gcc/testsuite/g++.dg/abi/mangle32.C b/gcc/testsuite/g++.dg/abi/mangle32.C
new file mode 100644
index 0000000..23ae865
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/mangle32.C
@@ -0,0 +1,32 @@
+// { dg-do compile }
+// { dg-options "-fabi-version=1 -Wabi" }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 30 Nov 2003 <nathan@codesourcery.com>
+
+// PR 13241
+// mangled template arguments that are external objects incorrectly
+
+extern "C" void Foo ();
+namespace NMS 
+{
+  extern "C" int V;
+}
+
+template <void (*)()> struct S {};
+template <int *> struct T {};
+
+
+typedef void f_type (S<Foo>);
+
+void f (S<Foo>);   // { dg-warning "mangled name" }
+
+void g(f_type);  // { dg-warning "mangled name" }
+
+void h()
+{
+  f_type *a;
+  a = f;
+  g(a);
+}
+

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