From e0c866ddfdb500cacefee4e37fb3e85521c55623 Mon Sep 17 00:00:00 2001 From: Kamlesh Kumar Date: Mon, 4 Nov 2019 23:24:25 +0000 Subject: [PATCH] PR c++/91979 - mangling nullptr expression 2019-11-04 Kamlesh Kumar gcc/cp * cp/mangle.c (write_template_arg_literal): Handle nullptr mangling. gcc * common.opt (-fabi-version): Document =14. * doc/invoke.texi (C++ Dialect Options): Likewise. gcc/c-family * c-opts.c (c_common_post_options): Update latest_abi_version. libiberty * cp-demangle.c (d_expr_primary): Handle nullptr demangling. * testsuite/demangle-expected: Added test. From-SVN: r277801 --- gcc/ChangeLog | 5 +++++ gcc/c-family/ChangeLog | 5 +++++ gcc/c-family/c-opts.c | 2 +- gcc/common.opt | 2 ++ gcc/cp/ChangeLog | 6 ++++++ gcc/cp/mangle.c | 4 +++- gcc/doc/invoke.texi | 3 +++ gcc/testsuite/g++.dg/abi/macro0.C | 2 +- gcc/testsuite/g++.dg/cpp0x/nullptr27.C | 2 +- gcc/testsuite/g++.dg/cpp0x/nullptr43.C | 9 +++++++++ gcc/testsuite/g++.dg/cpp0x/nullptr44.C | 15 +++++++++++++++ libiberty/ChangeLog | 6 ++++++ libiberty/cp-demangle.c | 11 +++++++++++ libiberty/testsuite/demangle-expected | 4 ++++ 14 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nullptr43.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/nullptr44.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 254b3950a8e..e726ff6d0a0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-11-04 Kamlesh Kumar + + * common.opt (-fabi-version): Document =14. + * doc/invoke.texi (C++ Dialect Options): Likewise. + 2019-11-04 Aldy Hernandez * tree-vrp.c (value_range_base::set): Do not special case pointers. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9e93911fab2..d95424537a9 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2019-11-04 Kamlesh Kumar + + * c-opts.c (c_common_post_options): Update + latest_abi_version. + 2019-11-02 Jakub Jelinek * c-common.h (c_omp_get_context_selector): Remove. diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 0fffe60b140..d4c77be5cd5 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -937,7 +937,7 @@ c_common_post_options (const char **pfilename) /* Change flag_abi_version to be the actual current ABI level, for the benefit of c_cpp_builtins, and to make comparison simpler. */ - const int latest_abi_version = 13; + const int latest_abi_version = 14; /* Generate compatibility aliases for ABI v11 (7.1) by default. */ const int abi_compat_default = 11; diff --git a/gcc/common.opt b/gcc/common.opt index cc279f411d7..fdd923e3c35 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -951,6 +951,8 @@ Driver Undocumented ; 13: Fixes the accidental change in 12 to the calling convention for classes ; with deleted copy constructor and trivial move constructor. ; Default in G++ 8.2. +; 14: Corrects the mangling of nullptr expression. +; Default in G++ 10. ; ; Additional positive integers will be assigned as new versions of ; the ABI become the default version of the ABI. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7c22a533339..0f7571633a7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-11-04 Kamlesh Kumar + + PR c++/91979 - mangling nullptr expression + * cp/mangle.c (write_template_arg_literal): Handle nullptr + mangling. + 2019-11-04 Jason Merrill * typeck.c (check_return_expr): Avoid redundant error. diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index a9333b84349..0ac04514e8e 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -3400,7 +3400,9 @@ write_template_arg_literal (const tree value) case INTEGER_CST: gcc_assert (!same_type_p (TREE_TYPE (value), boolean_type_node) || integer_zerop (value) || integer_onep (value)); - write_integer_cst (value); + if (!(abi_version_at_least (14) + && NULLPTR_TYPE_P (TREE_TYPE (value)))) + write_integer_cst (value); break; case REAL_CST: diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index bf3ea3f6c04..cf7cf206193 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2413,6 +2413,9 @@ trivial move constructor. Version 13, which first appeared in G++ 8.2, fixes the accidental change in version 12. +Version 14, which first appeared in G++ 10, corrects the mangling of +the nullptr expression. + See also @option{-Wabi}. @item -fabi-compat-version=@var{n} diff --git a/gcc/testsuite/g++.dg/abi/macro0.C b/gcc/testsuite/g++.dg/abi/macro0.C index 01a3541aa7d..08106004c4d 100644 --- a/gcc/testsuite/g++.dg/abi/macro0.C +++ b/gcc/testsuite/g++.dg/abi/macro0.C @@ -1,6 +1,6 @@ // This testcase will need to be kept in sync with c_common_post_options. // { dg-options "-fabi-version=0" } -#if __GXX_ABI_VERSION != 1013 +#if __GXX_ABI_VERSION != 1014 #error "Incorrect value of __GXX_ABI_VERSION" #endif diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr27.C b/gcc/testsuite/g++.dg/cpp0x/nullptr27.C index 2510dc80634..edd11606266 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr27.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr27.C @@ -1,7 +1,7 @@ // PR c++/52706 // { dg-do compile { target c++11 } } // { dg-options "-fabi-version=0" } -// { dg-final { scan-assembler "_Z1fIDnLDn0EEiT_" } } +// { dg-final { scan-assembler "_Z1fIDnLDnEEiT_" } } template int f(T); diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr43.C b/gcc/testsuite/g++.dg/cpp0x/nullptr43.C new file mode 100644 index 00000000000..fbdb6cd8e9d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr43.C @@ -0,0 +1,9 @@ +// PR c++/91979 +// { dg-do compile { target c++11 } } +// { dg-options "-fabi-version=13" } +// { dg-final { scan-assembler "_Z1fIDnLDn0EEiT_" } } + +template +int f(T); + +int i2 = f(nullptr); diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr44.C b/gcc/testsuite/g++.dg/cpp0x/nullptr44.C new file mode 100644 index 00000000000..9ceba14fc98 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr44.C @@ -0,0 +1,15 @@ +// PR c++/91979 +// { dg-do compile { target c++11 } } +// { dg-final { scan-assembler "_Z3fooILPv0EEvPN9enable_ifIXeqT_LDnEEvE4typeE" } } + +template +struct enable_if {}; + +template +struct enable_if { typedef T type; }; + +template +void foo(typename enable_if

