From: Mikhail Maltsev Date: Wed, 31 May 2017 13:47:51 +0000 (+0000) Subject: GIMPLEFE: Handle missing labels in goto statements X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9fc5e7a4430d16742e4cb910f0dbb26460cee50e;p=gcc.git GIMPLEFE: Handle missing labels in goto statements gcc/c/ PR testsuite/80580 * gimple-parser.c (c_parser_gimple_if_stmt): Check for empty labels. gcc/testsuite/ PR testsuite/80580 * gcc.dg/gimplefe-error-7.c: New test. From-SVN: r248738 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 2fa398466b1..c53a4bf9fb2 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2017-05-31 Mikhail Maltsev + + PR testsuite/80580 + * gimple-parser.c (c_parser_gimple_if_stmt): Check for empty labels. + 2017-05-30 David Malcolm * c-objc-common.c (c_tree_printer): Gain bool and const char ** diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 06f2fdba7cd..fb9a5430f31 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -1335,9 +1335,14 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq) { loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); + if (! c_parser_next_token_is (parser, CPP_NAME)) + { + c_parser_error (parser, "expected label"); + return; + } 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; } @@ -1359,6 +1364,11 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq) { loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); + if (! c_parser_next_token_is (parser, CPP_NAME)) + { + c_parser_error (parser, "expected label"); + return; + } label = c_parser_peek_token (parser)->value; f_label = lookup_label_for_goto (loc, label); c_parser_consume_token (parser); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fa0bbef93a7..d126dc1a361 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-05-31 Mikhail Maltsev + + PR testsuite/80580 + * gcc.dg/gimplefe-error-7.c: New test. + 2017-05-31 Graham Markall * gcc.target/arc/add_n-combine.c: New test. diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-7.c b/gcc/testsuite/gcc.dg/gimplefe-error-7.c new file mode 100644 index 00000000000..7d5ff374a6c --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-7.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +__GIMPLE() void fn1() +{ + if (1) + goto + else /* { dg-error "expected label" } */ + goto lbl; +} + +__GIMPLE() void fn2() +{ + if (1) + goto lbl; + else + goto ; /* { dg-error "expected label" } */ +} + +__GIMPLE() void fn3() +{ + if (1) + goto lbl; + else + goto +} /* { dg-error "expected label" } */ +