C++ PATCH: -Wabi warnings on the branch
Mark Mitchell
mark@codesourcery.com
Fri Oct 18 01:12:00 GMT 2002
This patch moves over some -Wabi warnings from the mainline to the
branch.
Tested on i686-pc-linux-gnu, applied on the branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-10-17 Mark Mitchell <mark@codesourcery.com>
* mangle.c (globals): Add entity and need_abi_warning.
(write_prefix): Likewise.
(write_template_prefix): Likewise.
(start_mangling): Add entity parameter.
(finish_mangling): Warn about names whose mangling will change.
(mangle_decl_string): Adjust.
(mangle_type_string): Likewise.
(mangle_special_for_type): Likewise.
(mangle_ctor_vtbl_for_type): Likewise.
(mangle_thunk): Likewise.
(mangle_guard_variable): Likewise.
(mangle_ref_init_variable): Likewise.
2002-10-18 Mark Mitchell <mark@codesourcery.com>
* g++.dg/abi/mangle11.C: New test.
* g++.dg/abi/mangle14.C: New test.
* g++.dg/abi/mangle17.C: New test.
Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.44.2.5.2.1
diff -c -5 -p -r1.44.2.5.2.1 mangle.c
*** cp/mangle.c 26 Jul 2002 23:22:58 -0000 1.44.2.5.2.1
--- cp/mangle.c 18 Oct 2002 08:07:26 -0000
*************** static struct globals
*** 91,100 ****
--- 91,107 ----
struct obstack name_obstack;
/* An array of the current substitution candidates, in the order
we've seen them. */
varray_type substitutions;
+
+ /* The entity that is being mangled. */
+ tree entity;
+
+ /* True if the mangling will be different in a future version of the
+ ABI. */
+ bool need_abi_warning;
} G;
/* Indices into subst_identifiers. These are identifiers used in
special substitution rules. */
typedef enum
*************** static void write_local_name PARAMS ((tr
*** 184,195 ****
static void dump_substitution_candidates PARAMS ((void));
static const char *mangle_decl_string PARAMS ((tree));
/* Control functions. */
! static inline void start_mangling PARAMS ((void));
! static inline const char *finish_mangling PARAMS ((void));
static tree mangle_special_for_type PARAMS ((tree, const char *));
/* Foreign language functions. */
static void write_java_integer_type_codes PARAMS ((tree));
--- 191,202 ----
static void dump_substitution_candidates PARAMS ((void));
static const char *mangle_decl_string PARAMS ((tree));
/* Control functions. */
! static inline void start_mangling PARAMS ((tree));
! static inline const char *finish_mangling PARAMS ((bool));
static tree mangle_special_for_type PARAMS ((tree, const char *));
/* Foreign language functions. */
static void write_java_integer_type_codes PARAMS ((tree));
*************** write_prefix (node)
*** 882,891 ****
--- 889,902 ----
decl = TYPE_NAME (node);
if (CLASSTYPE_TEMPLATE_ID_P (node))
template_info = CLASSTYPE_TEMPLATE_INFO (node);
}
+ /* In G++ 3.2, the name of the template parameter was used. */
+ if (TREE_CODE (node) == TEMPLATE_TYPE_PARM)
+ G.need_abi_warning = true;
+
if (template_info != NULL)
/* Templated. */
{
write_template_prefix (decl);
write_template_args (TI_ARGS (template_info));
*************** write_template_prefix (node)
*** 953,962 ****
--- 964,977 ----
substitution = template;
if (find_substitution (substitution))
return;
+ /* In G++ 3.2, the name of the template template parameter was used. */
+ if (TREE_CODE (TREE_TYPE (template)) == TEMPLATE_TEMPLATE_PARM)
+ G.need_abi_warning = true;
+
write_prefix (context);
write_unqualified_name (decl);
add_substitution (substitution);
}
*************** write_expression (expr)
*** 1821,1830 ****
--- 1836,1849 ----
/* Handle literals. */
else if (TREE_CODE_CLASS (code) == 'c')
write_template_arg_literal (expr);
else if (DECL_P (expr))
{
+ /* G++ 3.2 incorrectly mangled non-type template arguments of
+ enumeration type using their names. */
+ if (code == CONST_DECL)
+ G.need_abi_warning = 1;
write_char ('L');
write_mangled_name (expr);
write_char ('E');
}
else if (TREE_CODE (expr) == SIZEOF_EXPR
*************** write_expression (expr)
*** 1876,1886 ****
case SCOPE_REF:
write_type (TREE_OPERAND (expr, 0));
if (TREE_CODE (TREE_OPERAND (expr, 1)) == IDENTIFIER_NODE)
write_source_name (TREE_OPERAND (expr, 1));
else
! write_encoding (TREE_OPERAND (expr, 1));
break;
default:
for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
write_expression (TREE_OPERAND (expr, i));
--- 1895,1910 ----
case SCOPE_REF:
write_type (TREE_OPERAND (expr, 0));
if (TREE_CODE (TREE_OPERAND (expr, 1)) == IDENTIFIER_NODE)
write_source_name (TREE_OPERAND (expr, 1));
else
! {
! /* G++ 3.2 incorrectly put out both the "sr" code and
! the nested name of the qualified name. */
! G.need_abi_warning = 1;
! write_encoding (TREE_OPERAND (expr, 1));
! }
break;
default:
for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
write_expression (TREE_OPERAND (expr, i));
*************** write_template_arg (node)
*** 1981,1990 ****
--- 2005,2018 ----
else if (code == TEMPLATE_DECL)
/* A template appearing as a template arg is a template template arg. */
write_template_template_arg (node);
else if (DECL_P (node))
{
+ /* G++ 3.2 incorrectly mangled non-type template arguments of
+ enumeration type using their names. */
+ if (code == CONST_DECL)
+ G.need_abi_warning = 1;
write_char ('L');
write_char ('Z');
write_encoding (node);
write_char ('E');
}
*************** write_substitution (seq_id)
*** 2150,2169 ****
}
/* Start mangling a new name or type. */
static inline void
! start_mangling ()
{
obstack_free (&G.name_obstack, obstack_base (&G.name_obstack));
}
/* Done with mangling. Return the generated mangled name. */
static inline const char *
! finish_mangling ()
{
/* Clear all the substitutions. */
VARRAY_POP_ALL (G.substitutions);
/* Null-terminate the string. */
write_char ('\0');
--- 2178,2204 ----
}
/* Start mangling a new name or type. */
static inline void
! start_mangling (tree entity)
{
+ G.entity = entity;
+ G.need_abi_warning = false;
obstack_free (&G.name_obstack, obstack_base (&G.name_obstack));
}
/* Done with mangling. Return the generated mangled name. */
static inline const char *
! finish_mangling (bool warn)
{
+ if (warn_abi && warn && G.need_abi_warning)
+ warning ("the mangled name of `%D' will change in a future "
+ "version of GCC",
+ G.entity);
+
/* Clear all the substitutions. */
VARRAY_POP_ALL (G.substitutions);
/* Null-terminate the string. */
write_char ('\0');
*************** static const char *
*** 2195,2205 ****
mangle_decl_string (decl)
tree decl;
{
const char *result;
! start_mangling ();
if (TREE_CODE (decl) == TYPE_DECL)
write_type (TREE_TYPE (decl));
else if (/* The names of `extern "C"' functions are not mangled. */
(DECL_EXTERN_C_FUNCTION_P (decl)
--- 2230,2240 ----
mangle_decl_string (decl)
tree decl;
{
const char *result;
! start_mangling (decl);
if (TREE_CODE (decl) == TYPE_DECL)
write_type (TREE_TYPE (decl));
else if (/* The names of `extern "C"' functions are not mangled. */
(DECL_EXTERN_C_FUNCTION_P (decl)
*************** mangle_decl_string (decl)
*** 2222,2232 ****
we should never actually output it. So, we append some
characters the assembler won't like. */
write_string (" *INTERNAL* ");
}
! result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_decl_string = '%s'\n\n", result);
return result;
}
--- 2257,2267 ----
we should never actually output it. So, we append some
characters the assembler won't like. */
write_string (" *INTERNAL* ");
}
! result = finish_mangling (/*warn=*/true);
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_decl_string = '%s'\n\n", result);
return result;
}
*************** const char *
*** 2247,2259 ****
mangle_type_string (type)
tree type;
{
const char *result;
! start_mangling ();
write_type (type);
! result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
return result;
}
--- 2282,2294 ----
mangle_type_string (type)
tree type;
{
const char *result;
! start_mangling (type);
write_type (type);
! result = finish_mangling (/*warn=*/false);
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
return result;
}
*************** mangle_special_for_type (type, code)
*** 2277,2295 ****
{
const char *result;
/* We don't have an actual decl here for the special component, so
we can't just process the <encoded-name>. Instead, fake it. */
! start_mangling ();
/* Start the mangling. */
write_string ("_Z");
write_string (code);
/* Add the type. */
write_type (type);
! result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_special_for_type = %s\n\n", result);
return get_identifier (result);
--- 2312,2330 ----
{
const char *result;
/* We don't have an actual decl here for the special component, so
we can't just process the <encoded-name>. Instead, fake it. */
! start_mangling (type);
/* Start the mangling. */
write_string ("_Z");
write_string (code);
/* Add the type. */
write_type (type);
! result = finish_mangling (/*warn=*/false);
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_special_for_type = %s\n\n", result);
return get_identifier (result);
*************** mangle_ctor_vtbl_for_type (type, binfo)
*** 2352,2371 ****
tree type;
tree binfo;
{
const char *result;
! start_mangling ();
write_string ("_Z");
write_string ("TC");
write_type (type);
write_integer_cst (BINFO_OFFSET (binfo));
write_char ('_');
write_type (BINFO_TYPE (binfo));
! result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n", result);
return get_identifier (result);
}
--- 2387,2406 ----
tree type;
tree binfo;
{
const char *result;
! start_mangling (type);
write_string ("_Z");
write_string ("TC");
write_type (type);
write_integer_cst (BINFO_OFFSET (binfo));
write_char ('_');
write_type (BINFO_TYPE (binfo));
! result = finish_mangling (/*warn=*/false);
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n", result);
return get_identifier (result);
}
*************** mangle_thunk (fn_decl, offset, vcall_off
*** 2385,2395 ****
tree offset;
tree vcall_offset;
{
const char *result;
! start_mangling ();
write_string ("_Z");
/* The <special-name> for virtual thunks is Tv, for non-virtual
thunks Th. */
write_char ('T');
--- 2420,2430 ----
tree offset;
tree vcall_offset;
{
const char *result;
! start_mangling (fn_decl);
write_string ("_Z");
/* The <special-name> for virtual thunks is Tv, for non-virtual
thunks Th. */
write_char ('T');
*************** mangle_thunk (fn_decl, offset, vcall_off
*** 2411,2421 ****
}
/* Scoped name. */
write_encoding (fn_decl);
! result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_thunk = %s\n\n", result);
return get_identifier (result);
}
--- 2446,2456 ----
}
/* Scoped name. */
write_encoding (fn_decl);
! result = finish_mangling (/*warn=*/false);
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_thunk = %s\n\n", result);
return get_identifier (result);
}
*************** mangle_conv_op_name_for_type (type)
*** 2452,2484 ****
tree
mangle_guard_variable (variable)
tree variable;
{
! start_mangling ();
write_string ("_ZGV");
if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
/* The name of a guard variable for a reference temporary should refer
to the reference, not the temporary. */
write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
else
write_name (variable, /*ignore_local_scope=*/0);
! return get_identifier (finish_mangling ());
}
/* Return an identifier for the name of a temporary variable used to
initialize a static reference. This isn't part of the ABI, but we might
as well call them something readable. */
tree
mangle_ref_init_variable (variable)
tree variable;
{
! start_mangling ();
write_string ("_ZGR");
write_name (variable, /*ignore_local_scope=*/0);
! return get_identifier (finish_mangling ());
}
/* Foreign language type mangling section. */
--- 2487,2519 ----
tree
mangle_guard_variable (variable)
tree variable;
{
! start_mangling (variable);
write_string ("_ZGV");
if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
/* The name of a guard variable for a reference temporary should refer
to the reference, not the temporary. */
write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
else
write_name (variable, /*ignore_local_scope=*/0);
! return get_identifier (finish_mangling (/*warn=*/false));
}
/* Return an identifier for the name of a temporary variable used to
initialize a static reference. This isn't part of the ABI, but we might
as well call them something readable. */
tree
mangle_ref_init_variable (variable)
tree variable;
{
! start_mangling (variable);
write_string ("_ZGR");
write_name (variable, /*ignore_local_scope=*/0);
! return get_identifier (finish_mangling (/*warn=*/false));
}
/* Foreign language type mangling section. */
Index: testsuite/g++.dg/abi/mangle11.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle11.C
diff -N testsuite/g++.dg/abi/mangle11.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle11.C 18 Oct 2002 08:07:27 -0000
***************
*** 0 ****
--- 1,10 ----
+ // { dg-options "-Wabi" }
+
+ template <typename Q>
+ void f (typename Q::X) {}
+
+ struct S {
+ typedef int X;
+ };
+
+ template void f<S> (int); // { dg-warning "mangle" }
Index: testsuite/g++.dg/abi/mangle14.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle14.C
diff -N testsuite/g++.dg/abi/mangle14.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle14.C 18 Oct 2002 08:07:27 -0000
***************
*** 0 ****
--- 1,12 ----
+ // { dg-do compile }
+ // { dg-options "-Wabi" }
+
+ struct A {
+ template <typename T> int f ();
+ };
+
+ typedef int (A::*P)();
+
+ template <P> struct S {};
+
+ void g (S<&A::f<int> >) {} // { dg-warning "mangle" }
Index: testsuite/g++.dg/abi/mangle17.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle17.C
diff -N testsuite/g++.dg/abi/mangle17.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle17.C 18 Oct 2002 08:07:27 -0000
***************
*** 0 ****
--- 1,11 ----
+ // { dg-options "-Wabi" }
+
+ enum E { e = 3 };
+
+ template <int I> struct S {};
+
+ template <int I> void f (S<e + int (3.7)>) {}
+ template void f<7>(S<e + int (3.7)>); // { dg-warning "mangle" }
+
+ template <int I> void g (S<e + int (3.7)>) {}
+ template void g<7>(S<e + int (3.7)>); // { dg-warning "mangle" }
More information about the Gcc-patches
mailing list