::type* = 0) {} + +template void foo<(void *)0>(void *); + diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 4992b15d681..b6f9e2de60d 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,9 @@ +2019-11-04 Kamlesh Kumar + + * cp-demangle.c (d_expr_primary): Handle + nullptr demangling. + * testsuite/demangle-expected: Added test. + 2019-10-29 Paul Pluzhnikov * cp-demangle.c (d_number): Avoid signed int overflow. diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 5b674d7d93c..963217c37bd 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -3577,6 +3577,17 @@ d_expr_primary (struct d_info *di) && type->u.s_builtin.type->print != D_PRINT_DEFAULT) di->expansion -= type->u.s_builtin.type->len; + if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE + && strcmp (type->u.s_builtin.type->name, + cplus_demangle_builtin_types[33].name) == 0) + { + if (d_peek_char (di) == 'E') + { + d_advance (di, 1); + return type; + } + } + /* Rather than try to interpret the literal value, we just collect it as a string. Note that it's possible to have a floating point literal here. The ABI specifies that the diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index 61681484d0e..f68a8a71aaf 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -1446,3 +1446,7 @@ Foo()::X::fn _ZZZ3FooIiEfvENKUlT_E_clIcEEDaS0_EN1X2fnEv Foo()::{lambda(auto:1)#1}::operator()(char) const::X::fn() Foo()::{lambda(auto:1)#1}::operator()(char) const::X::fn +#PR91979 demangling nullptr expression + +_Z3fooILPv0EEvPN9enable_ifIXeqT_LDnEEvE4typeE +void foo<(void*)0>(enable_if<((void*)0)==((decltype(nullptr))), void>::type*) -- 2.30.2