public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression
@ 2019-10-22 16:39 kamlesh kumar
  2019-10-22 16:54 ` kamlesh kumar
  2019-10-22 17:23 ` Marek Polacek
  0 siblings, 2 replies; 14+ messages in thread
From: kamlesh kumar @ 2019-10-22 16:39 UTC (permalink / raw)
  To: gcc-patches, jason, polacek, marxin

bootstrap and regtested on x86_64.

Changelog:
gcc
------
2019-10-22  Kamlesh Kumar  <kamleshbhalui@gmail.com>

        PR c++/91979 - mangling nullptr expression
        * mangle.c (write_template_arg_literal): Handle nullptr
        mangling.
        * testsuite/g++.dg/cpp0x/nullptr27.C: Modify Test.
        * testsuite/g++.dg/cpp0x/pr91979.C: New Test.

libiberty
-----------
2019-10-22  Kamlesh Kumar  <kamleshbhalui@gmail.com>

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




diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index a9333b8..780da9f 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3400,7 +3400,8 @@ 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 (TREE_CODE(TREE_TYPE(value)) != NULLPTR_TYPE)
+         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 2510dc8..edd1160 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/pr91979.C
b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
new file mode 100644
index 0000000..7fcd56b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
@@ -0,0 +1,15 @@
+// PR c++/91989
+// { 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 aa78c86..3e6b6fb 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3577,6 +3577,16 @@ 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
+          &&
strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17)
== 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 f21ed00..b23a7c2 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*)

