From 42bdf814493c2c39e7a6bd3fb2dd4491352ce5d9 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 9 Dec 2020 09:56:59 +0100 Subject: [PATCH] c/98200 - improve error recovery for GIMPLE FE This avoids ICEing by making sure to propagate error early. 2020-12-09 Richard Biener 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 | 2 ++ gcc/testsuite/gcc.dg/gimplefe-error-8.c | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-8.c diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 5c0ed826119..473cb900481 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -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 index 00000000000..59e81eb4b32 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-8.c @@ -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; +} -- 2.30.2