gimplefe: Error recovery for invalid declarations [PR117749]

Message ID 20241130044327.1640070-1-quic_apinski@quicinc.com
State Committed
Commit 1701efd5c848f56cf9a469c5bf42dd0bca675e0a
Headers
Series gimplefe: Error recovery for invalid declarations [PR117749] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Andrew Pinski Nov. 30, 2024, 4:43 a.m. UTC
  c_parser_declarator can return null if there was an error,
but c_parser_gimple_declaration was not ready for that.
This fixes that oversight so we don't get an ICE after the error.

Bootstrapped and tested on x86_64-linux-gnu.

	PR c/117749

gcc/c/ChangeLog:

	* gimple-parser.cc (c_parser_gimple_declaration): Check
	declarator to be non-null.

gcc/testsuite/ChangeLog:

	* gcc.dg/gimplefe-55.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/c/gimple-parser.cc             | 12 ++++++------
 gcc/testsuite/gcc.dg/gimplefe-55.c | 11 +++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-55.c
  

Comments

Richard Biener Nov. 30, 2024, 6:56 a.m. UTC | #1
> Am 30.11.2024 um 05:44 schrieb Andrew Pinski <quic_apinski@quicinc.com>:
> 
> c_parser_declarator can return null if there was an error,
> but c_parser_gimple_declaration was not ready for that.
> This fixes that oversight so we don't get an ICE after the error.
> 
> Bootstrapped and tested on x86_64-linux-gnu.

Ok

Richard 

>    PR c/117749
> 
> gcc/c/ChangeLog:
> 
>    * gimple-parser.cc (c_parser_gimple_declaration): Check
>    declarator to be non-null.
> 
> gcc/testsuite/ChangeLog:
> 
>    * gcc.dg/gimplefe-55.c: New test.
> 
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
> gcc/c/gimple-parser.cc             | 12 ++++++------
> gcc/testsuite/gcc.dg/gimplefe-55.c | 11 +++++++++++
> 2 files changed, 17 insertions(+), 6 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/gimplefe-55.c
> 
> diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc
> index 4763cf23313..78e85d93487 100644
> --- a/gcc/c/gimple-parser.cc
> +++ b/gcc/c/gimple-parser.cc
> @@ -2208,7 +2208,12 @@ c_parser_gimple_declaration (gimple_parser &parser)
>                    specs->typespec_kind != ctsk_none,
>                    C_DTR_NORMAL, &dummy);
> 
> -  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
> +  if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
> +    {
> +      c_parser_error (parser, "expected %<;%>");
> +      return;
> +    }
> +  if (declarator)
>     {
>       /* Handle SSA name decls specially, they do not go into the identifier
>          table but we simply build the SSA name for later lookup.  */
> @@ -2253,11 +2258,6 @@ c_parser_gimple_declaration (gimple_parser &parser)
>             NULL_TREE);
>    }
>     }
> -  else
> -    {
> -      c_parser_error (parser, "expected %<;%>");
> -      return;
> -    }
> }
> 
> /* Parse gimple goto statement.  */
> diff --git a/gcc/testsuite/gcc.dg/gimplefe-55.c b/gcc/testsuite/gcc.dg/gimplefe-55.c
> new file mode 100644
> index 00000000000..120f4ec0ac9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/gimplefe-55.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fgimple" } */
> +
> +/* PR c/117749 */
> +/* Make sure we don't ICE after not have a full local
> +   declaration in gimple fe. */
> +
> +__GIMPLE
> +void foo ( ) {
> +  int ;  /* { dg-error "" } */
> +}
> --
> 2.43.0
>
  

Patch

diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc
index 4763cf23313..78e85d93487 100644
--- a/gcc/c/gimple-parser.cc
+++ b/gcc/c/gimple-parser.cc
@@ -2208,7 +2208,12 @@  c_parser_gimple_declaration (gimple_parser &parser)
 				    specs->typespec_kind != ctsk_none,
 				    C_DTR_NORMAL, &dummy);
 
-  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
+  if (!c_parser_next_token_is (parser, CPP_SEMICOLON))
+    {
+      c_parser_error (parser, "expected %<;%>");
+      return;
+    }
+  if (declarator)
     {
       /* Handle SSA name decls specially, they do not go into the identifier
          table but we simply build the SSA name for later lookup.  */
@@ -2253,11 +2258,6 @@  c_parser_gimple_declaration (gimple_parser &parser)
 			 NULL_TREE);
 	}
     }
-  else
-    {
-      c_parser_error (parser, "expected %<;%>");
-      return;
-    }
 }
 
 /* Parse gimple goto statement.  */
diff --git a/gcc/testsuite/gcc.dg/gimplefe-55.c b/gcc/testsuite/gcc.dg/gimplefe-55.c
new file mode 100644
index 00000000000..120f4ec0ac9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-55.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+/* PR c/117749 */
+/* Make sure we don't ICE after not have a full local
+   declaration in gimple fe. */
+
+__GIMPLE
+void foo ( ) {
+  int ;  /* { dg-error "" } */
+}