GIMPLEFE: Handle missing labels in goto statements
authorMikhail Maltsev <maltsevm@gmail.com>
Wed, 31 May 2017 13:47:51 +0000 (13:47 +0000)
committerMikhail Maltsev <miyuki@gcc.gnu.org>
Wed, 31 May 2017 13:47:51 +0000 (13:47 +0000)
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

gcc/c/ChangeLog
gcc/c/gimple-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/gimplefe-error-7.c [new file with mode: 0644]

index 2fa398466b1b99b5a14cdccf96c2fa6a5785cfb6..c53a4bf9fb21cd77682e500745d843bc267b688b 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-31  Mikhail Maltsev  <maltsevm@gmail.com>
+
+       PR testsuite/80580
+       * gimple-parser.c (c_parser_gimple_if_stmt): Check for empty labels.
+
 2017-05-30  David Malcolm  <dmalcolm@redhat.com>
 
        * c-objc-common.c (c_tree_printer): Gain bool and const char **
index 06f2fdba7cd36757cef959de9f825ca95745398c..fb9a5430f31a1100797ef3b9c0d1bb7f9d1b6048 100644 (file)
@@ -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);
index fa0bbef93a7bc868b142a20671b63c31d182e793..d126dc1a361b6dc484b42ad6589a2c272958f9ed 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-31  Mikhail Maltsev  <maltsevm@gmail.com>
+
+       PR testsuite/80580
+       * gcc.dg/gimplefe-error-7.c: New test.
+
 2017-05-31  Graham Markall  <graham.markall@embecosm.com>
 
        * 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 (file)
index 0000000..7d5ff37
--- /dev/null
@@ -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" } */
+