c/98200 - improve error recovery for GIMPLE FE
authorRichard Biener <rguenther@suse.de>
Wed, 9 Dec 2020 08:56:59 +0000 (09:56 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 9 Dec 2020 10:45:48 +0000 (11:45 +0100)
This avoids ICEing by making sure to propagate error early.

2020-12-09  Richard Biener  <rguenther@suse.de>

PR c/98200
gcc/c/
* gimple-parser.c (c_parser_gimple_postfix_expression): Return
early on error.

gcc/testsuite/
* gcc.dg/gimplefe-error-8.c: New testcase.

gcc/c/gimple-parser.c
gcc/testsuite/gcc.dg/gimplefe-error-8.c [new file with mode: 0644]

index 5c0ed826119795ae0a59d9c8e0b467428a930257..473cb900481ac4eea42c28cf776de441b2142c7b 100644 (file)
@@ -1700,6 +1700,8 @@ c_parser_gimple_postfix_expression (gimple_parser &parser)
       expr.set_error ();
       break;
     }
+  if (expr.value == error_mark_node)
+    return expr;
   return c_parser_gimple_postfix_expression_after_primary
     (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr);
 }
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-8.c b/gcc/testsuite/gcc.dg/gimplefe-error-8.c
new file mode 100644 (file)
index 0000000..59e81eb
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+int __GIMPLE() f(int x, int y)
+{
+  int a;
+  a = (x < y) ? 1 : 2; /* { dg-error "expected" } */
+  return a;
+}