./Kamlesh

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression
  2019-10-22 16:39 [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression kamlesh kumar
@ 2019-10-22 16:54 ` kamlesh kumar
  2019-10-22 17:23 ` Marek Polacek
  1 sibling, 0 replies; 14+ messages in thread
From: kamlesh kumar @ 2019-10-22 16:54 UTC (permalink / raw)
  To: gcc-patches, jason, polacek, marxin

[-- Attachment #1: Type: text/plain, Size: 4001 bytes --]

attached patch file.


On Tue, Oct 22, 2019 at 10:00 PM kamlesh kumar <kamleshbhalui@gmail.com> wrote:
>
> bootstrap and regtested on x86_64.
>
> Changelog:
> gcc
> ------
> 2019-10-22  Kamlesh Kumar  <kamleshbhalui@gmail.com>
>
>         PR c++/91979 - mangling nullptr expression
>         * mangle.c (write_template_arg_literal): Handle nullptr
>         mangling.
>         * testsuite/g++.dg/cpp0x/nullptr27.C: Modify Test.
>         * testsuite/g++.dg/cpp0x/pr91979.C: New Test.
>
> libiberty
> -----------
> 2019-10-22  Kamlesh Kumar  <kamleshbhalui@gmail.com>
>
>         * cp-demangle.c (d_expr_primary): Handle
>         nullptr demangling.
>         * testsuite/demangle-expected: Added test.
> =========================================================
>
>
>
>
> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
> index a9333b8..780da9f 100644
> --- a/gcc/cp/mangle.c
> +++ b/gcc/cp/mangle.c
> @@ -3400,7 +3400,8 @@ 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 (TREE_CODE(TREE_TYPE(value)) != NULLPTR_TYPE)
> +         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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> new file mode 100644
> index 0000000..7fcd56b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> @@ -0,0 +1,15 @@
> +// PR c++/91989
> +// { 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 aa78c86..3e6b6fb 100644
> --- a/libiberty/cp-demangle.c
> +++ b/libiberty/cp-demangle.c
> @@ -3577,6 +3577,16 @@ 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
> +          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 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 f21ed00..b23a7c2 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*)
>
> ./Kamlesh

[-- Attachment #2: pr91979.patch --]
[-- Type: application/octet-stream, Size: 2968 bytes --]

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index a9333b8..780da9f 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3400,7 +3400,8 @@ 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 (TREE_CODE(TREE_TYPE(value)) != NULLPTR_TYPE)
+	  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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
new file mode 100644
index 0000000..7fcd56b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
@@ -0,0 +1,15 @@
+// PR c++/91989
+// { 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 aa78c86..3e6b6fb 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3577,6 +3577,16 @@ 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
+          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 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 f21ed00..b23a7c2 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*)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression
  2019-10-22 16:39 [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression kamlesh kumar
  2019-10-22 16:54 ` kamlesh kumar
@ 2019-10-22 17:23 ` Marek Polacek
       [not found]   ` <CABKRkgjaFKpsWYDMdwgkDcZZSsMyruRn5_8tVRGhp93Gx5GVUQ@mail.gmail.com>
  2019-10-23  3:36   ` [[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix Kamlesh Kumar
  1 sibling, 2 replies; 14+ messages in thread
From: Marek Polacek @ 2019-10-22 17:23 UTC (permalink / raw)
  To: kamlesh kumar; +Cc: gcc-patches, jason, marxin

On Tue, Oct 22, 2019 at 10:00:19PM +0530, kamlesh kumar wrote:
> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
> index a9333b8..780da9f 100644
> --- a/gcc/cp/mangle.c
> +++ b/gcc/cp/mangle.c
> @@ -3400,7 +3400,8 @@ 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 (TREE_CODE(TREE_TYPE(value)) != NULLPTR_TYPE)
> +         write_integer_cst (value);

Please use NULLPTR_TYPE_P.

Does this warrant a new -fabi-version?

Marek

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression
       [not found]   ` <CABKRkgjaFKpsWYDMdwgkDcZZSsMyruRn5_8tVRGhp93Gx5GVUQ@mail.gmail.com>
@ 2019-10-22 17:53     ` kamlesh kumar
  2019-10-22 18:09       ` kamlesh kumar
  0 siblings, 1 reply; 14+ messages in thread
From: kamlesh kumar @ 2019-10-22 17:53 UTC (permalink / raw)
  To: Marek Polacek; +Cc: gcc-patches, jason, marxin, redi

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index a9333b8..334610c 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3400,7 +3400,8 @@ 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 (!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 2510dc8..edd1160 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/pr91979.C
b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
new file mode 100644
index 0000000..7fcd56b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
@@ -0,0 +1,15 @@
+// PR c++/91989
+// { 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 aa78c86..3c32b26 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3577,6 +3577,16 @@ 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
+          &&
strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17)
== 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 f21ed00..b23a7c2 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*)

On Tue, Oct 22, 2019 at 10:50 PM kamlesh kumar <kamleshbhalui@gmail.com>
wrote:

> Marek,
> updated the patch as per your suggestion.
> Regarding -fabi-version.
> this is what Jonathan said:
>
> This might need a new -fabi-version to preserve the old mangling for compatibility, but I'll let Jason determine that.
>
>
> Thanks.
>
>
>
> On Tue, Oct 22, 2019 at 10:24 PM Marek Polacek <polacek@redhat.com> wrote:
>
>> On Tue, Oct 22, 2019 at 10:00:19PM +0530, kamlesh kumar wrote:
>> > diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
>> > index a9333b8..780da9f 100644
>> > --- a/gcc/cp/mangle.c
>> > +++ b/gcc/cp/mangle.c
>> > @@ -3400,7 +3400,8 @@ 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 (TREE_CODE(TREE_TYPE(value)) != NULLPTR_TYPE)
>> > +         write_integer_cst (value);
>>
>> Please use NULLPTR_TYPE_P.
>>
>> Does this warrant a new -fabi-version?
>>
>> Marek
>>
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression
  2019-10-22 17:53     ` kamlesh kumar
@ 2019-10-22 18:09       ` kamlesh kumar
  0 siblings, 0 replies; 14+ messages in thread
From: kamlesh kumar @ 2019-10-22 18:09 UTC (permalink / raw)
  To: Marek Polacek; +Cc: gcc-patches, jason, marxin, redi

[-- Attachment #1: Type: text/plain, Size: 4446 bytes --]

On Tue, Oct 22, 2019 at 10:53 PM kamlesh kumar <kamleshbhalui@gmail.com> wrote:
>
> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
> index a9333b8..334610c 100644
> --- a/gcc/cp/mangle.c
> +++ b/gcc/cp/mangle.c
> @@ -3400,7 +3400,8 @@ 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 (!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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> new file mode 100644
> index 0000000..7fcd56b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> @@ -0,0 +1,15 @@
> +// PR c++/91989
> +// { 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 aa78c86..3c32b26 100644
> --- a/libiberty/cp-demangle.c
> +++ b/libiberty/cp-demangle.c
> @@ -3577,6 +3577,16 @@ 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
> +          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 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 f21ed00..b23a7c2 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*)
>
> On Tue, Oct 22, 2019 at 10:50 PM kamlesh kumar <kamleshbhalui@gmail.com> wrote:
>>
>> Marek,
>> updated the patch as per your suggestion.
>> Regarding -fabi-version.
>> this is what Jonathan said:
>>
>> This might need a new -fabi-version to preserve the old mangling for compatibility, but I'll let Jason determine that.
>>
>>
>> Thanks.
>>
>>
>>
>> On Tue, Oct 22, 2019 at 10:24 PM Marek Polacek <polacek@redhat.com> wrote:
>>>
>>> On Tue, Oct 22, 2019 at 10:00:19PM +0530, kamlesh kumar wrote:
>>> > diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
>>> > index a9333b8..780da9f 100644
>>> > --- a/gcc/cp/mangle.c
>>> > +++ b/gcc/cp/mangle.c
>>> > @@ -3400,7 +3400,8 @@ 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 (TREE_CODE(TREE_TYPE(value)) != NULLPTR_TYPE)
>>> > +         write_integer_cst (value);
>>>
>>> Please use NULLPTR_TYPE_P.
>>>
>>> Does this warrant a new -fabi-version?
>>>
>>> Marek
>>>

[-- Attachment #2: 0001-updated-the-fix.patch --]
[-- Type: application/octet-stream, Size: 3619 bytes --]

From 4ef84ed519e8a38ccc056da0bc6c254f803ba88e Mon Sep 17 00:00:00 2001
From: Kamlesh Kumar <kamleshbhalui@gmail.com>
Date: Tue, 22 Oct 2019 10:56:24 -0700
Subject: [[PATCH][PR91979] handle mangling of  nullptr expression ] updated
 the fix

---
 gcc/cp/mangle.c                        |  3 ++-
 gcc/testsuite/g++.dg/cpp0x/nullptr27.C |  2 +-
 gcc/testsuite/g++.dg/cpp0x/pr91979.C   | 15 +++++++++++++++
 libiberty/cp-demangle.c                | 10 ++++++++++
 libiberty/testsuite/demangle-expected  |  4 ++++
 5 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr91979.C

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index a9333b8..334610c 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3400,7 +3400,8 @@ 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 (!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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
new file mode 100644
index 0000000..7fcd56b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
@@ -0,0 +1,15 @@
+// PR c++/91989
+// { 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 aa78c86..3c32b26 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3577,6 +3577,16 @@ 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
+          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 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 f21ed00..b23a7c2 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*)
-- 
1.8.5.6


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [[PATCH][PR91979] handle mangling of  nullptr expression ] updated the fix
  2019-10-22 17:23 ` Marek Polacek
       [not found]   ` <CABKRkgjaFKpsWYDMdwgkDcZZSsMyruRn5_8tVRGhp93Gx5GVUQ@mail.gmail.com>
@ 2019-10-23  3:36   ` Kamlesh Kumar
  2019-10-31 18:08     ` kamlesh kumar
  1 sibling, 1 reply; 14+ messages in thread
From: Kamlesh Kumar @ 2019-10-23  3:36 UTC (permalink / raw)
  To: polacek; +Cc: gcc-patches, jason, marxin, Kamlesh Kumar

---
 gcc/cp/mangle.c                        |  3 ++-
 gcc/testsuite/g++.dg/cpp0x/nullptr27.C |  2 +-
 gcc/testsuite/g++.dg/cpp0x/pr91979.C   | 15 +++++++++++++++
 libiberty/cp-demangle.c                | 10 ++++++++++
 libiberty/testsuite/demangle-expected  |  4 ++++
 5 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr91979.C

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index a9333b8..334610c 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3400,7 +3400,8 @@ 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 (!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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
new file mode 100644
index 0000000..7fcd56b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
@@ -0,0 +1,15 @@
+// PR c++/91989
+// { 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 aa78c86..3c32b26 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3577,6 +3577,16 @@ 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
+          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 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 f21ed00..b23a7c2 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*)
-- 
1.8.5.6

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix
  2019-10-23  3:36   ` [[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix Kamlesh Kumar
@ 2019-10-31 18:08     ` kamlesh kumar
  2019-11-01 21:14       ` Jason Merrill
  0 siblings, 1 reply; 14+ messages in thread
From: kamlesh kumar @ 2019-10-31 18:08 UTC (permalink / raw)
  To: Marek Polacek; +Cc: gcc-patches, jason, marxin

Jason,
Can you please review this,
let me know how can we handle -fabi-version?

On Wed, Oct 23, 2019 at 7:55 AM Kamlesh Kumar <kamleshbhalui@gmail.com> wrote:
>
> ---
>  gcc/cp/mangle.c                        |  3 ++-
>  gcc/testsuite/g++.dg/cpp0x/nullptr27.C |  2 +-
>  gcc/testsuite/g++.dg/cpp0x/pr91979.C   | 15 +++++++++++++++
>  libiberty/cp-demangle.c                | 10 ++++++++++
>  libiberty/testsuite/demangle-expected  |  4 ++++
>  5 files changed, 32 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr91979.C
>
> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
> index a9333b8..334610c 100644
> --- a/gcc/cp/mangle.c
> +++ b/gcc/cp/mangle.c
> @@ -3400,7 +3400,8 @@ 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 (!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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> new file mode 100644
> index 0000000..7fcd56b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> @@ -0,0 +1,15 @@
> +// PR c++/91989
> +// { 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 aa78c86..3c32b26 100644
> --- a/libiberty/cp-demangle.c
> +++ b/libiberty/cp-demangle.c
> @@ -3577,6 +3577,16 @@ 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
> +          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 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 f21ed00..b23a7c2 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*)
> --
> 1.8.5.6
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix
  2019-10-31 18:08     ` kamlesh kumar
@ 2019-11-01 21:14       ` Jason Merrill
  2019-11-02  3:48         ` [PATCH v2] [PR91979] Updated the fix: Kamlesh Kumar
  0 siblings, 1 reply; 14+ messages in thread
From: Jason Merrill @ 2019-11-01 21:14 UTC (permalink / raw)
  To: kamlesh kumar, Marek Polacek; +Cc: gcc-patches, marxin

On 10/31/19 2:06 PM, kamlesh kumar wrote:
> Jason,
> Can you please review this,
> let me know how can we handle -fabi-version?

We should bump latest_abi_version in c-opts.c and use 
abi_version_at_least to control this change.

> On Wed, Oct 23, 2019 at 7:55 AM Kamlesh Kumar <kamleshbhalui@gmail.com> wrote:
>>
>> ---
>>   gcc/cp/mangle.c                        |  3 ++-
>>   gcc/testsuite/g++.dg/cpp0x/nullptr27.C |  2 +-
>>   gcc/testsuite/g++.dg/cpp0x/pr91979.C   | 15 +++++++++++++++
>>   libiberty/cp-demangle.c                | 10 ++++++++++
>>   libiberty/testsuite/demangle-expected  |  4 ++++
>>   5 files changed, 32 insertions(+), 2 deletions(-)
>>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr91979.C
>>
>> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
>> index a9333b8..334610c 100644
>> --- a/gcc/cp/mangle.c
>> +++ b/gcc/cp/mangle.c
>> @@ -3400,7 +3400,8 @@ 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 (!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 2510dc8..edd1160 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
>> new file mode 100644
>> index 0000000..7fcd56b
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
>> @@ -0,0 +1,15 @@
>> +// PR c++/91989
>> +// { 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 aa78c86..3c32b26 100644
>> --- a/libiberty/cp-demangle.c
>> +++ b/libiberty/cp-demangle.c
>> @@ -3577,6 +3577,16 @@ 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
>> +          && strncmp(type->u.s_builtin.type->name,cplus_demangle_builtin_types[33].name,17) == 0)

This line is too long and needs more spaces: before the ( and after commas.

>> +        {
>> +          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 f21ed00..b23a7c2 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*)
>> --
>> 1.8.5.6
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2] [PR91979] Updated the fix:
  2019-11-01 21:14       ` Jason Merrill
@ 2019-11-02  3:48         ` Kamlesh Kumar
  2019-11-03  8:04           ` Jason Merrill
  2019-11-03 11:43           ` [PATCH v3] Updated the Fix: Kamlesh Kumar
  0 siblings, 2 replies; 14+ messages in thread
From: Kamlesh Kumar @ 2019-11-02  3:48 UTC (permalink / raw)
  To: jason; +Cc: polacek, gcc-patches, marxin, Kamlesh Kumar

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

        PR c++/91979 - mangling nullptr expression
        * mangle.c (write_template_arg_literal): Handle nullptr
        mangling.
        * testsuite/g++.dg/cpp0x/nullptr27.C: Modify Test.
        * testsuite/g++.dg/cpp0x/pr91979.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/cp/mangle.c                        |  4 +++-
 gcc/testsuite/g++.dg/cpp0x/nullptr27.C |  2 +-
 gcc/testsuite/g++.dg/cpp0x/pr91979.C   | 15 +++++++++++++++
 libiberty/cp-demangle.c                | 11 +++++++++++
 libiberty/testsuite/demangle-expected  |  4 ++++
 6 files changed, 35 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr91979.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/cp/mangle.c b/gcc/cp/mangle.c
index a9333b84349..234a975781e 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/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
new file mode 100644
index 00000000000..7fcd56b27f0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
@@ -0,0 +1,15 @@
+// PR c++/91989
+// { 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..3fb1c56409e 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
+	  && strncmp (type->u.s_builtin.type->name,
+		      cplus_demangle_builtin_types[33].name, 17) == 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*)
-- 
2.17.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] [PR91979] Updated the fix:
  2019-11-02  3:48         ` [PATCH v2] [PR91979] Updated the fix: Kamlesh Kumar
@ 2019-11-03  8:04           ` Jason Merrill
  2019-11-03 11:43           ` [PATCH v3] Updated the Fix: Kamlesh Kumar
  1 sibling, 0 replies; 14+ messages in thread
From: Jason Merrill @ 2019-11-03  8:04 UTC (permalink / raw)
  To: Kamlesh Kumar; +Cc: polacek, gcc-patches, marxin

On 11/1/19 11:47 PM, Kamlesh Kumar wrote:
> Changlogs
> gcc
> ------
> 2019-11-02  Kamlesh Kumar  <kamleshbhalui@gmail.com>
> 
>          PR c++/91979 - mangling nullptr expression
>          * mangle.c (write_template_arg_literal): Handle nullptr
>          mangling.
>          * testsuite/g++.dg/cpp0x/nullptr27.C: Modify Test.
>          * testsuite/g++.dg/cpp0x/pr91979.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/cp/mangle.c                        |  4 +++-
>   gcc/testsuite/g++.dg/cpp0x/nullptr27.C |  2 +-
>   gcc/testsuite/g++.dg/cpp0x/pr91979.C   | 15 +++++++++++++++
>   libiberty/cp-demangle.c                | 11 +++++++++++
>   libiberty/testsuite/demangle-expected  |  4 ++++
>   6 files changed, 35 insertions(+), 3 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr91979.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;

Please also add a comment about ABI v14 above fabi-version= in 
gcc/common.opt.

>     /* Generate compatibility aliases for ABI v11 (7.1) by default.  */
>     const int abi_compat_default = 11;
>   
> diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
> index a9333b84349..234a975781e 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)))

This logic is wrong: it will never emit the value for ABI version lower 
than 14.  And you need a space before (.

> +	  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);

Please also add a test for the old mangled name with -fabi-version=13.

> diff --git a/gcc/testsuite/g++.dg/cpp0x/pr91979.C b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> new file mode 100644
> index 00000000000..7fcd56b27f0
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/pr91979.C
> @@ -0,0 +1,15 @@
> +// PR c++/91989
> +// { 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..3fb1c56409e 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
> +	  && strncmp (type->u.s_builtin.type->name,
> +		      cplus_demangle_builtin_types[33].name, 17) == 0)

Let's use strcmp rather than hardcode 17 here.

> +	{
> +	  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*)
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] Updated the Fix:
  2019-11-02  3:48         ` [PATCH v2] [PR91979] Updated the fix: Kamlesh Kumar
  2019-11-03  8:04           ` Jason Merrill
@ 2019-11-03 11:43           ` Kamlesh Kumar
  2019-11-04 23:35             ` Jason Merrill
  1 sibling, 1 reply; 14+ messages in thread
From: Kamlesh Kumar @ 2019-11-03 11:43 UTC (permalink / raw)
  To: jason; +Cc: polacek, gcc-patches, marxin

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

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*)
-- 
2.17.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Updated the Fix:
  2019-11-03 11:43           ` [PATCH v3] Updated the Fix: Kamlesh Kumar
@ 2019-11-04 23:35             ` Jason Merrill
  2020-01-12 13:31               ` Iain Sandoe
  0 siblings, 1 reply; 14+ messages in thread
From: Jason Merrill @ 2019-11-04 23:35 UTC (permalink / raw)
  To: Kamlesh Kumar; +Cc: polacek, gcc-patches, marxin

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*)
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Updated the Fix:
  2019-11-04 23:35             ` Jason Merrill
