From 3dcde5efcd2ead7eee8864a46e1cc0e1fa459318 Mon Sep 17 00:00:00 2001 From: Prasad Ghangal Date: Fri, 10 Feb 2017 12:47:05 +0000 Subject: [PATCH] gimple-parser.c (c_parser_gimple_binary_expression): Avoid building IL when arguments are error_mark_node. 2017-02-10 Prasad Ghangal Richard Biener * gimple-parser.c (c_parser_gimple_binary_expression): Avoid building IL when arguments are error_mark_node. (c_parser_gimple_unary_expression): Likewise. (c_parser_gimple_if_stmt): Likewise. (c_parser_gimple_switch_stmt): Likewise. (c_parser_gimple_return_stmt): Likewise. (c_parser_parse_ssa_name): When name lookup fails do not build an SSA name. Use undeclared rather than not declared in error reporting. * gcc.dg/gimplefe-error-1.c: New testcase. * gcc.dg/gimplefe-error-2.c: New testcase. * gcc.dg/gimplefe-error-3.c: New testcase. Co-Authored-By: Richard Biener From-SVN: r245326 --- gcc/c/ChangeLog | 13 +++++++++ gcc/c/gimple-parser.c | 38 +++++++++++++++---------- gcc/testsuite/ChangeLog | 7 +++++ gcc/testsuite/gcc.dg/gimplefe-error-1.c | 11 +++++++ gcc/testsuite/gcc.dg/gimplefe-error-2.c | 21 ++++++++++++++ gcc/testsuite/gcc.dg/gimplefe-error-3.c | 17 +++++++++++ 6 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-1.c create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-2.c create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-3.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 95784d80212..fdf50461181 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,16 @@ +2017-02-10 Prasad Ghangal + Richard Biener + + * gimple-parser.c (c_parser_gimple_binary_expression): Avoid + building IL when arguments are error_mark_node. + (c_parser_gimple_unary_expression): Likewise. + (c_parser_gimple_if_stmt): Likewise. + (c_parser_gimple_switch_stmt): Likewise. + (c_parser_gimple_return_stmt): Likewise. + (c_parser_parse_ssa_name): When name lookup fails do not build + an SSA name. Use undeclared rather than not declared in error + reporting. + 2017-02-09 Marek Polacek PR c/79428 diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index e167e420150..afa2e52b7a8 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -524,9 +524,8 @@ c_parser_gimple_binary_expression (c_parser *parser) location_t ret_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); rhs = c_parser_gimple_postfix_expression (parser); - if (c_parser_error (parser)) - return ret; - ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value); + if (lhs.value != error_mark_node && rhs.value != error_mark_node) + ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value); return ret; } @@ -560,6 +559,8 @@ c_parser_gimple_unary_expression (c_parser *parser) { c_parser_consume_token (parser); op = c_parser_gimple_postfix_expression (parser); + if (op.value == error_mark_node) + return ret; finish = op.get_finish (); location_t combined_loc = make_location (op_loc, op_loc, finish); ret.value = build_simple_mem_ref_loc (combined_loc, op.value); @@ -643,7 +644,7 @@ c_parser_parse_ssa_name (c_parser *parser, { if (! type) { - c_parser_error (parser, "SSA name not declared"); + c_parser_error (parser, "SSA name undeclared"); return error_mark_node; } name = make_ssa_name_fn (cfun, type, NULL, version); @@ -663,9 +664,9 @@ c_parser_parse_ssa_name (c_parser *parser, id = get_identifier (var_name); tree parent = lookup_name (id); XDELETEVEC (var_name); - if (! parent) + if (! parent || parent == error_mark_node) { - c_parser_error (parser, "base variable or SSA name not declared"); + c_parser_error (parser, "base variable or SSA name undeclared"); return error_mark_node; } if (VECTOR_TYPE_P (TREE_TYPE (parent)) @@ -1300,8 +1301,9 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq) return; } - gimple_seq_add_stmt (seq, gimple_build_cond_from_tree (cond, t_label, - f_label)); + if (cond != error_mark_node) + gimple_seq_add_stmt (seq, gimple_build_cond_from_tree (cond, t_label, + f_label)); } /* Parse gimple switch-statement. @@ -1441,10 +1443,13 @@ c_parser_gimple_switch_stmt (c_parser *parser, gimple_seq *seq) } if (! c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>")) return; - gimple_seq_add_stmt (seq, gimple_build_switch (cond_expr.value, - default_label, labels)); - gimple_seq_add_seq (seq, switch_body); - labels.release(); + + if (cond_expr.value != error_mark_node) + { + gimple_seq_add_stmt (seq, gimple_build_switch (cond_expr.value, + default_label, labels)); + gimple_seq_add_seq (seq, switch_body); + } } /* Parse gimple return statement. */ @@ -1465,9 +1470,12 @@ c_parser_gimple_return_stmt (c_parser *parser, gimple_seq *seq) { location_t xloc = c_parser_peek_token (parser)->location; c_expr expr = c_parser_gimple_unary_expression (parser); - c_finish_gimple_return (xloc, expr.value); - ret = gimple_build_return (expr.value); - gimple_seq_add_stmt (seq, ret); + if (expr.value != error_mark_node) + { + c_finish_gimple_return (xloc, expr.value); + ret = gimple_build_return (expr.value); + gimple_seq_add_stmt (seq, ret); + } } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d6cd7711a9a..3cf1cb24574 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-02-10 Prasad Ghangal + Richard Biener + + * gcc.dg/gimplefe-error-1.c: New testcase. + * gcc.dg/gimplefe-error-2.c: New testcase. + * gcc.dg/gimplefe-error-3.c: New testcase. + 2017-02-10 Jakub Jelinek PR tree-optimization/79411 diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-1.c b/gcc/testsuite/gcc.dg/gimplefe-error-1.c new file mode 100644 index 00000000000..5b870f14a31 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +void __GIMPLE () foo (int a) +{ +bb_2: + a = *b; /* { dg-error "undeclared" } */ + +bb_3: + return; +} diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-2.c b/gcc/testsuite/gcc.dg/gimplefe-error-2.c new file mode 100644 index 00000000000..216623e6d0f --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +int __GIMPLE () +main (int argc, char * * argv) +{ + +bb_2: + switch (a) {default: L2; case 1: L0; case 2: L1; } /* { dg-error "undeclared" } */ + +L0: + a = 0; + goto bb_6; + +L1: + a = 3; + goto L2; + +L2: + return a; +} diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-3.c b/gcc/testsuite/gcc.dg/gimplefe-error-3.c new file mode 100644 index 00000000000..9209bbaeb7d --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-3.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +int __GIMPLE foo() +{ + if (a != 2) /* { dg-error "undeclared" } */ + goto bb1; + else + goto bb2; + +bb1: + a_1 = 10; /* { dg-error "undeclared" } */ + return a_1; + +bb2: + return 1; +} -- 2.30.2