[[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix

2019-10-22 Thread 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
 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 000..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 
+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/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()::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*)
-- 
1.8.5.6



Re: [[PATCH][PR91979] handle mangling of nullptr expression ] updated the fix

2019-10-31 Thread kamlesh kumar
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  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
>  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 000..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 
> +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/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()::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*)
> --
> 1.8.5.6
>


[PATCH v2] [PR91979] Updated the fix:

2019-11-01 Thread Kamlesh Kumar
Changlogs
gcc
--
2019-11-02  Kamlesh Kumar  

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  

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

gcc/c-family
--
2019-11-02  Kamlesh Kumar  

* 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
 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 000..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 
+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/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()::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.17.1



[PATCH v3] Updated the Fix:

2019-11-03 Thread Kamlesh Kumar
ChangeLog Entries:

gcc/cp
--
2019-11-02  Kamlesh Kumar  

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

gcc
--
2019-11-02  Kamlesh Kumar  

* 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  

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

gcc/c-family
--
2019-11-02  Kamlesh Kumar  

* 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
 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 000..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 000..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/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.

Re: RFA: Fix libiberty testsuite failure

2020-01-20 Thread kamlesh kumar
yes, current expected entry is wrong and
Nick's patch corrects that.

./kamlesh


On Mon, Jan 20, 2020 at 9:29 PM Ian Lance Taylor  wrote:

> Nick Clifton  writes:
>
> > Hi Ian,
> >
> >   The libiberty testsuite in the gcc mainline is currently failing on
> >   the last test:
> >
> > 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*)
> >
> >   To me it looks like the expected demangling is incorrect - it wants a
> >   double set of parentheses around decltype(nullptr) when I think that
> >   only one is needed.  So I would like to apply the patch below to fix
> >   this.
> >
> >   Is this OK ?
>
> Looks like this problem was introduced by
>
> 2019-11-04  Kamlesh Kumar  
>
> * cp-demangle.c (d_expr_primary): Handle
> nullptr demangling.
> * testsuite/demangle-expected: Added test.
>
> https://gcc.gnu.org/ml/gcc-patches/2019-11/msg00064.html
>
> Kamlesh, Jason, can you confirm that Nick's change to the testsuite is
> testing the expected demangling, and that the current entry in the
> testsuite is incorrect?  Thanks.
>
> Ian
>
>
> > libiberty/ChangeLog
> > 2020-01-20  Nick Clifton  
> >
> >   * testsuite/demangle-expected: Fix expected demangling.
> >
> > Index: libiberty/testsuite/demangle-expected
> > ===
> > --- libiberty/testsuite/demangle-expected (revision 280157)
> > +++ libiberty/testsuite/demangle-expected (working copy)
> > @@ -1449,4 +1449,4 @@
> >  #PR91979 demangling nullptr expression
> >
> >  _Z3fooILPv0EEvPN9enable_ifIXeqT_LDnEEvE4typeE
> > -void foo<(void*)0>(enable_if<((void*)0)==((decltype(nullptr))),
> void>::type*)
> > +void foo<(void*)0>(enable_if<((void*)0)==(decltype(nullptr)),
> void>::type*)
>


[PATCH][PR89924] [missed-optimization] Function not de-virtualized within the same TU

2019-09-26 Thread kamlesh kumar
This patch resolves subjected issue.
bootstrapped and regtested on x86_64.

ChangeLog:

2019-09-26  Kamlesh Kumar  

PR ipa/89924
* ipa-polymorphic-call.c
(ipa_polymorphic_call_context::ipa_polymorphic_call_context):
Updated
outer_type.
* g++.dg/opt/pr89924.C: New Test.
* g++.dg/ipa/devirt-34.C: Modified.


==

diff --git a/gcc/ipa-polymorphic-call.c b/gcc/ipa-polymorphic-call.c
index 705af03..b76793f 100644
--- a/gcc/ipa-polymorphic-call.c
+++ b/gcc/ipa-polymorphic-call.c
@@ -1118,6 +1118,10 @@
ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
  We do not make this type of flow sensitive analysis yet.  */
   if (instance)
 *instance = base_pointer;
+
+  if (((TREE_CODE (TREE_TYPE(base_type)) == RECORD_TYPE)))
+outer_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base_pointer)));
+
   return;
 }

diff --git a/gcc/testsuite/g++.dg/ipa/devirt-34.C
b/gcc/testsuite/g++.dg/ipa/devirt-34.C
index 083c305..7961c0f 100644
--- a/gcc/testsuite/g++.dg/ipa/devirt-34.C
+++ b/gcc/testsuite/g++.dg/ipa/devirt-34.C
@@ -17,5 +17,4 @@ t(struct B *b)
 /* We should guess that the pointer of type B probably points to an
instance
of B or its derivates and exclude A::t from list of likely targets.  */

-/* { dg-final { scan-ipa-dump "Speculative targets"  "devirt"  } } */
 /* { dg-final { scan-ipa-dump "1 speculatively devirtualized"  "devirt"  }
} */
diff --git a/gcc/testsuite/g++.dg/opt/pr89924.C
b/gcc/testsuite/g++.dg/opt/pr89924.C
new file mode 100644
index 000..a78ef67
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr89924.C
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=c++11 -fdump-tree-optimized" } */
+
+struct A {
+  virtual A& operator+=(const A& other) noexcept = 0;
+  };
+
+  void foo_inner(int *p) noexcept { *p += *p; }
+  void foo_virtual_inner(A *p) noexcept { *p += *p; }
+
+  void foo(int *p) noexcept
+  {
+  return foo_inner(p);
+  }
+
+  struct Aint : public A {
+  int i;
+  A& operator+=(const A& other) noexcept override final
+  {
+ i += reinterpret_cast(other).i;
+  return *this;
+  }
+  };
+
+   void foo_virtual(Aint *p) noexcept
+   {
+   return foo_virtual_inner(p);
+   }
+
+//{ dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 2 "optimized" } }


[PATCH][PR83534] C++17: typeinfo for noexcept function lacks noexcept information

2019-10-04 Thread kamlesh kumar
bootstrapped and regtested on x86_64.

ChangeLog:
2019-10-04  Kamlesh Kumar  
* rtti.c (get_tinfo_decl_dynamic): Do not call
TYPE_MAIN_VARIANT for function.
(get_typeid): Likewise.
* g++.dg/rtti/pr83534.C: New Test.



diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index eb1b062a49b..8467e77f7ac 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -276,7 +276,9 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t
complain)
   type = non_reference (unlowered_expr_type (exp));

   /* Peel off cv qualifiers.  */
-  type = TYPE_MAIN_VARIANT (type);
+  if (TREE_CODE (type) != FUNCTION_TYPE
+|| cxx_dialect < cxx17)
+type = TYPE_MAIN_VARIANT (type);

   /* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics.  */
   if (CLASS_TYPE_P (type) || type == unknown_type_node
@@ -298,6 +300,8 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t
complain)
   t = build_vtbl_ref (exp, index);
   t = convert (type_info_ptr_type, t);
 }
+  else if(TREE_CODE (type) == FUNCTION_TYPE)
+   t = get_tinfo_ptr (type);
   else
 /* Otherwise return the type_info for the static type of the expr.  */
 t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type));
@@ -518,7 +522,9 @@ get_typeid (tree type, tsubst_flags_t complain)

   /* The top-level cv-qualifiers of the lvalue expression or the type-id
  that is the operand of typeid are always ignored.  */
-  type = TYPE_MAIN_VARIANT (type);
+  if (TREE_CODE (type) != FUNCTION_TYPE
+|| cxx_dialect < cxx17)
+type = TYPE_MAIN_VARIANT (type);

   /* For UNKNOWN_TYPEs call complete_type_or_else to get diagnostics.  */
   if (CLASS_TYPE_P (type) || type == unknown_type_node
ukallapa@ala-salim-lx1$git diff -p --staged
diff --git a/gcc/testsuite/g++.dg/rtti/pr83534.C
b/gcc/testsuite/g++.dg/rtti/pr83534.C
new file mode 100644
index 000..405ea5c2af4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/pr83534.C
@@ -0,0 +1,14 @@
+// { dg-options "-std=c++17" }
+// { dg-do run }
+
+#include 
+void f1();
+void f2() noexcept;
+int main() {
+
+if((typeid(void()) == typeid(void ()noexcept))
+|| (typeid(&f1) == typeid(&f2))
+|| (typeid(f1) == typeid(f2)))
+  abort();
+ }
+


[PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression

2019-10-22 Thread kamlesh kumar
bootstrap and regtested on x86_64.

Changelog:
gcc
--
2019-10-22  Kamlesh Kumar  

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  

* 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
 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 000..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 
+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/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()::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*)

./Kamlesh


Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression

2019-10-22 Thread kamlesh kumar
attached patch file.


On Tue, Oct 22, 2019 at 10:00 PM kamlesh kumar  wrote:
>
> bootstrap and regtested on x86_64.
>
> Changelog:
> gcc
> ------
> 2019-10-22  Kamlesh Kumar  
>
> 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  
>
> * 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
>  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 000..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 
> +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/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()::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*)
>
> ./Kamlesh


pr91979.patch
Description: Binary data


Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression

2019-10-22 Thread kamlesh kumar
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
 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 000..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 
+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/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()::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*)

On Tue, Oct 22, 2019 at 10:50 PM kamlesh kumar 
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  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
>>
>>


Re: [PATCH][PR91979] Incorrect mangling for non-template-argument nullptr expression

2019-10-22 Thread kamlesh kumar
On Tue, Oct 22, 2019 at 10:53 PM kamlesh kumar  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
>  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 000..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 
> +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/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()::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*)
>
> On Tue, Oct 22, 2019 at 10:50 PM kamlesh kumar  
> 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  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
>>>


0001-updated-the-fix.patch
Description: Binary data


[PATCH] [PR81810] unused strcpy to a local buffer not eliminated

2019-08-21 Thread kamlesh kumar
Hi ,
This patch include fix for PR81810
Bootstrapped/regtested on x86_64-linux, ok for trunk?

