diff mbox series

c++: zero_init_expr_p of dependent expression

Message ID 20200423200948.1949802-2-ppalka@redhat.com
State New
Headers show
Series c++: zero_init_expr_p of dependent expression | expand

Commit Message

Patrick Palka April 23, 2020, 8:09 p.m. UTC
This fixes a ICE coming from mangle.c:write_expression when compiling the
ranges-v3 testsuite; the added testcase is a reduced reproducer of the ICE.

Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on the
cmcstl2, fmt and range-v3 libraries.  Does this look OK to commit?

gcc/cp/ChangeLog:

	* tree.c (zero_init_expr_p): Use uses_template_parms instead of
	dependent_type_p.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/dependent3.C: New test.
---
 gcc/cp/tree.c                           |  2 +-
 gcc/testsuite/g++.dg/cpp0x/dependent3.C | 28 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/dependent3.C

Comments

Jason Merrill April 23, 2020, 9:16 p.m. UTC | #1
On 4/23/20 4:09 PM, Patrick Palka wrote:
> This fixes a ICE coming from mangle.c:write_expression when compiling the
> ranges-v3 testsuite; the added testcase is a reduced reproducer of the ICE.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on the
> cmcstl2, fmt and range-v3 libraries.  Does this look OK to commit?

OK.

> gcc/cp/ChangeLog:
> 
> 	* tree.c (zero_init_expr_p): Use uses_template_parms instead of
> 	dependent_type_p.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp0x/dependent3.C: New test.
> ---
>   gcc/cp/tree.c                           |  2 +-
>   gcc/testsuite/g++.dg/cpp0x/dependent3.C | 28 +++++++++++++++++++++++++
>   2 files changed, 29 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/dependent3.C
> 
> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> index 090c565c093..8840932dba2 100644
> --- a/gcc/cp/tree.c
> +++ b/gcc/cp/tree.c
> @@ -4486,7 +4486,7 @@ bool
>   zero_init_expr_p (tree t)
>   {
>     tree type = TREE_TYPE (t);
> -  if (!type || dependent_type_p (type))
> +  if (!type || uses_template_parms (type))
>       return false;
>     if (zero_init_p (type))
>       return initializer_zerop (t);
> diff --git a/gcc/testsuite/g++.dg/cpp0x/dependent3.C b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
> new file mode 100644
> index 00000000000..caf7e1cd4a4
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
> @@ -0,0 +1,28 @@
> +// { dg-do compile { target c++11 } }
> +
> +template<typename c>
> +struct d
> +{
> +  using e = c;
> +};
> +
> +template<class f>
> +struct g
> +{
> +  using h = typename d<f>::e;
> +
> +  template<class i, class j>
> +  auto operator()(i, j k) -> decltype(h{k});
> +};
> +
> +template<class l>
> +void m()
> +{
> +  int a[1];
> +  l{}(a, a);
> +}
> +
> +int main()
> +{
> +  m<g<int *>>();
> +}
>
Patrick Palka June 16, 2020, 1:06 p.m. UTC | #2
On Thu, Apr 23, 2020 at 5:17 PM Jason Merrill <jason@redhat.com> wrote:
>
> On 4/23/20 4:09 PM, Patrick Palka wrote:
> > This fixes a ICE coming from mangle.c:write_expression when compiling the
> > ranges-v3 testsuite; the added testcase is a reduced reproducer of the ICE.
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on the
> > cmcstl2, fmt and range-v3 libraries.  Does this look OK to commit?
>
> OK.

Is it OK to backport the same patch to the 9 branch in order to resolve PR95678?

>
> > gcc/cp/ChangeLog:> >
> >       * tree.c (zero_init_expr_p): Use uses_template_parms instead of
> >       dependent_type_p.
> >
> > gcc/testsuite/ChangeLog:
> >
> >       * g++.dg/cpp0x/dependent3.C: New test.
> > ---
> >   gcc/cp/tree.c                           |  2 +-
> >   gcc/testsuite/g++.dg/cpp0x/dependent3.C | 28 +++++++++++++++++++++++++
> >   2 files changed, 29 insertions(+), 1 deletion(-)
> >   create mode 100644 gcc/testsuite/g++.dg/cpp0x/dependent3.C
> >
> > diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> > index 090c565c093..8840932dba2 100644
> > --- a/gcc/cp/tree.c
> > +++ b/gcc/cp/tree.c
> > @@ -4486,7 +4486,7 @@ bool
> >   zero_init_expr_p (tree t)
> >   {
> >     tree type = TREE_TYPE (t);
> > -  if (!type || dependent_type_p (type))
> > +  if (!type || uses_template_parms (type))
> >       return false;
> >     if (zero_init_p (type))
> >       return initializer_zerop (t);
> > diff --git a/gcc/testsuite/g++.dg/cpp0x/dependent3.C b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
> > new file mode 100644
> > index 00000000000..caf7e1cd4a4
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
> > @@ -0,0 +1,28 @@
> > +// { dg-do compile { target c++11 } }
> > +
> > +template<typename c>
> > +struct d
> > +{
> > +  using e = c;
> > +};
> > +
> > +template<class f>
> > +struct g
> > +{
> > +  using h = typename d<f>::e;
> > +
> > +  template<class i, class j>
> > +  auto operator()(i, j k) -> decltype(h{k});
> > +};
> > +
> > +template<class l>
> > +void m()
> > +{
> > +  int a[1];
> > +  l{}(a, a);
> > +}
> > +
> > +int main()
> > +{
> > +  m<g<int *>>();
> > +}
> >
>
Jason Merrill June 16, 2020, 4:06 p.m. UTC | #3
On 6/16/20 9:06 AM, Patrick Palka wrote:
> On Thu, Apr 23, 2020 at 5:17 PM Jason Merrill <jason@redhat.com> wrote:
>>
>> On 4/23/20 4:09 PM, Patrick Palka wrote:
>>> This fixes a ICE coming from mangle.c:write_expression when compiling the
>>> ranges-v3 testsuite; the added testcase is a reduced reproducer of the ICE.
>>>
>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on the
>>> cmcstl2, fmt and range-v3 libraries.  Does this look OK to commit?
>>
>> OK.
> 
> Is it OK to backport the same patch to the 9 branch in order to resolve PR95678?

OK.

>>
>>> gcc/cp/ChangeLog:> >
>>>        * tree.c (zero_init_expr_p): Use uses_template_parms instead of
>>>        dependent_type_p.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>>        * g++.dg/cpp0x/dependent3.C: New test.
>>> ---
>>>    gcc/cp/tree.c                           |  2 +-
>>>    gcc/testsuite/g++.dg/cpp0x/dependent3.C | 28 +++++++++++++++++++++++++
>>>    2 files changed, 29 insertions(+), 1 deletion(-)
>>>    create mode 100644 gcc/testsuite/g++.dg/cpp0x/dependent3.C
>>>
>>> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
>>> index 090c565c093..8840932dba2 100644
>>> --- a/gcc/cp/tree.c
>>> +++ b/gcc/cp/tree.c
>>> @@ -4486,7 +4486,7 @@ bool
>>>    zero_init_expr_p (tree t)
>>>    {
>>>      tree type = TREE_TYPE (t);
>>> -  if (!type || dependent_type_p (type))
>>> +  if (!type || uses_template_parms (type))
>>>        return false;
>>>      if (zero_init_p (type))
>>>        return initializer_zerop (t);
>>> diff --git a/gcc/testsuite/g++.dg/cpp0x/dependent3.C b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
>>> new file mode 100644
>>> index 00000000000..caf7e1cd4a4
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
>>> @@ -0,0 +1,28 @@
>>> +// { dg-do compile { target c++11 } }
>>> +
>>> +template<typename c>
>>> +struct d
>>> +{
>>> +  using e = c;
>>> +};
>>> +
>>> +template<class f>
>>> +struct g
>>> +{
>>> +  using h = typename d<f>::e;
>>> +
>>> +  template<class i, class j>
>>> +  auto operator()(i, j k) -> decltype(h{k});
>>> +};
>>> +
>>> +template<class l>
>>> +void m()
>>> +{
>>> +  int a[1];
>>> +  l{}(a, a);
>>> +}
>>> +
>>> +int main()
>>> +{
>>> +  m<g<int *>>();
>>> +}
>>>
>>
>
diff mbox series

Patch

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 090c565c093..8840932dba2 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -4486,7 +4486,7 @@  bool
 zero_init_expr_p (tree t)
 {
   tree type = TREE_TYPE (t);
-  if (!type || dependent_type_p (type))
+  if (!type || uses_template_parms (type))
     return false;
   if (zero_init_p (type))
     return initializer_zerop (t);
diff --git a/gcc/testsuite/g++.dg/cpp0x/dependent3.C b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
new file mode 100644
index 00000000000..caf7e1cd4a4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/dependent3.C
@@ -0,0 +1,28 @@ 
+// { dg-do compile { target c++11 } }
+
+template<typename c>
+struct d
+{
+  using e = c;
+};
+
+template<class f>
+struct g
+{
+  using h = typename d<f>::e;
+
+  template<class i, class j>
+  auto operator()(i, j k) -> decltype(h{k});
+};
+
+template<class l>
+void m()
+{
+  int a[1];
+  l{}(a, a);
+}
+
+int main()
+{
+  m<g<int *>>();
+}