diff mbox series

[v3] Updated the Fix:

Message ID 20191103114249.22001-1-kamleshbhalui@gmail.com
State New
Headers show
Series [v3] Updated the Fix: | expand

Commit Message

kamlesh kumar Nov. 3, 2019, 11:42 a.m. UTC
ChangeLog Entries:

gcc/cp
------
2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        PR c++/91979 - mangling nullptr expression
        * cp/mangle.c (write_template_arg_literal): Handle nullptr
        mangling.

gcc
------
2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        * common.opt (-fabi-version): Added Description.
        * testsuite/g++.dg/cpp0x/nullptr27.C: Modify Test.
        * testsuite/g++.dg/cpp0x/nullptr43.C: New Test.
        * testsuite/g++.dg/cpp0x/nullptr44.C: New Test.

libiberty
-----------
2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        * cp-demangle.c (d_expr_primary): Handle
        nullptr demangling.
        * testsuite/demangle-expected: Added test.

gcc/c-family
----------
2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        * c-opts.c (c_common_post_options): Updated
        latest_abi_version.
---
 gcc/c-family/c-opts.c                  |  2 +-
 gcc/common.opt                         |  2 ++
 gcc/cp/mangle.c                        |  4 +++-
 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/cp-demangle.c                | 11 +++++++++++
 libiberty/testsuite/demangle-expected  |  4 ++++
 8 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/nullptr43.C
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/nullptr44.C

Comments

Jason Merrill Nov. 4, 2019, 11:35 p.m. UTC | #1
On 11/3/19 6:42 AM, Kamlesh Kumar wrote:
> ChangeLog Entries:
> 
> gcc/cp
> ------
> 2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>
> 
>          PR c++/91979 - mangling nullptr expression
>          * cp/mangle.c (write_template_arg_literal): Handle nullptr
>          mangling.
> 
> gcc
> ------
> 2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>
> 
>          * common.opt (-fabi-version): Added Description.
>          * testsuite/g++.dg/cpp0x/nullptr27.C: Modify Test.
>          * testsuite/g++.dg/cpp0x/nullptr43.C: New Test.
>          * testsuite/g++.dg/cpp0x/nullptr44.C: New Test.
> 
> libiberty
> -----------
> 2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>
> 
>          * cp-demangle.c (d_expr_primary): Handle
>          nullptr demangling.
>          * testsuite/demangle-expected: Added test.
> 
> gcc/c-family
> ----------
> 2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>
> 
>          * c-opts.c (c_common_post_options): Updated
>          latest_abi_version.

Applied, thanks.  I also added the -fabi-version=14 to doc/invoke.texi.

Any word on your copyright assignment?

> ---
>   gcc/c-family/c-opts.c                  |  2 +-
>   gcc/common.opt                         |  2 ++
>   gcc/cp/mangle.c                        |  4 +++-
>   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/cp-demangle.c                | 11 +++++++++++
>   libiberty/testsuite/demangle-expected  |  4 ++++
>   8 files changed, 46 insertions(+), 3 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/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/mangle.c b/gcc/cp/mangle.c
> index a9333b84349..a32ff2a2210 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/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<class T, decltype(nullptr) = nullptr>
>   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<class T, decltype(nullptr) = nullptr>
> +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 <bool, typename T = void>
> +struct enable_if {};
> +
> +template <typename T>
> +struct enable_if<true, T> { typedef T type; };
> +
> +template <void *P>
> +void foo(typename enable_if<P == nullptr>::type* = 0) {}
> +
> +template void foo<(void *)0>(void *);
> +
> diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
> index 5b674d7d93c..3150efff80d 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<int>()::X::fn
>   _ZZZ3FooIiEfvENKUlT_E_clIcEEDaS0_EN1X2fnEv
>   Foo<int>()::{lambda(auto:1)#1}::operator()<char>(char) const::X::fn()
>   Foo<int>()::{lambda(auto:1)#1}::operator()<char>(char) const::X::fn
> +#PR91979 demangling nullptr expression
> +
> +_Z3fooILPv0EEvPN9enable_ifIXeqT_LDnEEvE4typeE
> +void foo<(void*)0>(enable_if<((void*)0)==((decltype(nullptr))), void>::type*)
>
Iain Sandoe Jan. 12, 2020, 1 p.m. UTC | #2
Jason Merrill <jason@redhat.com> wrote:

> On 11/3/19 6:42 AM, Kamlesh Kumar wrote:
>> ChangeLog Entries:

>> -----------
>> 2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>
>>         * cp-demangle.c (d_expr_primary): Handle
>>         nullptr demangling.
>>         * testsuite/demangle-expected: Added test.

This test is failing in at least some places (x86_64-darwin, x86_64-linux)

x86_64-apple-darwin16-gcc -DHAVE_CONFIG_H -g -O2  -I..  
-I/src-local/gcc-master/libiberty/testsuite/../../include  -o test-demangle  
\
	/src-local/gcc-master/libiberty/testsuite/test-demangle.c ../libiberty.a
./test-demangle < /src-local/gcc-master/libiberty/testsuite/demangle-expected
FAIL at line 1452, options :
in:  _Z3fooILPv0EEvPN9enable_ifIXeqT_LDnEEvE4typeE
out: void foo<(void*)0>(enable_if<((void*)0)==(decltype(nullptr)),  
void>::type*)
exp: void foo<(void*)0>(enable_if<((void*)0)==((decltype(nullptr))),  
void>::type*)
./test-demangle: 335 tests, 1 failures

Is the extra set of parentheses significant in your expected output?
if so, then the demangling is not working …
… if not, we should amend the test since it causes early failure of  
libiberty tests

(I guess this goes unnoticed, because they are not integrated into the  
headline
  GCC regression tests).

thanks
Iain
diff mbox series

Patch

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/mangle.c b/gcc/cp/mangle.c
index a9333b84349..a32ff2a2210 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/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<class T, decltype(nullptr) = nullptr>
 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<class T, decltype(nullptr) = nullptr>
+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 <bool, typename T = void>
+struct enable_if {};
+
+template <typename T>
+struct enable_if<true, T> { typedef T type; };
+
+template <void *P>
+void foo(typename enable_if<P == nullptr>::type* = 0) {}
+
+template void foo<(void *)0>(void *);
+
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 5b674d7d93c..3150efff80d 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<int>()::X::fn
 _ZZZ3FooIiEfvENKUlT_E_clIcEEDaS0_EN1X2fnEv
 Foo<int>()::{lambda(auto:1)#1}::operator()<char>(char) const::X::fn()
 Foo<int>()::{lambda(auto:1)#1}::operator()<char>(char) const::X::fn
+#PR91979 demangling nullptr expression
+
+_Z3fooILPv0EEvPN9enable_ifIXeqT_LDnEEvE4typeE
+void foo<(void*)0>(enable_if<((void*)0)==((decltype(nullptr))), void>::type*)