Thanks
./Kamlesh

2019-08-21  Kamlesh Kumar   

   PR tree-optimization/81810
   * tree-ssa-dse.c (dse_dom_walker::dse_optimize_stmt): Added
   BUILT_IN_STRCPY to consider for dse.
   (maybe_trim_memstar_call): Likewise.
   (initialize_ao_ref_for_dse): Likewise.
   * gcc.dg/tree-ssa/pr81810.c: New testcase.


diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index ba67884a825..dc4da4c9730 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -115,8 +115,11 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write)
case BUILT_IN_MEMSET_CHK:
case BUILT_IN_STRNCPY:
case BUILT_IN_STRNCPY_CHK:
+   case BUILT_IN_STRCPY:
  {
-   tree size = gimple_call_arg (stmt, 2);
+   tree size = NULL;
+   if (gimple_call_num_args (stmt) > 2)
+   size = gimple_call_arg (stmt, 2);
tree ptr = gimple_call_arg (stmt, 0);
ao_ref_init_from_ptr_and_size (write, ptr, size);
return true;
@@ -470,6 +473,7 @@ maybe_trim_memstar_call (ao_ref *ref, sbitmap live,
gimple *stmt)
 case BUILT_IN_MEMCPY:
 case BUILT_IN_MEMMOVE:
 case BUILT_IN_STRNCPY:
+case BUILT_IN_STRCPY:
 case BUILT_IN_MEMCPY_CHK:
 case BUILT_IN_MEMMOVE_CHK:
 case BUILT_IN_STRNCPY_CHK:
@@ -966,6 +970,7 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator
*gsi)
case BUILT_IN_MEMCPY:
case BUILT_IN_MEMMOVE:
case BUILT_IN_STRNCPY:
+   case BUILT_IN_STRCPY:
case BUILT_IN_MEMSET:
case BUILT_IN_MEMCPY_CHK:
case BUILT_IN_MEMMOVE_CHK:
@@ -975,11 +980,14 @@ dse_dom_walker::dse_optimize_stmt
(gimple_stmt_iterator *gsi)
/* Occasionally calls with an explicit length of zero
   show up in the IL.  It's pointless to do analysis
   on them, they're trivially dead.  */
-   tree size = gimple_call_arg (stmt, 2);
-   if (integer_zerop (size))
+   if (gimple_call_num_args (stmt) > 2)
  {
-   delete_dead_or_redundant_call (gsi, "dead");
-   return;
+   tree size = gimple_call_arg (stmt, 2);
+   if (integer_zerop (size))
+ {
+   delete_dead_or_redundant_call (gsi, "dead");
+   return;
+ }
  }

/* If this is a memset call that initializes an object
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81810.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr81810.c
new file mode 100644
index 000..89cf36a1367
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81810.c
@@ -0,0 +1,25 @@
+/* PR tree-optimization/81810
+   { dg-do compile }
+   { dg-options "-O2 -fdump-tree-optimized" } */
+
+void f (const void *p, unsigned n)
+{
+  char a[8];
+  __builtin_memcpy (a, p, n);
+}
+
+void g (const char *s)
+{
+  char a[8];
+  __builtin_strcpy (a, s);
+}
+
+void h (const char *s)
+{
+  char a[8];
+  __builtin_strncpy (a, s, sizeof a);
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_memcpy" "optimized" } }
+   { dg-final { scan-tree-dump-not "__builtin_strcpy" "optimized" } }
+   { dg-final { scan-tree-dump-not "__builtin_strncpy" "optimized" } } */


[Patch][PR91504] Inlining misses some logical operation folding

2019-08-26 Thread kamlesh kumar
2019-08-26  Kamlesh Kumar  

* gcc/match.pd: Added simplification
pattern.
* gcc.dg/tree-ssa/pr91504.c: New test.


diff --git a/gcc/match.pd b/gcc/match.pd
index 93dcef9..b3734f8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -831,6 +831,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_xor:c (bit_and:cs @0 (bit_not @1)) (bit_not @0))
  (bit_not (bit_and @0 @1)))

