public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881]
@ 2020-11-17 19:32 Marek Polacek
  2020-11-20 22:23 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2020-11-17 19:32 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

This invalid (?) code broke my assumption that if decl_specifiers->type
is null, there must be any type-specifiers.  Turn the assert into an if
to fix this crash.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

gcc/cp/ChangeLog:

	PR c++/97881
	* parser.c (warn_about_ambiguous_parse): Only assume "int" if we
	actually saw any type-specifiers.

gcc/testsuite/ChangeLog:

	PR c++/97881
	* g++.dg/warn/Wvexing-parse9.C: New test.
---
 gcc/cp/parser.c                            | 11 +++++------
 gcc/testsuite/g++.dg/warn/Wvexing-parse9.C |  8 ++++++++
 2 files changed, 13 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wvexing-parse9.C

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index b7ef259b048..7a6bf4ad2cf 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -20792,13 +20792,12 @@ warn_about_ambiguous_parse (const cp_decl_specifier_seq *decl_specifiers,
       if (same_type_p (type, void_type_node))
 	return;
     }
+  else if (decl_specifiers->any_type_specifiers_p)
+    /* Code like long f(); will have null ->type.  If we have any
+       type-specifiers, pretend we've seen int.  */
+    type = integer_type_node;
   else
-    {
-      /* Code like long f(); will have null ->type.  If we have any
-	 type-specifiers, pretend we've seen int.  */
-      gcc_checking_assert (decl_specifiers->any_type_specifiers_p);
-      type = integer_type_node;
-    }
+    return;
 
   auto_diagnostic_group d;
   location_t loc = declarator->u.function.parens_loc;
diff --git a/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
new file mode 100644
index 00000000000..dc4198d6c5e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
@@ -0,0 +1,8 @@
+// PR c++/97881
+// { dg-do compile }
+
+void
+cb ()
+{
+  volatile _Atomic (int) a1; // { dg-error "expected initializer" }
+}

base-commit: a5f9c27bfc4417224e332392bb81a2d733b2b5bf
-- 
2.28.0


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

* Re: [PATCH] c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881]
  2020-11-17 19:32 [PATCH] c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881] Marek Polacek
@ 2020-11-20 22:23 ` Jason Merrill
  2020-11-21 20:49   ` Marek Polacek
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2020-11-20 22:23 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 11/17/20 2:32 PM, Marek Polacek wrote:
> This invalid (?) code broke my assumption that if decl_specifiers->type
> is null, there must be any type-specifiers.  Turn the assert into an if
> to fix this crash.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> gcc/cp/ChangeLog:
> 
> 	PR c++/97881
> 	* parser.c (warn_about_ambiguous_parse): Only assume "int" if we
> 	actually saw any type-specifiers.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/97881
> 	* g++.dg/warn/Wvexing-parse9.C: New test.
> ---
>   gcc/cp/parser.c                            | 11 +++++------
>   gcc/testsuite/g++.dg/warn/Wvexing-parse9.C |  8 ++++++++
>   2 files changed, 13 insertions(+), 6 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
> 
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index b7ef259b048..7a6bf4ad2cf 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -20792,13 +20792,12 @@ warn_about_ambiguous_parse (const cp_decl_specifier_seq *decl_specifiers,
>         if (same_type_p (type, void_type_node))
>   	return;
>       }
> +  else if (decl_specifiers->any_type_specifiers_p)
> +    /* Code like long f(); will have null ->type.  If we have any
> +       type-specifiers, pretend we've seen int.  */
> +    type = integer_type_node;
>     else
> -    {
> -      /* Code like long f(); will have null ->type.  If we have any
> -	 type-specifiers, pretend we've seen int.  */
> -      gcc_checking_assert (decl_specifiers->any_type_specifiers_p);
> -      type = integer_type_node;
> -    }
> +    return;
>   
>     auto_diagnostic_group d;
>     location_t loc = declarator->u.function.parens_loc;
> diff --git a/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
> new file mode 100644
> index 00000000000..dc4198d6c5e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
> @@ -0,0 +1,8 @@
> +// PR c++/97881
> +// { dg-do compile }
> +
> +void
> +cb ()
> +{
> +  volatile _Atomic (int) a1; // { dg-error "expected initializer" }

I'm not sure it's useful to test for this particular error, since a 
missing initializer isn't the problem with this declaration.  OK either way.

> +}
> 
> base-commit: a5f9c27bfc4417224e332392bb81a2d733b2b5bf
> 


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

* Re: [PATCH] c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881]
  2020-11-20 22:23 ` Jason Merrill
@ 2020-11-21 20:49   ` Marek Polacek
  0 siblings, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2020-11-21 20:49 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Fri, Nov 20, 2020 at 05:23:56PM -0500, Jason Merrill wrote:
> On 11/17/20 2:32 PM, Marek Polacek wrote:
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
> > @@ -0,0 +1,8 @@
> > +// PR c++/97881
> > +// { dg-do compile }
> > +
> > +void
> > +cb ()
> > +{
> > +  volatile _Atomic (int) a1; // { dg-error "expected initializer" }
> 
> I'm not sure it's useful to test for this particular error, since a missing
> initializer isn't the problem with this declaration.  OK either way.

True, I pushed the patch with { dg-error "" } instead.


Thanks,
Marek


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

end of thread, other threads:[~2020-11-21 20:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 19:32 [PATCH] c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881] Marek Polacek
2020-11-20 22:23 ` Jason Merrill
2020-11-21 20:49   ` Marek Polacek

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