From 58a15cf8ee953516f101e4320e83c3fed6bb2cd7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 3 Mar 2010 14:01:36 -0500 Subject: [PATCH] re PR c++/12909 (ambiguity in mangling vector types) PR c++/12909 * mangle.c: Include cgraph.h. (mangle_decl): If the mangled name will change in a later ABI version, make the later mangled name an alias. * method.c (make_alias_for): Copy DECL_ARGUMENTS. * Make-lang.in (mangle.o): Depend on cgraph.h. From-SVN: r157201 --- gcc/cp/ChangeLog | 9 ++++++++ gcc/cp/Make-lang.in | 2 +- gcc/cp/mangle.c | 33 +++++++++++++++++++++++++++++ gcc/cp/method.c | 1 + gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/abi/mangle40.C | 25 ++++++++++++++++++++++ gcc/testsuite/g++.dg/abi/mangle41.C | 7 ++++++ 7 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/abi/mangle40.C create mode 100644 gcc/testsuite/g++.dg/abi/mangle41.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 556c4ac39fc..1b0b72bc6dd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2010-03-03 Jason Merrill + + PR c++/12909 + * mangle.c: Include cgraph.h. + (mangle_decl): If the mangled name will change in a later + ABI version, make the later mangled name an alias. + * method.c (make_alias_for): Copy DECL_ARGUMENTS. + * Make-lang.in (mangle.o): Depend on cgraph.h. + 2010-03-01 Marco Poletti * pt.c (redeclare_class_template): Use error_n and inform_n. diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index f6cb70fbeec..1484063fae5 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -308,7 +308,7 @@ cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) rtl.h $(INTEGRATE_H) \ insn-config.h input.h $(PARAMS_H) debug.h $(TREE_INLINE_H) $(GIMPLE_H) \ $(TARGET_H) tree-iterator.h $(CGRAPH_H) cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h $(REAL_H) \ - gt-cp-mangle.h $(TARGET_H) $(TM_P_H) + gt-cp-mangle.h $(TARGET_H) $(TM_P_H) $(CGRAPH_H) cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) $(DIAGNOSTIC_H) gt-cp-parser.h \ output.h $(TARGET_H) $(PLUGIN_H) intl.h cp/cp-gimplify.o: cp/cp-gimplify.c $(CXX_TREE_H) toplev.h $(C_COMMON_H) \ diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 6196ae2edf6..9478092daf6 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -58,6 +58,7 @@ along with GCC; see the file COPYING3. If not see #include "varray.h" #include "flags.h" #include "target.h" +#include "cgraph.h" /* Debugging support. */ @@ -3055,6 +3056,38 @@ mangle_decl (const tree decl) tree id = mangle_decl_string (decl); id = targetm.mangle_decl_assembler_name (decl, id); SET_DECL_ASSEMBLER_NAME (decl, id); + +#ifdef ASM_OUTPUT_DEF + if (G.need_abi_warning) + { + /* If the mangling will change in the future, emit an alias with the + future mangled name for forward-compatibility. */ + int save_ver; + tree id2, alias; + + SET_IDENTIFIER_GLOBAL_VALUE (id, decl); + if (IDENTIFIER_GLOBAL_VALUE (id) != decl) + inform (DECL_SOURCE_LOCATION (decl), "-fabi-version=4 (or =0) " + "avoids this error with a change in vector mangling"); + + if (TREE_CODE (decl) != FUNCTION_DECL) + return; + + save_ver = flag_abi_version; + flag_abi_version = 0; + id2 = mangle_decl_string (decl); + id2 = targetm.mangle_decl_assembler_name (decl, id2); + flag_abi_version = save_ver; + + alias = make_alias_for (decl, id2); + DECL_IGNORED_P (alias) = 1; + TREE_PUBLIC (alias) = TREE_PUBLIC (decl); + DECL_VISIBILITY (alias) = DECL_VISIBILITY (decl); + if (vague_linkage_fn_p (decl)) + DECL_WEAK (alias) = 1; + cgraph_same_body_alias (alias, decl); + } +#endif } /* Generate the mangled representation of TYPE. */ diff --git a/gcc/cp/method.c b/gcc/cp/method.c index ccc977d9df3..c25cedba178 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -234,6 +234,7 @@ make_alias_for (tree function, tree newid) DECL_TEMPLATE_INSTANTIATED (alias) = 0; DECL_TEMPLATE_INFO (alias) = NULL; DECL_INITIAL (alias) = error_mark_node; + DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target)); TREE_ADDRESSABLE (alias) = 1; TREE_USED (alias) = 1; SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ba742fde473..77aaf9c6833 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2010-03-03 Jason Merrill + + PR c++/12909 + * g++.dg/abi/mangle40.C: New. + * g++.dg/abi/mangle41.C: New. + 2010-03-03 Paul Thomas PR fortran/43243 diff --git a/gcc/testsuite/g++.dg/abi/mangle40.C b/gcc/testsuite/g++.dg/abi/mangle40.C new file mode 100644 index 00000000000..1d604ef162d --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/mangle40.C @@ -0,0 +1,25 @@ +// PR c++/12909 +// { dg-do compile { target i?86-*-* x86_64-*-* } } +// { dg-options "-mavx -Wabi -fabi-version=2" } +// { dg-final { scan-assembler "weak\[^\n\]*_Z1fIDv4_fEvT_" } } +// { dg-final { scan-assembler "weak\[^\n\]*_Z1fIU8__vectorfEvT_" } } +// { dg-final { scan-assembler "weak\[^\n\]*_ZN1AIU8__vectorfE1tE" } } + +#include + +template +struct A +{ + static T t; +}; + +template +T A::t; // { dg-warning "mangled name" } + +template +void f (T t) { } // { dg-warning "mangled name" } + +int main() +{ + f (A<__m128>::t); +} diff --git a/gcc/testsuite/g++.dg/abi/mangle41.C b/gcc/testsuite/g++.dg/abi/mangle41.C new file mode 100644 index 00000000000..3a9c04f77d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/mangle41.C @@ -0,0 +1,7 @@ +// PR c++/41959 +// { dg-do compile { target i?86-*-* x86_64-*-* } } +// { dg-options "-mavx -fabi-version=2" } + +#include +void f(__m128) { } // { dg-error "previous" } +void f(__m256) { } // { dg-message "declaration|mangling" }