+/* (~a & b) ^ a  -->   (a | b)   */
+(simplify
+ (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
+ (bit_ior @0 @1))
+
 /* (a | b) & ~(a ^ b)  -->  a & b  */
 (simplify
  (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
new file mode 100644
index 000..a52dea4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+static inline unsigned deposit32(unsigned value, int start, int length,
+ unsigned fieldval)
+{
+unsigned mask = (~0U >> (32 - length)) << start;
+return (value & ~mask) | ((fieldval << start) & mask);
+}
+
+unsigned foo(unsigned value)
+{
+   return deposit32(value, 10, 1, 1);
+}
+
+/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */


Re: [PATCH] c++: Implement DR2303 [PR97453]

2020-11-02 Thread kamlesh kumar via Gcc-patches
addressed jason comments.
no regression due to this, tested on x86_64 linux.

On Tue, Oct 27, 2020 at 11:09 PM Jason Merrill  wrote:
>
> On 10/22/20 1:31 PM, kamlesh kumar wrote:
> > Attaching the patch file.
> >
> >  >>Instead of building a hash table, would it work to handle ambiguity by
> >  >>checking whether one of the classes is a base of the other?
>
> > Fixing for cases like: struct B: A,A may not be cleaner
> > this way.
>
> Why not?  Your patch does extra work even when there's no ambiguity.
>
> > On Thu, Oct 22, 2020 at 3:23 AM Jason Merrill  > <mailto:ja...@redhat.com>> wrote:
> >  >
> >  > On 10/21/20 6:32 AM, kamlesh kumar wrote:
> >  > > gcc/cp/ChangeLog
> >  > > ---
> >  > >
> >  > > 2020-10-21  Kamlesh Kumar   > <mailto:kamleshbha...@gmail.com>>
> >  > >
> >  > > PR c++/97453
> >  > > * pt.c (get_template_base): Implement DR2303,
> >  > > Consider closest base while template
> >  > > deduction when base of base also matches.
> >  > >
> >  > > gcc/testsuite/ChangeLog
> >  > > --
> >  > >
> >  > > 2020-10-21  Kamlesh Kumar   > <mailto:kamleshbha...@gmail.com>>
> >  > >
> >  > > * g++.dg/Drs/dr2303.C: New Test
> >  > >
> >  > > --
> >  > >
> >  > > As part of this patch I Implemented fix for below defect report in cwg
> >  > > https://wg21.cmeerw.net/cwg/issue2303 .
> >  >
> >  > Thanks!
> >  >
> >  > Please see https://gcc.gnu.org/contribute.html for guidance on email
> >  > subject lines; for this patch I'd think something like
> >  >
> >  > [PATCH] c++: Implement DR2303 [PR97453]
> >  >
> >  > Also, your patch was corrupted by word wrap; the easiest way to avoid
> >  > that is probably to attach the file rather than copy it into the message.
> >  >
> >  > > Reg tested on x86_64 and did not found any failure.
> >  > > Patch summary: Remove base of base from list of bases
> >  > >
> >  > > created a hash_set from list of bases and then iterate over each
> >  > > element of hash_set and find its  list of bases and remove this from
> >  > > hash_set if present.
> >  > > and finally, deduction succeeds if in hash_set remains only single
> >  > > element or it's empty.
> >  > > otherwise deduction is ambiguous.
> >  >
> >  > Instead of building a hash table, would it work to handle ambiguity by
> >  > checking whether one of the classes is a base of the other?
> >  >
> >  > > ---
> >  > > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> >  > > index dc664ec3798..7adf461e108 100644
> >  > > --- a/gcc/cp/pt.c
> >  > > +++ b/gcc/cp/pt.c
> >  > > @@ -22643,8 +22643,9 @@ static enum template_base_result
> >  > >   get_template_base (tree tparms, tree targs, tree parm, tree arg,
> >  > >   bool explain_p, tree *result)
> >  > >   {
> >  > > -  tree rval = NULL_TREE;
> >  > > +  *result = NULL_TREE;
> >  > > tree binfo;
> >  > > +  hash_set binfo_set;
> >  > >
> >  > > gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (arg)));
> >  > >
> >  > > @@ -22659,31 +22660,51 @@ get_template_base (tree tparms, tree targs,
> >  > > tree parm, tree arg,
> >  > > /* Walk in inheritance graph order.  The search order is not
> >  > >important, and this avoids multiple walks of virtual bases.  */
> >  > > for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN (binfo))
> >  > > -{
> >  > > -  tree r = try_class_unification (tparms, targs, parm,
> >  > > -   BINFO_TYPE (binfo), explain_p);
> >  > > -
> >  > > -  if (r)
> >  > > - {
> >  > > -   /* If there is more than one satisfactory baseclass, then:
> >  > > -
> >  > > -[temp.deduct.call]
> >  > > + {
> >  > > +   tree r = try_class_unification (tparms, targs, parm,
> >  > > +   BINFO_TYPE (binfo), explain_p);
> >  > > +   if (r)
> >  > > + {
> >  > >

Re: [PATCH] c++: Implement DR2303 [PR97453]

2020-11-02 Thread kamlesh kumar via Gcc-patches
>>Do you see a reason this wouldn't work?
No, I do not see any.This is good.
>>so it's probably simplest to go ahead with mine.
Yes, thank you.

On Mon, Nov 2, 2020 at 9:48 PM Jason Merrill  wrote:
>
> On 11/2/20 10:10 AM, kamlesh kumar wrote:
> > addressed jason comments.
> > no regression due to this, tested on x86_64 linux.
> >
> > On Tue, Oct 27, 2020 at 11:09 PM Jason Merrill  wrote:
> >>
> >> On 10/22/20 1:31 PM, kamlesh kumar wrote:
> >>> Attaching the patch file.
> >>>
> >>>   >>Instead of building a hash table, would it work to handle ambiguity by
> >>>   >>checking whether one of the classes is a base of the other?
> >>
> >>> Fixing for cases like: struct B: A,A may not be cleaner
> >>> this way.
> >>
> >> Why not?  Your patch does extra work even when there's no ambiguity.
> >>
> >>> On Thu, Oct 22, 2020 at 3:23 AM Jason Merrill  >>> <mailto:ja...@redhat.com>> wrote:
> >>>   >
> >>>   > On 10/21/20 6:32 AM, kamlesh kumar wrote:
> >>>   > > gcc/cp/ChangeLog
> >>>   > > ---
> >>>   > >
> >>>   > > 2020-10-21  Kamlesh Kumar   >>> <mailto:kamleshbha...@gmail.com>>
> >>>   > >
> >>>   > > PR c++/97453
> >>>   > > * pt.c (get_template_base): Implement DR2303,
> >>>   > > Consider closest base while template
> >>>   > > deduction when base of base also matches.
> >>>   > >
> >>>   > > gcc/testsuite/ChangeLog
> >>>   > > --
> >>>   > >
> >>>   > > 2020-10-21  Kamlesh Kumar   >>> <mailto:kamleshbha...@gmail.com>>
> >>>   > >
> >>>   > > * g++.dg/Drs/dr2303.C: New Test
> >>>   > >
> >>>   > > --
> >>>   > >
> >>>   > > As part of this patch I Implemented fix for below defect report in 
> >>> cwg
> >>>   > > https://wg21.cmeerw.net/cwg/issue2303 .
> >>>   >
> >>>   > Thanks!
> >>>   >
> >>>   > Please see https://gcc.gnu.org/contribute.html for guidance on email
> >>>   > subject lines; for this patch I'd think something like
> >>>   >
> >>>   > [PATCH] c++: Implement DR2303 [PR97453]
> >>>   >
> >>>   > Also, your patch was corrupted by word wrap; the easiest way to avoid
> >>>   > that is probably to attach the file rather than copy it into the 
> >>> message.
> >>>   >
> >>>   > > Reg tested on x86_64 and did not found any failure.
> >>>   > > Patch summary: Remove base of base from list of bases
> >>>   > >
> >>>   > > created a hash_set from list of bases and then iterate over each
> >>>   > > element of hash_set and find its  list of bases and remove this from
> >>>   > > hash_set if present.
> >>>   > > and finally, deduction succeeds if in hash_set remains only single
> >>>   > > element or it's empty.
> >>>   > > otherwise deduction is ambiguous.
> >>>   >
> >>>   > Instead of building a hash table, would it work to handle ambiguity by
> >>>   > checking whether one of the classes is a base of the other?
>
> This is what I had in mind; it seems clearer to me.  Do you see a reason
> this wouldn't work?
>
> Also, I notice that you still don't seem to have a copyright assignment
> on file with the FSF.  I and Jonathan Wakely both asked about it last
> year; has there been any progress on that?  Your patch is too large to
> go in without a copyright assignment, so it's probably simplest to go
> ahead with mine.
>
> Thanks,
> Jason


[PATCH][PPC64] [PR88877]

2020-03-23 Thread kamlesh kumar via Gcc-patches
Attached patch fixes.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877.
ChangeLog Entry.

2020-03-23  Kamlesh Kumar  

* rtl.h : Defined Tuple for bundling rtx, mode and
unsignedness default as 0
Added Extra argument (unsignedp) in emit_library_call and
emit_library_call_value.
* except.c : Likewise.
* explow.c : Likewise.
* expmed.c : Likewise.
* expr.c : Likewise.
* optabs.c : Likewise.
* asan.c : Likewise.
* builtins.c : Likewise.
* calls.c : Likewise.
* cfgexpand.c : Likewise.
* config/aarch64/aarch64.c : Likewise.
* config/aarch64/aarch64.h : Likewise.
* config/aarch64/atomics.md : Likewise.
* config/alpha/alpha.c : Likewise.
* config/arc/arc.c : Likewise.
* config/arc/elf.h : Likewise.
* config/arc/linux.h : Likewise.
* config/arm/arm.c : Likewise.
* config/bfin/bfin.md : Likewise.
* config/c6x/c6x.c : Likewise.
* config/csky/csky.c : Likewise.
* config/frv/frv.c : Likewise.
* config/i386/i386-expand.c : Likewise.
* config/i386/i386.c : Likewise.
* config/ia64/ia64.c : Likewise.
* config/ia64/ia64.md : Likewise.
* config/m32r/m32r.c : Likewise.
* config/m68k/linux.h : Likewise.
* config/m68k/m68k.c : Likewise.
* config/microblaze/microblaze.c : Likewise.
* config/mips/mips.h : Likewise.
* config/mips/sdemtk.h : Likewise.
* config/nds32/nds32.h : Likewise.
* config/nios2/nios2.c : Likewise.
* config/or1k/or1k.c : Likewise.
* config/pa/pa.c : Likewise.
* config/pa/pa.md : Likewise.
* config/pru/pru.c : Likewise.
* config/riscv/riscv.h : Likewise.
* config/riscv/riscv.md : Likewise.
* config/rl78/rl78.c : Likewise.
* config/rs6000/rs6000-string.c : Likewise.
* config/rs6000/rs6000.c : Likewise.
* config/rs6000/rs6000.md : Likewise.
* config/rs6000/vsx.md : Likewise.
* config/sh/sh.c : Likewise.
* config/sparc/sparc.c : Likewise.
* config/tilegx/tilegx.c : Likewise.
* config/tilepro/tilepro.c : Likewise.
* config/visium/visium.c : Likewise.
* config/xtensa/xtensa.c : Likewise.
* testsuite/gcc.target/powerpc/pr88877.c : Newtest
diff --git a/gcc/asan.c b/gcc/asan.c
index cc8f9122e3d..ec4d6bdc161 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1488,7 +1488,7 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
   ret = emit_library_call_value (ret, NULL_RTX, LCT_NORMAL, ptr_mode,
  GEN_INT (asan_frame_size
 	  + base_align_bias),
- TYPE_MODE (pointer_sized_int_node));
+ TYPE_MODE (pointer_sized_int_node), 0);
   /* __asan_stack_malloc_[n] returns a pointer to fake stack if succeeded
 	 and NULL otherwise.  Check RET value is NULL here and jump over the
 	 BASE reassignment in this case.  Otherwise, reassign BASE to RET.  */
@@ -1615,7 +1615,7 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
 	  emit_library_call (ret, LCT_NORMAL, ptr_mode, addr, ptr_mode,
 			 GEN_INT (asan_frame_size + base_align_bias),
 			 TYPE_MODE (pointer_sized_int_node),
-			 orig_addr, ptr_mode);
+			 orig_addr, ptr_mode, 0);
 	}
   lab = gen_label_rtx ();
   emit_jump (lab);
@@ -1715,7 +1715,7 @@ asan_emit_allocas_unpoison (rtx top, rtx bot, rtx_insn *before)
   top = convert_memory_address (ptr_mode, top);
   bot = convert_memory_address (ptr_mode, bot);
   emit_library_call (ret, LCT_NORMAL, ptr_mode,
-		 top, ptr_mode, bot, ptr_mode);
+		 top, ptr_mode, bot, ptr_mode, 0);
 
   do_pending_stack_adjust ();
   rtx_insn *insns = get_insns ();
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 53bae599d3e..99fa50bd515 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -2979,7 +2979,7 @@ expand_builtin_powi (tree exp, rtx target)
 
   target = emit_library_call_value (optab_libfunc (powi_optab, mode),
 target, LCT_CONST, mode,
-op0, mode, op1, mode2);
+op0, mode, op1, mode2, 0);
 
   return target;
 }
@@ -5858,7 +5858,7 @@ expand_asan_emit_allocas_unpoison (tree exp)
 			 OPTAB_LIB_WIDEN);
   rtx ret = init_one_libfunc ("__asan_allocas_unpoison");
   ret = emit_library_call_value (ret, NULL_RTX, LCT_NORMAL, ptr_mode,
- top, ptr_mode, bot, ptr_mode);
+ top, ptr_mode, bot, ptr_mode, 0);
   return ret;
 }
 
