On Mon, May 1, 2017 at 8:04 PM, Mikhail Maltsev <malts...@gmail.com> wrote: > The first problem happens because we don't check for missing labels when > parsing > 'goto' statements. I.e.: > > __GIMPLE() void fn1() { > if (1) > goto > } > > The fix is pretty obvious: just add a check. > My question is: which functions should I use to produce diagnostics? The > surrounding code uses 'c_parser_error', but this function does not handle > locations very well (in fact, it uses input_location).
Certainly an improvement. I suppose we can do better error recovery for cases like if (1) goto else goto bar; but I guess this is better than nothing. And yes, we use c_parser_error -- input_location should be ok but here we just peek which may upset the parser. Maybe it works better when consuming the token before issueing the error? Thus Index: gcc/c/gimple-parser.c =================================================================== --- gcc/c/gimple-parser.c (revision 247498) +++ gcc/c/gimple-parser.c (working copy) @@ -1315,8 +1315,8 @@ c_parser_gimple_if_stmt (c_parser *parse loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); label = c_parser_peek_token (parser)->value; - t_label = lookup_label_for_goto (loc, label); c_parser_consume_token (parser); + t_label = lookup_label_for_goto (loc, label); if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) return; } ? Patch is ok with or without this adjustment (and testcase adjustment). Thanks, Richard. > -- > Regards, > Mikhail Maltsev > > gcc/testsuite/ChangeLog: > > 2017-05-01 Mikhail Maltsev <malts...@gmail.com> > > * gcc.dg/gimplefe-error-4.c: New test. > * gcc.dg/gimplefe-error-5.c: New test. > > > gcc/c/ChangeLog: > > 2017-05-01 Mikhail Maltsev <malts...@gmail.com> > > * gimple-parser.c (c_parser_gimple_if_stmt): Check for empty labels. > >