* [PATCH] c++: Fix ICE-on-invalid with lambda template [PR94507]
@ 2020-04-07 1:05 Marek Polacek
2020-04-08 12:55 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2020-04-07 1:05 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
While reducing something else I noticed that we ICE on the following
invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
reported an error and returned the error_mark_node, so make sure we
don't ICE on that. I'm using a goto here because we still have to
do finish_struct because it does popclass ().
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
PR c++/94507 - ICE-on-invalid with lambda template.
* pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl returns
error_mark_node.
* g++.dg/cpp2a/lambda-generic7.C: New test.
---
gcc/cp/pt.c | 6 ++++++
gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
2 files changed, 16 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6122227c22f..f804ba18692 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18876,6 +18876,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (oldtmpl)
{
tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
+ if (tmpl == error_mark_node)
+ {
+ r = error_mark_node;
+ goto out;
+ }
fn = DECL_TEMPLATE_RESULT (tmpl);
finish_member_declaration (tmpl);
}
@@ -18948,6 +18953,7 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
maybe_add_lambda_conv_op (type);
}
+out:
finish_struct (type, /*attr*/NULL_TREE);
insert_pending_capture_proxies ();
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
new file mode 100644
index 00000000000..bedba683671
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
@@ -0,0 +1,10 @@
+// PR c++/94507 - ICE-on-invalid with lambda template.
+// { dg-do compile { target c++2a } }
+
+struct S { };
+
+template<typename T, typename U>
+auto foo(T, U)
+{
+ [] <> () { foo (S{}, S{}); }; // { dg-error "expected" }
+}
base-commit: 130f703da0c0d7b785d394b17df884379b4aadd9
--
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: Fix ICE-on-invalid with lambda template [PR94507]
2020-04-07 1:05 [PATCH] c++: Fix ICE-on-invalid with lambda template [PR94507] Marek Polacek
@ 2020-04-08 12:55 ` Jason Merrill
2020-04-08 13:44 ` [PATCH v2] " Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2020-04-08 12:55 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 4/6/20 9:05 PM, Marek Polacek wrote:
> While reducing something else I noticed that we ICE on the following
> invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
> reported an error and returned the error_mark_node, so make sure we
> don't ICE on that. I'm using a goto here because we still have to
> do finish_struct because it does popclass ().
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> PR c++/94507 - ICE-on-invalid with lambda template.
> * pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl returns
> error_mark_node.
>
> * g++.dg/cpp2a/lambda-generic7.C: New test.
> ---
> gcc/cp/pt.c | 6 ++++++
> gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
> 2 files changed, 16 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 6122227c22f..f804ba18692 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -18876,6 +18876,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> if (oldtmpl)
> {
> tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
> + if (tmpl == error_mark_node)
> + {
> + r = error_mark_node;
> + goto out;
> + }
> fn = DECL_TEMPLATE_RESULT (tmpl);
> finish_member_declaration (tmpl);
> }
Perhaps we also want an early exit if the tsubst_function_decl in the
else clause returns error_mark_node?
> @@ -18948,6 +18953,7 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> maybe_add_lambda_conv_op (type);
> }
>
> +out:
> finish_struct (type, /*attr*/NULL_TREE);
>
> insert_pending_capture_proxies ();
> diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
> new file mode 100644
> index 00000000000..bedba683671
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
> @@ -0,0 +1,10 @@
> +// PR c++/94507 - ICE-on-invalid with lambda template.
> +// { dg-do compile { target c++2a } }
> +
> +struct S { };
> +
> +template<typename T, typename U>
> +auto foo(T, U)
> +{
> + [] <> () { foo (S{}, S{}); }; // { dg-error "expected" }
> +}
>
> base-commit: 130f703da0c0d7b785d394b17df884379b4aadd9
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] c++: Fix ICE-on-invalid with lambda template [PR94507]
2020-04-08 12:55 ` Jason Merrill
@ 2020-04-08 13:44 ` Marek Polacek
2020-04-08 17:35 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2020-04-08 13:44 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On Wed, Apr 08, 2020 at 08:55:08AM -0400, Jason Merrill via Gcc-patches wrote:
> On 4/6/20 9:05 PM, Marek Polacek wrote:
> > While reducing something else I noticed that we ICE on the following
> > invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
> > reported an error and returned the error_mark_node, so make sure we
> > don't ICE on that. I'm using a goto here because we still have to
> > do finish_struct because it does popclass ().
> >
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> >
> > PR c++/94507 - ICE-on-invalid with lambda template.
> > * pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl returns
> > error_mark_node.
> >
> > * g++.dg/cpp2a/lambda-generic7.C: New test.
> > ---
> > gcc/cp/pt.c | 6 ++++++
> > gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
> > 2 files changed, 16 insertions(+)
> > create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
> >
> > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> > index 6122227c22f..f804ba18692 100644
> > --- a/gcc/cp/pt.c
> > +++ b/gcc/cp/pt.c
> > @@ -18876,6 +18876,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> > if (oldtmpl)
> > {
> > tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
> > + if (tmpl == error_mark_node)
> > + {
> > + r = error_mark_node;
> > + goto out;
> > + }
> > fn = DECL_TEMPLATE_RESULT (tmpl);
> > finish_member_declaration (tmpl);
> > }
>
> Perhaps we also want an early exit if the tsubst_function_decl in the else
> clause returns error_mark_node?
Can't hurt (but don't have a testcase for it).
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
While reducing something else I noticed that we ICE on the following
invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
reported an error and returned the error_mark_node, so make sure we
don't ICE on that. I'm using a goto here because we still have to
do finish_struct because it does popclass ().
PR c++/94507 - ICE-on-invalid with lambda template.
* pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl or
tsubst_function_decl returns error_mark_node.
* g++.dg/cpp2a/lambda-generic7.C: New test.
---
gcc/cp/pt.c | 11 +++++++++++
gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
2 files changed, 21 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6122227c22f..b9cbdb36de7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18876,6 +18876,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (oldtmpl)
{
tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
+ if (tmpl == error_mark_node)
+ {
+ r = error_mark_node;
+ goto out;
+ }
fn = DECL_TEMPLATE_RESULT (tmpl);
finish_member_declaration (tmpl);
}
@@ -18883,6 +18888,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
tmpl = NULL_TREE;
fn = tsubst_function_decl (oldfn, args, complain, fntype);
+ if (fn == error_mark_node)
+ {
+ r = error_mark_node;
+ goto out;
+ }
finish_member_declaration (fn);
}
@@ -18948,6 +18958,7 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
maybe_add_lambda_conv_op (type);
}
+out:
finish_struct (type, /*attr*/NULL_TREE);
insert_pending_capture_proxies ();
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
new file mode 100644
index 00000000000..bedba683671
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
@@ -0,0 +1,10 @@
+// PR c++/94507 - ICE-on-invalid with lambda template.
+// { dg-do compile { target c++2a } }
+
+struct S { };
+
+template<typename T, typename U>
+auto foo(T, U)
+{
+ [] <> () { foo (S{}, S{}); }; // { dg-error "expected" }
+}
base-commit: 130f703da0c0d7b785d394b17df884379b4aadd9
--
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] c++: Fix ICE-on-invalid with lambda template [PR94507]
2020-04-08 13:44 ` [PATCH v2] " Marek Polacek
@ 2020-04-08 17:35 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2020-04-08 17:35 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On 4/8/20 9:44 AM, Marek Polacek wrote:
> On Wed, Apr 08, 2020 at 08:55:08AM -0400, Jason Merrill via Gcc-patches wrote:
>> On 4/6/20 9:05 PM, Marek Polacek wrote:
>>> While reducing something else I noticed that we ICE on the following
>>> invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
>>> reported an error and returned the error_mark_node, so make sure we
>>> don't ICE on that. I'm using a goto here because we still have to
>>> do finish_struct because it does popclass ().
>>>
>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>>>
>>> PR c++/94507 - ICE-on-invalid with lambda template.
>>> * pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl returns
>>> error_mark_node.
OK.
>>> * g++.dg/cpp2a/lambda-generic7.C: New test.
>>> ---
>>> gcc/cp/pt.c | 6 ++++++
>>> gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
>>> 2 files changed, 16 insertions(+)
>>> create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
>>>
>>> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
>>> index 6122227c22f..f804ba18692 100644
>>> --- a/gcc/cp/pt.c
>>> +++ b/gcc/cp/pt.c
>>> @@ -18876,6 +18876,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>>> if (oldtmpl)
>>> {
>>> tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
>>> + if (tmpl == error_mark_node)
>>> + {
>>> + r = error_mark_node;
>>> + goto out;
>>> + }
>>> fn = DECL_TEMPLATE_RESULT (tmpl);
>>> finish_member_declaration (tmpl);
>>> }
>>
>> Perhaps we also want an early exit if the tsubst_function_decl in the else
>> clause returns error_mark_node?
>
> Can't hurt (but don't have a testcase for it).
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> -- >8 --
> While reducing something else I noticed that we ICE on the following
> invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
> reported an error and returned the error_mark_node, so make sure we
> don't ICE on that. I'm using a goto here because we still have to
> do finish_struct because it does popclass ().
>
> PR c++/94507 - ICE-on-invalid with lambda template.
> * pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl or
> tsubst_function_decl returns error_mark_node.
>
> * g++.dg/cpp2a/lambda-generic7.C: New test.
> ---
> gcc/cp/pt.c | 11 +++++++++++
> gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
> 2 files changed, 21 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 6122227c22f..b9cbdb36de7 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -18876,6 +18876,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> if (oldtmpl)
> {
> tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
> + if (tmpl == error_mark_node)
> + {
> + r = error_mark_node;
> + goto out;
> + }
> fn = DECL_TEMPLATE_RESULT (tmpl);
> finish_member_declaration (tmpl);
> }
> @@ -18883,6 +18888,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> {
> tmpl = NULL_TREE;
> fn = tsubst_function_decl (oldfn, args, complain, fntype);
> + if (fn == error_mark_node)
> + {
> + r = error_mark_node;
> + goto out;
> + }
> finish_member_declaration (fn);
> }
>
> @@ -18948,6 +18958,7 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> maybe_add_lambda_conv_op (type);
> }
>
> +out:
> finish_struct (type, /*attr*/NULL_TREE);
>
> insert_pending_capture_proxies ();
> diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
> new file mode 100644
> index 00000000000..bedba683671
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
> @@ -0,0 +1,10 @@
> +// PR c++/94507 - ICE-on-invalid with lambda template.
> +// { dg-do compile { target c++2a } }
> +
> +struct S { };
> +
> +template<typename T, typename U>
> +auto foo(T, U)
> +{
> + [] <> () { foo (S{}, S{}); }; // { dg-error "expected" }
> +}
>
> base-commit: 130f703da0c0d7b785d394b17df884379b4aadd9
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-04-08 17:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 1:05 [PATCH] c++: Fix ICE-on-invalid with lambda template [PR94507] Marek Polacek
2020-04-08 12:55 ` Jason Merrill
2020-04-08 13:44 ` [PATCH v2] " Marek Polacek
2020-04-08 17:35 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).