diff --git a/gcc/calls.c b/gcc/calls.c
index 4c3a8f3c215..20324ff6f04 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -5247,7 +5247,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
 {
   rtx val = args[i].first;
   function_arg_info arg (args[i].second, /*named=*/true);
-  int unsigned_p = 0;
+  int unsigned_p = GET_THIRD(args[i]);
 
   /* We cannot convert the arg value to the mode the library wants here;
 	 must do 

Re: [PATCH][PPC64] [PR88877]

2020-03-24 Thread kamlesh kumar via Gcc-patches
Thanks Hans-Peter for reviewing.
Here is Formatted ChangeLog Entry.

2020-03-24  Kamlesh Kumar  

* rtl.h: Defined Tuple for bundling rtx, mode and unsignedness
(default as 0), Added Extra argument (unsignedp)
in emit_library_call and emit_library_call_value.
* except.c: Likewise.
* explow.c: Likewise.
* expmed.c: Likewise.
* expr.c: Likewise.
* optabs.c: Likewise.
* asan.c: Likewise.
* builtins.c: Likewise.
* calls.c: Likewise.
* cfgexpand.c: Likewise.
* config/aarch64/aarch64.c: Likewise.
* config/aarch64/aarch64.h: Likewise.
* config/aarch64/atomics.md: Likewise.
* config/alpha/alpha.c: Likewise.
* config/arc/arc.c: Likewise.
* config/arc/elf.h: Likewise.
* config/arc/linux.h: Likewise.
* config/arm/arm.c: Likewise.
* config/bfin/bfin.md: Likewise.
* config/c6x/c6x.c: Likewise.
* config/csky/csky.c: Likewise.
* config/frv/frv.c: Likewise.
* config/i386/i386-expand.c: Likewise.
* config/i386/i386.c: Likewise.
* config/ia64/ia64.c: Likewise.
* config/ia64/ia64.md: Likewise.
* config/m32r/m32r.c: Likewise.
* config/m68k/linux.h: Likewise.
* config/m68k/m68k.c: Likewise.
* config/microblaze/microblaze.c: Likewise.
* config/mips/mips.h: Likewise.
* config/mips/sdemtk.h: Likewise.
* config/nds32/nds32.h: Likewise.
* config/nios2/nios2.c: Likewise.
* config/or1k/or1k.c: Likewise.
* config/pa/pa.c: Likewise.
* config/pa/pa.md: Likewise.
* config/pru/pru.c: Likewise.
* config/riscv/riscv.h: Likewise.
* config/riscv/riscv.md: Likewise.
* config/rl78/rl78.c: Likewise.
* config/rs6000/rs6000-string.c: Likewise.
* config/rs6000/rs6000.c: Likewise.
* config/rs6000/rs6000.md: Likewise.
* config/rs6000/vsx.md: Likewise.
* config/sh/sh.c: Likewise.
* config/sparc/sparc.c: Likewise.
* config/tilegx/tilegx.c: Likewise.
* config/tilepro/tilepro.c: Likewise.
* config/visium/visium.c: Likewise.
* config/xtensa/xtensa.c: Likewise.
* testsuite/gcc.target/powerpc/pr88877.c: Newtest

./kamlesh


On Tue, Mar 24, 2020 at 10:54 PM Hans-Peter Nilsson  wrote:
>
>
> On Tue, 24 Mar 2020, Hans-Peter Nilsson wrote:
> > The new argument is default 0, so make use of that: do not patch
> > all those files where 0 is fine.
>
> Oops, I was tricked by the comment; it's not actually "default 0"
> in the C++ sense.  And you have an overloaded function with
> different numbers of parameters; I don't know if you can get
> away cheaper than all those files you patched.  Sorry for the
> noise in that part; the ChangeLog formatting comment still
> applies.
>
> brgds, H-P


Re: [PATCH][PPC64] [PR88877]

2020-04-05 Thread kamlesh kumar via Gcc-patches
Segher,
Please provide your suggestion/thought on the fix.

On Mon, Mar 23, 2020 at 8:16 PM kamlesh kumar  wrote:
>
> Attached patch fixes.
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877.
> ChangeLog Entry.
>
> 2020-03-23  Kamlesh Kumar  
>
> * rtl.h : Defined Tuple for bundling rtx, mode and
> unsignedness default as 0
> Added Extra argument (unsignedp) in emit_library_call and
> emit_library_call_value.
> * except.c : Likewise.
> * explow.c : Likewise.
> * expmed.c : Likewise.
> * expr.c : Likewise.
> * optabs.c : Likewise.
> * asan.c : Likewise.
> * builtins.c : Likewise.
> * calls.c : Likewise.
> * cfgexpand.c : Likewise.
> * config/aarch64/aarch64.c : Likewise.
> * config/aarch64/aarch64.h : Likewise.
> * config/aarch64/atomics.md : Likewise.
> * config/alpha/alpha.c : Likewise.
> * config/arc/arc.c : Likewise.
> * config/arc/elf.h : Likewise.
> * config/arc/linux.h : Likewise.
> * config/arm/arm.c : Likewise.
> * config/bfin/bfin.md : Likewise.
> * config/c6x/c6x.c : Likewise.
> * config/csky/csky.c : Likewise.
> * config/frv/frv.c : Likewise.
> * config/i386/i386-expand.c : Likewise.
> * config/i386/i386.c : Likewise.
> * config/ia64/ia64.c : Likewise.
> * config/ia64/ia64.md : Likewise.
> * config/m32r/m32r.c : Likewise.
> * config/m68k/linux.h : Likewise.
> * config/m68k/m68k.c : Likewise.
> * config/microblaze/microblaze.c : Likewise.
> * config/mips/mips.h : Likewise.
> * config/mips/sdemtk.h : Likewise.
> * config/nds32/nds32.h : Likewise.
> * config/nios2/nios2.c : Likewise.
> * config/or1k/or1k.c : Likewise.
> * config/pa/pa.c : Likewise.
> * config/pa/pa.md : Likewise.
> * config/pru/pru.c : Likewise.
> * config/riscv/riscv.h : Likewise.
> * config/riscv/riscv.md : Likewise.
> * config/rl78/rl78.c : Likewise.
> * config/rs6000/rs6000-string.c : Likewise.
> * config/rs6000/rs6000.c : Likewise.
> * config/rs6000/rs6000.md : Likewise.
> * config/rs6000/vsx.md : Likewise.
> * config/sh/sh.c : Likewise.
> * config/sparc/sparc.c : Likewise.
> * config/tilegx/tilegx.c : Likewise.
> * config/tilepro/tilepro.c : Likewise.
> * config/visium/visium.c : Likewise.
> * config/xtensa/xtensa.c : Likewise.
> * testsuite/gcc.target/powerpc/pr88877.c : Newtest


Re: [PATCH][PPC64] [PR88877]

2020-04-06 Thread kamlesh kumar via Gcc-patches
Hi Richard,
Here is a discussion we did some time ago
https://gcc.gnu.org/pipermail/gcc/2019-January/227834.html
please see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877 for more
info regarding the bug.

We incorporated below Jakub's suggestion in this patch.

Jakub wrote:
""
Yeah, all the callers of emit_library_call* would need to be changed to pass
triplets rtx, machine_mode, int/bool /*unsignedp*/, instead of just
rtx_mode_t pair.
Jakub
""

On Mon, Apr 6, 2020 at 2:47 PM Richard Biener  wrote:
>
> On Mon, 6 Apr 2020, kamlesh kumar wrote:
>
> > Segher,
> > Please provide your suggestion/thought on the fix.
>
> There is not a single line of explanation what the change does so what
> do you expect?
>
> Richard.
>
> > On Mon, Mar 23, 2020 at 8:16 PM kamlesh kumar  
> > wrote:
> > >
> > > Attached patch fixes.
> > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877.
> > > ChangeLog Entry.
> > >
> > > 2020-03-23  Kamlesh Kumar  
> > >
> > > * rtl.h : Defined Tuple for bundling rtx, mode and
> > > unsignedness default as 0
> > > Added Extra argument (unsignedp) in emit_library_call and
> > > emit_library_call_value.
> > > * except.c : Likewise.
> > > * explow.c : Likewise.
> > > * expmed.c : Likewise.
> > > * expr.c : Likewise.
> > > * optabs.c : Likewise.
> > > * asan.c : Likewise.
> > > * builtins.c : Likewise.
> > > * calls.c : Likewise.
> > > * cfgexpand.c : Likewise.
> > > * config/aarch64/aarch64.c : Likewise.
> > > * config/aarch64/aarch64.h : Likewise.
> > > * config/aarch64/atomics.md : Likewise.
> > > * config/alpha/alpha.c : Likewise.
> > > * config/arc/arc.c : Likewise.
> > > * config/arc/elf.h : Likewise.
> > > * config/arc/linux.h : Likewise.
> > > * config/arm/arm.c : Likewise.
> > > * config/bfin/bfin.md : Likewise.
> > > * config/c6x/c6x.c : Likewise.
> > > * config/csky/csky.c : Likewise.
> > > * config/frv/frv.c : Likewise.
> > > * config/i386/i386-expand.c : Likewise.
> > > * config/i386/i386.c : Likewise.
> > > * config/ia64/ia64.c : Likewise.
> > > * config/ia64/ia64.md : Likewise.
> > > * config/m32r/m32r.c : Likewise.
> > > * config/m68k/linux.h : Likewise.
> > > * config/m68k/m68k.c : Likewise.
> > > * config/microblaze/microblaze.c : Likewise.
> > > * config/mips/mips.h : Likewise.
> > > * config/mips/sdemtk.h : Likewise.
> > > * config/nds32/nds32.h : Likewise.
> > > * config/nios2/nios2.c : Likewise.
> > > * config/or1k/or1k.c : Likewise.
> > > * config/pa/pa.c : Likewise.
> > > * config/pa/pa.md : Likewise.
> > > * config/pru/pru.c : Likewise.
> > > * config/riscv/riscv.h : Likewise.
> > > * config/riscv/riscv.md : Likewise.
> > > * config/rl78/rl78.c : Likewise.
> > > * config/rs6000/rs6000-string.c : Likewise.
> > > * config/rs6000/rs6000.c : Likewise.
> > > * config/rs6000/rs6000.md : Likewise.
> > > * config/rs6000/vsx.md : Likewise.
> > > * config/sh/sh.c : Likewise.
> > > * config/sparc/sparc.c : Likewise.
> > > * config/tilegx/tilegx.c : Likewise.
> > > * config/tilepro/tilepro.c : Likewise.
> > > * config/visium/visium.c : Likewise.
> > > * config/xtensa/xtensa.c : Likewise.
> > > * testsuite/gcc.target/powerpc/pr88877.c : Newtest
> >
>
> --
> Richard Biener 
> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
> Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)


[PATCH][libstd++][PR92156]

2020-04-17 Thread kamlesh kumar via Gcc-patches
This patch corrects the requirement  of 4,5 and 6th constructor
As per https://en.cppreference.com/w/cpp/utility/any/any.

ChangeLog:
2020-04-17  Kamlesh Kumar  

