public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikhail Maltsev <maltsevm@gmail.com>
To: gcc-patches <gcc-patches@gnu.org>,
	Richard Biener <richard.guenther@gmail.com>,
	Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Subject: [PATCH 1/5][GIMPLE FE] PR testsuite/80580. Handle missing labels in goto statements
Date: Mon, 01 May 2017 18:04:00 -0000	[thread overview]
Message-ID: <9e3b3ee6-0c67-f974-c38e-7f9f25249914@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

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).

-- 
Regards,
   Mikhail Maltsev

gcc/testsuite/ChangeLog:

2017-05-01  Mikhail Maltsev  <maltsevm@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  <maltsevm@gmail.com>

	* gimple-parser.c (c_parser_gimple_if_stmt): Check for empty labels.



[-- Attachment #2: 0001-GIMPLEFE-handle-missing-labels-in-goto-statements.patch --]
[-- Type: text/plain, Size: 2411 bytes --]

From 07453ba1bf0b1290cef54dcb028cb477b17966df Mon Sep 17 00:00:00 2001
From: Mikhail Maltsev <maltsevm@gmail.com>
Date: Fri, 24 Feb 2017 13:09:10 +0300
Subject: [PATCH 1/5] GIMPLEFE: handle missing labels in goto statements

---
 gcc/c/gimple-parser.c                   | 10 ++++++++++
 gcc/testsuite/gcc.dg/gimplefe-error-4.c |  7 +++++++
 gcc/testsuite/gcc.dg/gimplefe-error-5.c |  9 +++++++++
 3 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-4.c
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-5.c

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index 0d6384b..a99b502 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -1315,6 +1315,11 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq)
       loc = c_parser_peek_token (parser)->location;
       c_parser_consume_token (parser);
       label = c_parser_peek_token (parser)->value;
+      if (! label)
+	{
+	  c_parser_error (parser, "expected label");
+	  return;
+	}
       t_label = lookup_label_for_goto (loc, label);
       c_parser_consume_token (parser);
       if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
@@ -1339,6 +1344,11 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq)
       loc = c_parser_peek_token (parser)->location;
       c_parser_consume_token (parser);
       label = c_parser_peek_token (parser)->value;
+      if (! label)
+	{
+	  c_parser_error (parser, "expected label");
+	  return;
+	}
       f_label = lookup_label_for_goto (loc, label);
       c_parser_consume_token (parser);
       if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-4.c b/gcc/testsuite/gcc.dg/gimplefe-error-4.c
new file mode 100644
index 0000000..c61539c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-error-4.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+__GIMPLE() void fn1() {
+  if (1)
+    goto
+} /* { dg-error "expected label" } */
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-5.c b/gcc/testsuite/gcc.dg/gimplefe-error-5.c
new file mode 100644
index 0000000..7398861
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-error-5.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+__GIMPLE() void fn1() {
+  if (1)
+    goto lbl;
+  else
+    goto
+} /* { dg-error "expected label" } */
-- 
2.1.4


             reply	other threads:[~2017-05-01 18:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-01 18:04 Mikhail Maltsev [this message]
2017-05-02 14:21 ` Richard Biener
2017-05-29  5:04   ` Mikhail Maltsev
2017-05-30 11:47     ` Richard Biener
2017-05-30 11:50       ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e3b3ee6-0c67-f974-c38e-7f9f25249914@gmail.com \
    --to=maltsevm@gmail.com \
    --cc=gcc-patches@gnu.org \
    --cc=prathamesh.kulkarni@linaro.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).