From a3bf6ce7f2e17f2c977c13df23eb718e7b433dcd Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Tue, 30 Mar 2021 22:57:11 -0400 Subject: c++: Adjust mangling of __alignof__ [PR88115] r11-4926 made __alignof__ get mangled differently from alignof, encoding __alignof__ as a vendor extended operator. But this mangling is problematic for the reasons mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88115#c6. This patch changes our mangling of __alignof__ to instead use the new "vendor extended expression" syntax that's proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/112. Clang does the same thing already, so after this patch Clang and GCC agree about the mangling of __alignof__(type) and __alignof__(expr). gcc/cp/ChangeLog: PR c++/88115 * mangle.c (write_expression): Adjust the mangling of __alignof__. include/ChangeLog: PR c++/88115 * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_VENDOR_EXPR. libiberty/ChangeLog: PR c++/88115 * cp-demangle.c (d_dump, d_make_comp, d_expression_1) (d_count_templates_scopes): Handle DEMANGLE_COMPONENT_VENDOR_EXPR. (d_print_comp_inner): Likewise. : Revert r11-4926 change. : Likewise. * testsuite/demangle-expected: Adjust __alignof__ tests. gcc/testsuite/ChangeLog: PR c++/88115 * g++.dg/cpp0x/alignof7.C: Adjust expected mangling. --- gcc/cp/mangle.c | 8 +++----- gcc/testsuite/g++.dg/cpp0x/alignof7.C | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'gcc') diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 0a9e5aa..57ce9a6 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -3124,11 +3124,9 @@ write_expression (tree expr) if (abi_version_at_least (15)) { /* We used to mangle __alignof__ like alignof. */ - write_string ("v111__alignof__"); - if (TYPE_P (TREE_OPERAND (expr, 0))) - write_type (TREE_OPERAND (expr, 0)); - else - write_expression (TREE_OPERAND (expr, 0)); + write_string ("u11__alignof__"); + write_template_arg (TREE_OPERAND (expr, 0)); + write_char ('E'); return; } } diff --git a/gcc/testsuite/g++.dg/cpp0x/alignof7.C b/gcc/testsuite/g++.dg/cpp0x/alignof7.C index a4d7f24..2369b87 100644 --- a/gcc/testsuite/g++.dg/cpp0x/alignof7.C +++ b/gcc/testsuite/g++.dg/cpp0x/alignof7.C @@ -18,5 +18,5 @@ template void f4(std::size_t); // { dg-final { scan-assembler "_Z2f1IiEvDTatT_E" } } // { dg-final { scan-assembler "_Z2f2IiEvDTaztlT_EE" } } -// { dg-final { scan-assembler "_Z2f3IiEvDTv111__alignof__T_E" } } -// { dg-final { scan-assembler "_Z2f4IiEvDTv111__alignof__tlT_EE" } } +// { dg-final { scan-assembler "_Z2f3IiEvDTu11__alignof__T_EE" } } +// { dg-final { scan-assembler "_Z2f4IiEvDTu11__alignof__XtlT_EEEE" } } -- cgit v1.1