PR libstdc++/92156
* include/std/any (ans::any(_ValueType &&):: Remove
is_constructible.
(any::any(in_place_type_t<_ValueType>, _Args&&...)): Use decay_t.
(any::any(in_place_type_t<_ValueType>,initializer_list<_Up>,
_Args&&...)):
Use decay_t.
 * testsuite/20_util/any/misc/92156.cc: New Test.

diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index 6b7e68f0e63..fb212eb2231 100644
--- a/libstdc++-v3/include/std/any
+++ b/libstdc++-v3/include/std/any
@@ -178,30 +178,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 /// Construct with a copy of @p __value as the contained object.
 template ,
   typename _Mgr = _Manager<_Tp>,
-  __any_constructible_t<_Tp, _ValueType&&> = true,
-  enable_if_t::value, bool> = true>
+  enable_if_t::value &&
+  !__is_in_place_type<_Tp>::value, bool> = true>
   any(_ValueType&& __value)
   : _M_manager(&_Mgr::_S_manage)
   {
 _Mgr::_S_create(_M_storage, std::forward<_ValueType>(__value));
   }

-/// Construct with a copy of @p __value as the contained object.
-template ,
-  typename _Mgr = _Manager<_Tp>,
-  enable_if_t<__and_v,
-  __not_>,
-  __not_<__is_in_place_type<_Tp>>>,
-  bool> = false>
-  any(_ValueType&& __value)
-  : _M_manager(&_Mgr::_S_manage)
-  {
-_Mgr::_S_create(_M_storage, __value);
-  }
-
 /// Construct with an object created from @p __args as the contained
object.
 template ,
+  typename _Tp = decay_t<_ValueType>,
   typename _Mgr = _Manager<_Tp>,
   __any_constructible_t<_Tp, _Args&&...> = false>
   explicit
@@ -214,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 /// Construct with an object created from @p __il and @p __args as
 /// the contained object.
 template ,
+  typename _Tp = decay_t<_ValueType>,
   typename _Mgr = _Manager<_Tp>,
   __any_constructible_t<_Tp, initializer_list<_Up>,
 _Args&&...> = false>
diff --git a/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
new file mode 100644
index 000..c4f1ed55aee
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
@@ -0,0 +1,34 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2014-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include 
+#include 
+#include 
+
+int main() {
+auto a = std::any(std::in_place_type, 5);
+auto b = std::any(std::in_place_type, {1});
+std::any p = std::pair(1, 1);
+(void)p;
+std::any t = std::tuple(1);
+(void)t;
+return 0;
+}
+

Regtested on X86_64-linux.

Thanks,


Re: [PATCH][libstd++][PR92156]

2020-04-17 Thread kamlesh kumar via Gcc-patches
Fixes all this.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92156
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91630
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90415

On Fri, Apr 17, 2020 at 10:45 PM kamlesh kumar  wrote:
>
> This patch corrects the requirement  of 4,5 and 6th constructor
> As per https://en.cppreference.com/w/cpp/utility/any/any.
>
> ChangeLog:
> 2020-04-17  Kamlesh Kumar  
>
> PR libstdc++/92156
> * include/std/any (ans::any(_ValueType &&):: Remove is_constructible.
> (any::any(in_place_type_t<_ValueType>, _Args&&...)): Use decay_t.
> (any::any(in_place_type_t<_ValueType>,initializer_list<_Up>, 
> _Args&&...)):
> Use decay_t.
>  * testsuite/20_util/any/misc/92156.cc: New Test.
>
> diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
> index 6b7e68f0e63..fb212eb2231 100644
> --- a/libstdc++-v3/include/std/any
> +++ b/libstdc++-v3/include/std/any
> @@ -178,30 +178,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  /// Construct with a copy of @p __value as the contained object.
>  template ,
>typename _Mgr = _Manager<_Tp>,
> -  __any_constructible_t<_Tp, _ValueType&&> = true,
> -  enable_if_t::value, bool> = true>
> +  enable_if_t::value &&
> +  !__is_in_place_type<_Tp>::value, bool> = true>
>any(_ValueType&& __value)
>: _M_manager(&_Mgr::_S_manage)
>{
>  _Mgr::_S_create(_M_storage, std::forward<_ValueType>(__value));
>}
>
> -/// Construct with a copy of @p __value as the contained object.
> -template ,
> -  typename _Mgr = _Manager<_Tp>,
> -  enable_if_t<__and_v,
> -  __not_>,
> -  __not_<__is_in_place_type<_Tp>>>,
> -  bool> = false>
> -  any(_ValueType&& __value)
> -  : _M_manager(&_Mgr::_S_manage)
> -  {
> -_Mgr::_S_create(_M_storage, __value);
> -  }
> -
>  /// Construct with an object created from @p __args as the contained 
> object.
>  template  -  typename _Tp = _Decay<_ValueType>,
> +  typename _Tp = decay_t<_ValueType>,
>typename _Mgr = _Manager<_Tp>,
>__any_constructible_t<_Tp, _Args&&...> = false>
>explicit
> @@ -214,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  /// Construct with an object created from @p __il and @p __args as
>  /// the contained object.
>  template  -  typename _Tp = _Decay<_ValueType>,
> +  typename _Tp = decay_t<_ValueType>,
>typename _Mgr = _Manager<_Tp>,
>__any_constructible_t<_Tp, initializer_list<_Up>,
>  _Args&&...> = false>
> diff --git a/libstdc++-v3/testsuite/20_util/any/misc/92156.cc 
> b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
> new file mode 100644
> index 000..c4f1ed55aee
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
> @@ -0,0 +1,34 @@
> +// { dg-options "-std=gnu++17" }
> +// { dg-do compile }
> +
> +// Copyright (C) 2014-2020 Free Software Foundation, Inc.
> +//
> +// This file is part of the GNU ISO C++ Library.  This library is free
> +// software; you can redistribute it and/or modify it under the
> +// terms of the GNU General Public License as published by the
> +// Free Software Foundation; either version 3, or (at your option)
> +// any later version.
> +
> +// This library is distributed in the hope that it will be useful,
> +// but WITHOUT ANY WARRANTY; without even the implied warranty of
> +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +// GNU General Public License for more details.
> +
> +// You should have received a copy of the GNU General Public License along
> +// with this library; see the file COPYING3.  If not see
> +// <http://www.gnu.org/licenses/>.
> +
> +#include 
> +#include 
> +#include 
> +
> +int main() {
> +auto a = std::any(std::in_place_type, 5);
> +auto b = std::any(std::in_place_type, {1});
> +std::any p = std::pair(1, 1);
> +(void)p;
> +std::any t = std::tuple(1);
> +(void)t;
> +return 0;
> +}
> +
>
> Regtested on X86_64-linux.
>
> Thanks,
>


Re: [PATCH][libstd++][PR92156]

2020-04-17 Thread kamlesh kumar via Gcc-patches
On Fri, Apr 17, 2020, 10:59 PM kamlesh kumar 
wrote:

> Fixes all this.
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92156
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91630
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90415
>
> On Fri, Apr 17, 2020 at 10:45 PM kamlesh kumar 
> wrote:
> >
> > This patch corrects the requirement  of 4,5 and 6th constructor
> > As per https://en.cppreference.com/w/cpp/utility/any/any.
> >
> > ChangeLog:
> > 2020-04-17  Kamlesh Kumar  
> >
> > PR libstdc++/92156
> > * include/std/any (ans::any(_ValueType &&):: Remove
> is_constructible.
> > (any::any(in_place_type_t<_ValueType>, _Args&&...)): Use decay_t.
> > (any::any(in_place_type_t<_ValueType>,initializer_list<_Up>,
> _Args&&...)):
> > Use decay_t.
> >  * testsuite/20_util/any/misc/92156.cc: New Test.
> >
> > diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
> > index 6b7e68f0e63..fb212eb2231 100644
> > --- a/libstdc++-v3/include/std/any
> > +++ b/libstdc++-v3/include/std/any
> > @@ -178,30 +178,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >  /// Construct with a copy of @p __value as the contained object.
> >  template ,
> >typename _Mgr = _Manager<_Tp>,
> > -  __any_constructible_t<_Tp, _ValueType&&> = true,
> > -  enable_if_t::value, bool> = true>
> > +  enable_if_t::value &&
> > +  !__is_in_place_type<_Tp>::value, bool> = true>
> >any(_ValueType&& __value)
> >: _M_manager(&_Mgr::_S_manage)
> >{
> >  _Mgr::_S_create(_M_storage, std::forward<_ValueType>(__value));
> >}
> >
> > -/// Construct with a copy of @p __value as the contained object.
> > -template ,
> > -  typename _Mgr = _Manager<_Tp>,
> > -  enable_if_t<__and_v,
> > -  __not_>,
> > -  __not_<__is_in_place_type<_Tp>>>,
> > -  bool> = false>
> > -  any(_ValueType&& __value)
> > -  : _M_manager(&_Mgr::_S_manage)
> > -  {
> > -_Mgr::_S_create(_M_storage, __value);
> > -  }
> > -
> >  /// Construct with an object created from @p __args as the
> contained object.
> >  template  > -  typename _Tp = _Decay<_ValueType>,
> > +  typename _Tp = decay_t<_ValueType>,
> >typename _Mgr = _Manager<_Tp>,
> >__any_constructible_t<_Tp, _Args&&...> = false>
> >explicit
> > @@ -214,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >  /// Construct with an object created from @p __il and @p __args as
> >  /// the contained object.
> >  template  > -  typename _Tp = _Decay<_ValueType>,
> > +  typename _Tp = decay_t<_ValueType>,
> >typename _Mgr = _Manager<_Tp>,
> >__any_constructible_t<_Tp, initializer_list<_Up>,
> >  _Args&&...> = false>
> > diff --git a/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
> b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
> > new file mode 100644
> > index 000..c4f1ed55aee
> > --- /dev/null
> > +++ b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
> > @@ -0,0 +1,34 @@
> > +// { dg-options "-std=gnu++17" }
> > +// { dg-do compile }
> > +
> > +// Copyright (C) 2014-2020 Free Software Foundation, Inc.
> > +//
> > +// This file is part of the GNU ISO C++ Library.  This library is free
> > +// software; you can redistribute it and/or modify it under the
> > +// terms of the GNU General Public License as published by the
> > +// Free Software Foundation; either version 3, or (at your option)
> > +// any later version.
> > +
> > +// This library is distributed in the hope that it will be useful,
> > +// but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +// GNU General Public License for more details.
> > +
> > +// You should have received a copy of the GNU General Public License
> along
> > +// with this library; see the file COPYING3.  If not see
> > +// <http://www.gnu.org/licenses/>.
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +int main() {
> > +auto a = std::any(std::in_place_type, 5);
> > +auto b = std::any(std::in_place_type, {1});
> > +std::any p = std::pair(1, 1);
> > +(void)p;
> > +std::any t = std::tuple(1);
> > +(void)t;
> > +return 0;
> > +}
> > +
> >
> > Regtested on X86_64-linux.
> >
> > Thanks,
> >
>


Re: [PATCH][libstd++][PR92156]

2020-04-20 Thread kamlesh kumar via Gcc-patches
Thank you for reviewing.
without  _Decay to decay_t in the constructor which takes inplace_type_t,
cases like this fails
auto a = std::any(std::in_place_type, 5);

for these constructors, standard does not say anything about
not-sameness checks with any.
https://en.cppreference.com/w/cpp/utility/any/any.

./kamlesh


On Mon, Apr 20, 2020 at 11:54 PM Ville Voutilainen
 wrote:
>
> On Mon, 20 Apr 2020 at 21:09, Ville Voutilainen
>  wrote:
> >
> > On Sat, 18 Apr 2020 at 03:35, kamlesh kumar via Libstdc++
> >  wrote:
> > >
> > > On Fri, Apr 17, 2020, 10:59 PM kamlesh kumar 
> > > wrote:
> > >
> > > > Fixes all this.
> > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92156
> > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91630
> > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90415
> > > >
> > > > On Fri, Apr 17, 2020 at 10:45 PM kamlesh kumar 
> > > > wrote:
> > > > >
> > > > > This patch corrects the requirement  of 4,5 and 6th constructor
> > > > > As per https://en.cppreference.com/w/cpp/utility/any/any.
> >
> > The patch looks correct to me. We have some old cruft there, like the
> > overload your patch removes, it was
> > there to support copy-only types, but LWG issues axed that bit. This
> > constructor indeed should not check is_constructible,
> > because it'll end up instantiating this constructor itself, and
> > compute its constraints, and instantiate itself.
> > The in_place constructor doesn't have that problem, because it won't
> > instantiate itself.
>
> ..except the change from _Decay to decay_t looks wrong. _Decay also
> checks the non-sameness with
> any. That change shouldn't be made.


Re: [PATCH][libstd++][PR92156]

2020-04-21 Thread kamlesh kumar via Gcc-patches
Added the fix for emplace.

diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index 6b7e68f0e63..f35d90e548d 100644
--- a/libstdc++-v3/include/std/any
+++ b/libstdc++-v3/include/std/any
@@ -178,30 +178,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 /// Construct with a copy of @p __value as the contained object.
 template ,
   typename _Mgr = _Manager<_Tp>,
-  __any_constructible_t<_Tp, _ValueType&&> = true,
-  enable_if_t::value, bool> = true>
+  enable_if_t::value &&
+  !__is_in_place_type<_Tp>::value, bool> = true>
   any(_ValueType&& __value)
   : _M_manager(&_Mgr::_S_manage)
   {
 _Mgr::_S_create(_M_storage, std::forward<_ValueType>(__value));
   }

-/// Construct with a copy of @p __value as the contained object.
-template ,
-  typename _Mgr = _Manager<_Tp>,
-  enable_if_t<__and_v,
-  __not_>,
-  __not_<__is_in_place_type<_Tp>>>,
-  bool> = false>
-  any(_ValueType&& __value)
-  : _M_manager(&_Mgr::_S_manage)
-  {
-_Mgr::_S_create(_M_storage, __value);
-  }
-
 /// Construct with an object created from @p __args as the contained
object.
 template ,
+  typename _Tp = decay_t<_ValueType>,
   typename _Mgr = _Manager<_Tp>,
   __any_constructible_t<_Tp, _Args&&...> = false>
   explicit
@@ -214,7 +201,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 /// Construct with an object created from @p __il and @p __args as
 /// the contained object.
 template ,
+  typename _Tp = decay_t<_ValueType>,
   typename _Mgr = _Manager<_Tp>,
   __any_constructible_t<_Tp, initializer_list<_Up>,
 _Args&&...> = false>
@@ -267,31 +254,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }

 /// Emplace with an object created from @p __args as the contained
object.
-template 
-  typename __any_constructible<_Decay<_ValueType>&,
-   _Decay<_ValueType>, _Args&&...>::type
+template >
+  typename __any_constructible<_Tp&,
+   _Tp, _Args&&...>::type
   emplace(_Args&&... __args)
   {
- __do_emplace<_Decay<_ValueType>>(std::forward<_Args>(__args)...);
+ __do_emplace<_Tp>(std::forward<_Args>(__args)...);
  any::_Arg __arg;
  this->_M_manager(any::_Op_access, this, &__arg);
- return *static_cast<_Decay<_ValueType>*>(__arg._M_obj);
+ return *static_cast<_Tp*>(__arg._M_obj);
   }

 /// Emplace with an object created from @p __il and @p __args as
 /// the contained object.
-template 
-  typename __any_constructible<_Decay<_ValueType>&,
-   _Decay<_ValueType>,
+template >
+  typename __any_constructible<_Tp&,
+   _Tp,
initializer_list<_Up>,
_Args&&...>::type
   emplace(initializer_list<_Up> __il, _Args&&... __args)
   {
- __do_emplace<_Decay<_ValueType>, _Up>(__il,
+ __do_emplace<_Tp, _Up>(__il,
   std::forward<_Args>(__args)...);
  any::_Arg __arg;
  this->_M_manager(any::_Op_access, this, &__arg);
- return *static_cast<_Decay<_ValueType>*>(__arg._M_obj);
+ return *static_cast<_Tp*>(__arg._M_obj);
   }

 // modifiers
diff --git a/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
new file mode 100644
index 000..c4f1ed55aee
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
@@ -0,0 +1,34 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2014-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include 
+#include 
+#include 
+
+int main() {
+auto a = std::any(std::in_place_type, 5);
+auto b = std::any(std::in_place_type, {1});
+std::any p = std::pair(1, 1);
+(void)p;
+std::any t = std::tuple(1);
+(void)t;
+return 0;
+}
+

thanks,


On Tue, Apr 21, 2020 at 12:09 PM Ville Voutilainen <
ville.voutilai...@gmail.com> wrote:

> O

Re: [PATCH][libstd++][PR92156]

2020-04-21 Thread kamlesh kumar via Gcc-patches
- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/any/misc/92156.cc
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2014-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+int main() {
+auto a = std::any(std::in_place_type, 5);
+VERIFY(std::any_cast(a) == 5);
+auto b = std::any(std::in_place_type, {1});
+VERIFY(std::any_cast(b) == 1);
+std::any p = std::pair(1, 1);
+VERIFY((std::any_cast>(p) == std::pair(1,1)));
+std::any t = std::tuple(1);
+VERIFY((std::any_cast>(t) == std::tuple(1)));
+return 0;
+}
+

thanks,


On Tue, Apr 21, 2020 at 5:14 PM Ville Voutilainen
 wrote:
>
> On Tue, 21 Apr 2020 at 11:29, kamlesh kumar  wrote:
> >
> > Added the fix for emplace.
> >
> > diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
> > index 6b7e68f0e63..f35d90e548d 100644
> > --- a/libstdc++-v3/include/std/any
> > +++ b/libstdc++-v3/include/std/any
> > @@ -178,30 +178,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >  /// Construct with a copy of @p __value as the contained object.
> >  template ,
>
> While we're at it, we should rename _ValueType to _Tp and the decayed
> type to _VTp,
> so that it matches the standard's naming as close as possible, and
> thus removes the ongoing
> maintenance confusion about which is which.
>
> > +int main() {
> > +auto a = std::any(std::in_place_type, 5);
> > +auto b = std::any(std::in_place_type, {1});
> > +std::any p = std::pair(1, 1);
> > +(void)p;
> > +std::any t = std::tuple(1);
>
> I think this sort of tests should VERIFY that the constructed any
> contains what we expect.
> Iow, do an any_cast and check that, for instance, a and b contain an any.


Re: [PATCH][PPC64] [PR88877]

2020-05-19 Thread kamlesh kumar via Gcc-patches
can someone look at the patch, please?


On Wed, Apr 8, 2020 at 9:29 PM Jeff Law  wrote:

> On Mon, 2020-04-06 at 14:58 +0530, kamlesh kumar via Gcc-patches wrote:
> > Hi Richard,
> > Here is a discussion we did some time ago
> > https://gcc.gnu.org/pipermail/gcc/2019-January/227834.html
> > please see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877 for more
> > info regarding the bug.
> >
> > We incorporated below Jakub's suggestion in this patch.
> >
> > Jakub wrote:
> > ""
> > Yeah, all the callers of emit_library_call* would need to be changed to
> pass
> > triplets rtx, machine_mode, int/bool /*unsignedp*/, instead of just
> > rtx_mode_t pair.
> > Jakub
> > ""
> I think you're generally on the right track here, but I'm deferring this
> to gcc11
> (other maintainers are, of course, welcome to push it for gcc10 as it's a
> code
> correctness issue).
>
> Jeff
> >
>
>


Re: [PATCH][PPC64] [PR88877]

2020-05-22 Thread kamlesh kumar via Gcc-patches
ping?

On Tue, May 19, 2020 at 5:32 PM kamlesh kumar 
wrote:

> can someone look at the patch, please?
>
>
> On Wed, Apr 8, 2020 at 9:29 PM Jeff Law  wrote:
>
>> On Mon, 2020-04-06 at 14:58 +0530, kamlesh kumar via Gcc-patches wrote:
>> > Hi Richard,
>> > Here is a discussion we did some time ago
>> > https://gcc.gnu.org/pipermail/gcc/2019-January/227834.html
>> > please see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877 for more
>> > info regarding the bug.
>> >
>> > We incorporated below Jakub's suggestion in this patch.
>> >
>> > Jakub wrote:
>> > ""
>> > Yeah, all the callers of emit_library_call* would need to be changed to
>> pass
>> > triplets rtx, machine_mode, int/bool /*unsignedp*/, instead of just
>> > rtx_mode_t pair.
>> > Jakub
>> > ""
>> I think you're generally on the right track here, but I'm deferring this
>> to gcc11
>> (other maintainers are, of course, welcome to push it for gcc10 as it's a
>> code
>> correctness issue).
>>
>> Jeff
>> >
>>
>>


[PATCH v1 1/2][PPC64] [PR88877]

2020-05-24 Thread Kamlesh Kumar via Gcc-patches
Here is a discussion we did some time ago regarding the defect.
https://gcc.gnu.org/pipermail/gcc/2019-January/227834.html
please see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88877 for testcase
behavior.

We incorporating below Jakub's suggestion in this patch series.

Jakub wrote:
""
Yeah, all the callers of emit_library_call* would need to be changed to pass
triplets rtx, machine_mode, int/bool /*unsignedp*/, instead of just
rtx_mode_t pair.
""


In this patch series trying to address same by creating a struct Tuple
which bundles existing rtx and machine_mode and added one more
bool member which store unsigned_p which by default is false.
This patch does not change underlying behavior yet. This will be done in
follow up patches.

ChangeLog Entry:

2020-05-24 Kamlesh Kumar 

* rtl.h (Tuple): Defined and typedefed to rtx_mode_t.
(emit_library_call): Added default arg unsigned_p.
(emit_library_call_value): Added default arg unsigned_p.
---
 gcc/rtl.h | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/gcc/rtl.h b/gcc/rtl.h
index b0b1aac..ee42de7 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2238,10 +2238,20 @@ struct address_info {
   enum rtx_code base_outer_code;
 };
 
-/* This is used to bundle an rtx and a mode together so that the pair
-   can be used with the wi:: routines.  If we ever put modes into rtx
-   integer constants, this should go away and then just pass an rtx in.  */
-typedef std::pair  rtx_mode_t;
+/* This is used to bundle an rtx and a mode and unsignedness together so
+   that the tuple can be used with the wi:: routines.  If we ever put modes
+   into rtx integer constants, this should go away and then just pass an rtx 
in.  */
+typedef struct Tuple {
+  rtx first;
+  machine_mode second;
+  /* unsigned_p  */
+  bool third;
+  Tuple (rtx f, machine_mode s, bool t = false) {
+first = f;
+second = s;
+third = t;
+  }
+} rtx_mode_t;
 
 namespace wi
 {
@@ -4176,9 +4186,9 @@ emit_library_call (rtx fun, libcall_type fn_type, 
machine_mode outmode)
 
 inline void
 emit_library_call (rtx fun, libcall_type fn_type, machine_mode outmode,
-  rtx arg1, machine_mode arg1_mode)
+  rtx arg1, machine_mode arg1_mode, bool unsigned_p = false)
 {
-  rtx_mode_t args[] = { rtx_mode_t (arg1, arg1_mode) };
+  rtx_mode_t args[] = { rtx_mode_t (arg1, arg1_mode, unsigned_p) };
   emit_library_call_value_1 (0, fun, NULL_RTX, fn_type, outmode, 1, args);
 }
 
@@ -4238,9 +4248,9 @@ emit_library_call_value (rtx fun, rtx value, libcall_type 
fn_type,
 inline rtx
 emit_library_call_value (rtx fun, rtx value, libcall_type fn_type,
 machine_mode outmode,
-rtx arg1, machine_mode arg1_mode)
+rtx arg1, machine_mode arg1_mode, bool unsigned_p = 
false)
 {
-  rtx_mode_t args[] = { rtx_mode_t (arg1, arg1_mode) };
+  rtx_mode_t args[] = { rtx_mode_t (arg1, arg1_mode, unsigned_p) };
   return emit_library_call_value_1 (1, fun, value, fn_type, outmode, 1, args);
 }
 
-- 
2.7.4



Re: [PATCH v1 1/2][PPC64] [PR88877]

2020-05-25 Thread kamlesh kumar via Gcc-patches
> OTOH, you don't need to name Tuple at all...  It should not *have* a
> constructor, since you declared it as class...  But you can just use
> std::tuple here?

I thought of using std::tuple  but it requires c++11 support.
I am not sure we always build gcc with c++11?

>
> > (emit_library_call): Added default arg unsigned_p.
> > (emit_library_call_value): Added default arg unsigned_p.
>
> Yeah, eww.  Default arguments have all the problems you had before,
> except now it is hidden and much more surprising.
>
> Those functions really should take rtx_mode_t arguments?

I was thinking the same. will incorporate this.

./kamlesh


[PATCH] Defined libcall_arg_t

2020-06-13 Thread Kamlesh Kumar via Gcc-patches
This is first patch where I have just defined a struct libcall_arg_t which 
contains
three member rtx, machine_mode and a boolean unsigned_p and will be used in 
passing args in
emit_library_[call/value] functions.

Once this patch is approved then i will create second patch in which arg type 
libcall_arg_t will be
propogated on all instances needed.
Then final patch which will fix the actual problem reported in PR88877.

ChangeLog Entry:

2020-06-13  Kamlesh Kumar  

   * rtl.h (libcall_arg_t): Defined.


---
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0872cc4..c023ff0 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2238,6 +2238,18 @@ struct address_info {
   enum rtx_code base_outer_code;
 };
 
+/* This is used for passing args in emit_library_* functions */
+typedef struct libcall_arg {
+  rtx value;
+  machine_mode mode;
+  bool unsigned_p;
+  libcall_arg (rtx v, machine_mode m, bool u) {
+value = v;
+mode = m;
+unsigned_p = u;
+  }
+} libcall_arg_t;
+
 /* This is used to bundle an rtx and a mode together so that the pair
can be used with the wi:: routines.  If we ever put modes into rtx
integer constants, this should go away and then just pass an rtx in.  */
-- 
2.7.4



[PATCH] Defined libcall_arg_t

2020-06-13 Thread Kamlesh Kumar via Gcc-patches
This is first patch where I have just defined a struct libcall_arg_t which 
contains
three member rtx, machine_mode and a boolean unsigned_p and will be used in 
passing args in
emit_library_[call/value] functions.

Once this patch is approved then i will create second patch in which arg type 
libcall_arg_t will be
propogated on all instances needed.
Then final patch which will fix the actual problem reported in PR88877.

ChangeLog Entry:

2020-06-13  Kamlesh Kumar  

   * rtl.h (libcall_arg_t): Defined.


---
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0872cc4..c023ff0 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2238,6 +2238,18 @@ struct address_info {
   enum rtx_code base_outer_code;
 };
 
+/* This is used for passing args in emit_library_* functions */
+typedef struct libcall_arg {
+  rtx value;
+  machine_mode mode;
+  bool unsigned_p;
+  libcall_arg (rtx v, machine_mode m, bool u) {
+value = v;
+mode = m;
+unsigned_p = u;
+  }
+} libcall_arg_t;
+
 /* This is used to bundle an rtx and a mode together so that the pair
can be used with the wi:: routines.  If we ever put modes into rtx
integer constants, this should go away and then just pass an rtx in.  */
-- 
2.7.4



Re: [PATCH v1 1/2][PPC64] [PR88877]

2020-06-13 Thread kamlesh kumar via Gcc-patches
Thank you all for the suggestions.
This is first patch where I have just defined a struct libcall_arg_t
which contains
three member rtx, machine_mode and a boolean unsigned_p and will be
used in passing args in
emit_library_[call/value] functions.

Once this patch is approved then i will create second patch in which
arg type libcall_arg_t will be
propogated on all instances needed.
Then final patch which will fix the actual problem reported in PR88877.

ChangeLog Entry:

2020-06-13  Kamlesh Kumar  

   * rtl.h (libcall_arg_t): Defined.


---
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0872cc4..c023ff0 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2238,6 +2238,18 @@ struct address_info {
   enum rtx_code base_outer_code;
 };

+/* This is used for passing args in emit_library_* functions */
+typedef struct libcall_arg {
+  rtx value;
+  machine_mode mode;
+  bool unsigned_p;
+  libcall_arg (rtx v, machine_mode m, bool u) {
+value = v;
+mode = m;
+unsigned_p = u;
+  }
+} libcall_arg_t;
+
 /* This is used to bundle an rtx and a mode together so that the pair
can be used with the wi:: routines.  If we ever put modes into rtx
integer constants, this should go away and then just pass an rtx in.  */
--
2.7.4

On Fri, Jun 12, 2020 at 4:43 AM Segher Boessenkool
 wrote:
>
> On Tue, Jun 09, 2020 at 02:29:13PM -0600, Jeff Law wrote:
> > On Sun, 2020-05-24 at 11:22 -0500, Segher Boessenkool wrote:
> > > OTOH, you don't need to name Tuple at all...  It should not *have* a
> > > constructor, since you declared it as class...  But you can just use
> > > std::tuple here?
> > >
> > > > (emit_library_call): Added default arg unsigned_p.
> > > > (emit_library_call_value): Added default arg unsigned_p.
> > >
> > > Yeah, eww.  Default arguments have all the problems you had before,
> > > except now it is hidden and much more surprising.
> > >
> > > Those functions really should take rtx_mode_t arguments?
> > >
> > > Thanks again for working on this,
> > ISTM that using std::tuple would be better than defining our own types.
>
> Yeah.  But as Jakub an Iain said, not using a container type (but a more
> concrete type, instead) is much better anyway :-)
>
> > I'd rather see the argument be explicit rather than using default arguments 
> > too.
> > While I have ack'd some patches with default arguments, I still don't like 
> > 'em.
>
> Default arguments have their place (but it's not here :-) )
>
> > I do like the approach of getting the infrastructure in place without 
> > changing
> > behavior, then having the behavior fix as a distinct change.
>
> With Git, commits are easy and cheap, and massaging a patch series into
> shape is easy and cheap as well.  If you develop using Git in the first
> place (and you should!), you should naturally end up with many patches
> in your series, and the preparatory patches first (after you reshuffle
> things a bit, if you are like me and your foresight is severly limited).
>
> So you have this separate *anyway* (or should have).  Since it helps
> reviewing a lot, and also later bisecting, it is good to keep it.
>
>
> Segher


Re: [PATCH] Defined libcall_arg_t

2020-06-16 Thread Kamlesh Kumar via Gcc-patches

thanks Richard,

addressed your concern.

diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0872cc4..7206c8a 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2238,6 +2238,16 @@ struct address_info {
   enum rtx_code base_outer_code;
 };

+/* This is used for passing args in emit_library_* functions */
+struct libcall_arg {
+  rtx value;
+  machine_mode mode;
+  bool unsigned_p;
+  constexpr
+  libcall_arg (rtx v, machine_mode m, bool u) : value(v), mode(m),
+    unsigned_p(u) {}
+};
+
 /* This is used to bundle an rtx and a mode together so that the pair
    can be used with the wi:: routines.  If we ever put modes into rtx
    integer constants, this should go away and then just pass an rtx 
in.  */


On 16/06/20 2:34 pm, Richard Sandiford wrote:

Thanks for doing this.

Kamlesh Kumar via Gcc-patches  writes:

diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0872cc4..c023ff0 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2238,6 +2238,18 @@ struct address_info {
enum rtx_code base_outer_code;
  };
  
+/* This is used for passing args in emit_library_* functions */

+typedef struct libcall_arg {

There's not really any need for a typedef here.  We should just
use “libcall_arg” directly.


+  rtx value;
+  machine_mode mode;
+  bool unsigned_p;
+  libcall_arg (rtx v, machine_mode m, bool u) {
+value = v;
+mode = m;
+unsigned_p = u;
+  }

Please use member initialisation for the fields instead.

Now that we're C++11, the constructor might as well be constexpr.

Thanks,
Richard


+} libcall_arg_t;
+
  /* This is used to bundle an rtx and a mode together so that the pair
 can be used with the wi:: routines.  If we ever put modes into rtx
 integer constants, this should go away and then just pass an rtx in.  */


PATCH [DR2303][PR97453]

2020-10-21 Thread kamlesh kumar via Gcc-patches
gcc/cp/ChangeLog
---

2020-10-21  Kamlesh Kumar  

PR c++/97453
* pt.c (get_template_base): Implement DR2303,
Consider closest base while template
deduction when base of base also matches.

gcc/testsuite/ChangeLog
--

2020-10-21  Kamlesh Kumar  

* g++.dg/Drs/dr2303.C: New Test

--

As part of this patch I Implemented fix for below defect report in cwg
https://wg21.cmeerw.net/cwg/issue2303 .
Reg tested on x86_64 and did not found any failure.
Patch summary: Remove base of base from list of bases

created a hash_set from list of bases and then iterate over each
element of hash_set and find its  list of bases and remove this from
hash_set if present.
and finally, deduction succeeds if in hash_set remains only single
element or it's empty.
otherwise deduction is ambiguous.
---
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dc664ec3798..7adf461e108 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -22643,8 +22643,9 @@ static enum template_base_result
 get_template_base (tree tparms, tree targs, tree parm, tree arg,
 bool explain_p, tree *result)
 {
-  tree rval = NULL_TREE;
+  *result = NULL_TREE;
   tree binfo;
+  hash_set binfo_set;

   gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (arg)));

@@ -22659,31 +22660,51 @@ get_template_base (tree tparms, tree targs,
tree parm, tree arg,
   /* Walk in inheritance graph order.  The search order is not
  important, and this avoids multiple walks of virtual bases.  */
   for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN (binfo))
-{
-  tree r = try_class_unification (tparms, targs, parm,
-   BINFO_TYPE (binfo), explain_p);
-
-  if (r)
- {
-   /* If there is more than one satisfactory baseclass, then:
-
-[temp.deduct.call]
+ {
+   tree r = try_class_unification (tparms, targs, parm,
+   BINFO_TYPE (binfo), explain_p);
+   if (r)
+ {
+   binfo_set.add(r);
+ }
+ }

-   If they yield more than one possible deduced A, the type
-   deduction fails.
+  /* If there is more than one satisfactory baseclass, then:
+ [temp.deduct.call]
+  If they yield more than one possible deduced A, the type
+  deduction fails.
+ However, if there is a class C that is a (direct or indirect)
base class of
+ D and derived (directly or indirectly) from a class B and that would be a
+ valid deduced A, the deduced A cannot be B or pointer to B,
respectively.  */
+  for (hash_set::iterator it = binfo_set.begin();
+it != binfo_set.end(); ++it)
+{
+  binfo = TYPE_BINFO (*it);
+  for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN (binfo))
+{
+  tree r = try_class_unification (tparms, targs, parm,
+  BINFO_TYPE (binfo), explain_p);
+  if (r && binfo_set.contains(r))
+{
+  binfo_set.remove(r);
+}
+}
+}

-  applies.  */
-   if (rval && !same_type_p (r, rval))
- {
-   *result = NULL_TREE;
-   return tbr_ambiguous_baseclass;
- }
+  if (binfo_set.elements() > 1)
+{
+  return tbr_ambiguous_baseclass;
+}

-   rval = r;
- }
+  if (binfo_set.is_empty())
+{
+  return tbr_success;
 }

-  *result = rval;
+  if (binfo_set.elements() == 1)
+{
+  *result = *binfo_set.begin();
+}
   return tbr_success;
 }

diff --git a/gcc/testsuite/g++.dg/DRs/dr2303.C
b/gcc/testsuite/g++.dg/DRs/dr2303.C
new file mode 100644
index 000..b4c23332358
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr2303.C
@@ -0,0 +1,20 @@
+// DR 2303
+// PR c++/97453
+// { dg-do compile { target c++11 } }
+
+template 
+struct A;
+template <>
+struct A<> {};
+template 
+struct A : A {};
+struct B : A {};
+
+template 
+void f(const A &) {
+  static_assert(sizeof...(T) == 2, "it should duduce to A");
+}
+
+void g() {
+  f(B{});
+}


./kamlesh


[PATCH] c++: Implement DR2303 [PR97453]

2020-10-22 Thread kamlesh kumar via Gcc-patches
Attaching the patch file.

>>Instead of building a hash table, would it work to handle ambiguity by
>>checking whether one of the classes is a base of the other?
Fixing for cases like: struct B: A,A may not be cleaner this
way.

On Thu, Oct 22, 2020 at 3:23 AM Jason Merrill  wrote:
>
> On 10/21/20 6:32 AM, kamlesh kumar wrote:
> > gcc/cp/ChangeLog
> > -------
> >
> > 2020-10-21  Kamlesh Kumar  
> >
> > PR c++/97453
> > * pt.c (get_template_base): Implement DR2303,
> > Consider closest base while template
> > deduction when base of base also matches.
> >
> > gcc/testsuite/ChangeLog
> > --
> >
> > 2020-10-21  Kamlesh Kumar  
> >
> > * g++.dg/Drs/dr2303.C: New Test
> >
> > --
> >
> > As part of this patch I Implemented fix for below defect report in cwg
> > https://wg21.cmeerw.net/cwg/issue2303 .
>
> Thanks!
>
> Please see https://gcc.gnu.org/contribute.html for guidance on email
> subject lines; for this patch I'd think something like
>
> [PATCH] c++: Implement DR2303 [PR97453]
>
> Also, your patch was corrupted by word wrap; the easiest way to avoid
> that is probably to attach the file rather than copy it into the message.
>
> > Reg tested on x86_64 and did not found any failure.
> > Patch summary: Remove base of base from list of bases
> >
> > created a hash_set from list of bases and then iterate over each
> > element of hash_set and find its  list of bases and remove this from
> > hash_set if present.
> > and finally, deduction succeeds if in hash_set remains only single
> > element or it's empty.
> > otherwise deduction is ambiguous.
>
> Instead of building a hash table, would it work to handle ambiguity by
> checking whether one of the classes is a base of the other?
>
> > ---
> > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> > index dc664ec3798..7adf461e108 100644
> > --- a/gcc/cp/pt.c
> > +++ b/gcc/cp/pt.c
> > @@ -22643,8 +22643,9 @@ static enum template_base_result
> >   get_template_base (tree tparms, tree targs, tree parm, tree arg,
> >   bool explain_p, tree *result)
> >   {
> > -  tree rval = NULL_TREE;
> > +  *result = NULL_TREE;
> > tree binfo;
> > +  hash_set binfo_set;
> >
> > gcc_assert (RECORD_OR_UNION_CODE_P (TREE_CODE (arg)));
> >
> > @@ -22659,31 +22660,51 @@ get_template_base (tree tparms, tree targs,
> > tree parm, tree arg,
> > /* Walk in inheritance graph order.  The search order is not
> >important, and this avoids multiple walks of virtual bases.  */
> > for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN (binfo))
> > -{
> > -  tree r = try_class_unification (tparms, targs, parm,
> > -   BINFO_TYPE (binfo), explain_p);
> > -
> > -  if (r)
> > - {
> > -   /* If there is more than one satisfactory baseclass, then:
> > -
> > -[temp.deduct.call]
> > + {
> > +   tree r = try_class_unification (tparms, targs, parm,
> > +   BINFO_TYPE (binfo), explain_p);
> > +   if (r)
> > + {
> > +   binfo_set.add(r);
> > + }
> > + }
> >
> > -   If they yield more than one possible deduced A, the type
> > -   deduction fails.
> > +  /* If there is more than one satisfactory baseclass, then:
> > + [temp.deduct.call]
> > +  If they yield more than one possible deduced A, the type
> > +  deduction fails.
> > + However, if there is a class C that is a (direct or indirect)
> > base class of
> > + D and derived (directly or indirectly) from a class B and that
would be a
> > + valid deduced A, the deduced A cannot be B or pointer to B,
> > respectively.  */
> > +  for (hash_set::iterator it = binfo_set.begin();
> > +it != binfo_set.end(); ++it)
> > +{
> > +  binfo = TYPE_BINFO (*it);
> > +  for (binfo = TREE_CHAIN (binfo); binfo; binfo = TREE_CHAIN
(binfo))
> > +{
> > +  tree r = try_class_unification (tparms, targs, parm,
> > +  BINFO_TYPE (binfo), explain_p);
> > +  if (r && binfo_set.contains(r))
> > +{
> > +  binfo_set.remove(r);
> > +}
> > +}
> > +}
> >
> > -  applies.  */
> > -   if (rval &a