@ 2020-01-12 13:31               ` Iain Sandoe
  2020-01-12 14:39                 ` Iain Sandoe
  0 siblings, 1 reply; 14+ messages in thread
From: Iain Sandoe @ 2020-01-12 13:31 UTC (permalink / raw)
  To: Kamlesh Kumar; +Cc: GCC Patches, Jason Merrill

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Updated the Fix:
  2020-01-12 13:31               ` Iain Sandoe
@ 2020-01-12 14:39                 ` Iain Sandoe
  0 siblings, 0 replies; 14+ messages in thread
From: Iain Sandoe @ 2020-01-12 14:39 UTC (permalink / raw)
  To: Kamlesh Kumar; +Cc: GCC Patches, Jason Merrill

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-01-12 13:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22 16:39 [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression kamlesh kumar
2019-10-22 16:54 ` kamlesh kumar
2019-10-22 17:23 ` Marek Polacek
     [not found]   ` <CABKRkgjaFKpsWYDMdwgkDcZZSsMyruRn5_8tVRGhp93Gx5GVUQ@mail.gmail.com>
2019-10-22 17:53     ` kamlesh kumar
2019-10-22 18:09       ` kamlesh kumar
2019-10-23  3:36   ` [[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix Kamlesh Kumar
2019-10-31 18:08     ` kamlesh kumar
2019-11-01 21:14       ` Jason Merrill
2019-11-02  3:48         ` [PATCH v2] [PR91979] Updated the fix: Kamlesh Kumar
2019-11-03  8:04           ` Jason Merrill
2019-11-03 11:43           ` [PATCH v3] Updated the Fix: Kamlesh Kumar
2019-11-04 23:35             ` Jason Merrill
2020-01-12 13:31               ` Iain Sandoe
2020-01-12 14:39                 ` Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).