The compiler could crash in c_parser_unary_expression in case CPP_MULT: 7050 exp_loc = c_parser_peek_token (parser)->location; 7051 op = c_parser_cast_expression (parser, NULL); 7052 finish = op.get_finish (); ... 7054 location_t combined_loc = make_location (op_loc, op_loc, finish); 7055 ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR); because there was a parse error and op.get_finish () points to garbage. The fix is to use set_error which properly resets src_range in c_expr.
Bootstrapped/regtested on x86_64-linux and ppc64le-linux, ok for trunk? 2017-08-02 Marek Polacek <pola...@redhat.com> PR c/81289 * c-parser.c (c_parser_unary_expression): Use set_error. * gcc.dg/noncompile/pr81289.c: New test. diff --git gcc/c/c-parser.c gcc/c/c-parser.c index 16cd3579972..d018fbc5961 100644 --- gcc/c/c-parser.c +++ gcc/c/c-parser.c @@ -7099,9 +7099,9 @@ c_parser_unary_expression (c_parser *parser) else { c_parser_error (parser, "expected identifier"); - ret.value = error_mark_node; + ret.set_error (); } - return ret; + return ret; case CPP_KEYWORD: switch (c_parser_peek_token (parser)->keyword) { diff --git gcc/testsuite/gcc.dg/noncompile/pr81289.c gcc/testsuite/gcc.dg/noncompile/pr81289.c index e69de29bb2d..dd211466718 100644 --- gcc/testsuite/gcc.dg/noncompile/pr81289.c +++ gcc/testsuite/gcc.dg/noncompile/pr81289.c @@ -0,0 +1,8 @@ +/* PR c/81289 */ +/* { dg-do compile } */ + +int +fn (int mm) +{ + mm == *&& +} /* { dg-error "expected identifier" } */ Marek