From: Jakub Jelinek Date: Thu, 25 Jan 2001 07:35:21 +0000 (+0100) Subject: mangle.c (write_mangled_name, [...]): Mangle overloaded operators even in "C" linkage. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=324ffb8c3d49d2f17b88626b0b5b38194c2e4bf3;p=gcc.git mangle.c (write_mangled_name, [...]): Mangle overloaded operators even in "C" linkage. * mangle.c (write_mangled_name, write_encoding): Mangle overloaded operators even in "C" linkage. * method.c (set_mangled_name_for_decl): Likewise. * decl.c (grokfndecl): Call set_mangled_name_for_decl even for overloaded operators in "C" linkage. * g++.old-deja/g++.other/mangle2.C: New test. From-SVN: r39257 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 69ac61d1032..8ba3cc7a084 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2001-01-25 Jakub Jelinek + + * mangle.c (write_mangled_name, write_encoding): Mangle overloaded + operators even in "C" linkage. + * method.c (set_mangled_name_for_decl): Likewise. + * decl.c (grokfndecl): Call set_mangled_name_for_decl even for + overloaded operators in "C" linkage. + 2001-01-24 Nathan Sidwell * pt.c (tsubst_decl): Remove IN_DECL parameter. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6fcf9c4d2c2..761b843b162 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8846,7 +8846,7 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, /* Plain overloading: will not be grok'd by grokclassfn. */ if (! ctype && ! processing_template_decl - && !DECL_EXTERN_C_P (decl) + && (! DECL_EXTERN_C_P (decl) || DECL_OVERLOADED_OPERATOR_P (decl)) && (! DECL_USE_TEMPLATE (decl) || name_mangling_version < 1)) set_mangled_name_for_decl (decl); diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index d0c8e69d068..10f0bc89828 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -602,10 +602,14 @@ write_mangled_name (decl) { MANGLE_TRACE_TREE ("mangled-name", decl); - if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl)) + if (DECL_LANG_SPECIFIC (decl) + && DECL_EXTERN_C_FUNCTION_P (decl) + && ! DECL_OVERLOADED_OPERATOR_P (decl)) /* The standard notes: "The of an extern "C" function is treated like - global-scope data, i.e. as its without a type." */ + global-scope data, i.e. as its without a type." + We cannot write overloaded operators that way though, + because it contains characters invalid in assembler. */ write_source_name (DECL_NAME (decl)); else /* C++ name; needs to be mangled. */ @@ -626,7 +630,12 @@ write_encoding (decl) if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl)) { - write_source_name (DECL_NAME (decl)); + /* For overloaded operators write just the mangled name + without arguments. */ + if (DECL_OVERLOADED_OPERATOR_P (decl)) + write_name (decl, /*ignore_local_scope=*/0); + else + write_source_name (DECL_NAME (decl)); return; } diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 3e6b3ccf20e..17016a4a972 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1763,6 +1763,24 @@ set_mangled_name_for_decl (decl) return; } + if (DECL_EXTERN_C_P (decl)) + { + /* In extern "C" we have to mangle at least overloaded operators, + because they contain characters invalid in assembler. */ + enum tree_code code = DECL_OVERLOADED_OPERATOR_P (decl); + const char *name; + + if (code) + { + if (DECL_ASSIGNMENT_OPERATOR_P (decl)) + name = assignment_operator_name_info[(int) code].mangled_name; + else + name = operator_name_info[(int) code].mangled_name; + DECL_ASSEMBLER_NAME (decl) = get_identifier (name); + return; + } + } + parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); if (DECL_STATIC_FUNCTION_P (decl)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c68a93d35f0..a8352d8a3fe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-01-25 Jakub Jelinek + + * g++.old-deja/g++.other/mangle2.C: New test. + 2001-01-24 Joseph S. Myers * gcc.c-torture/compile/20010124-1.c: New test. diff --git a/gcc/testsuite/g++.old-deja/g++.other/mangle2.C b/gcc/testsuite/g++.old-deja/g++.other/mangle2.C new file mode 100644 index 00000000000..25bab87a249 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/mangle2.C @@ -0,0 +1,24 @@ +// Test for overloaded operators in "C" linkage +// Build don't link: + +extern "C" { +typedef struct b +{ + int a; +} c; + +extern const c z; + +inline bool operator!=(const c& x, const c& y) +{ + return x.a != y.a; +} +}; + +void foo(); + +void bar(c x) +{ + if (x != z) + foo(); +}