public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH] PR fortran/56667 -- Issue a sane error message
Date: Mon, 05 Mar 2018 19:09:00 -0000	[thread overview]
Message-ID: <20180305190914.GA8963@troutmask.apl.washington.edu> (raw)

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

For the mangled code in the new testcase, gfortran issues
a somewhat obtuse error message.  The problem is the matcher
for a complex entity runs prior to the matcher for an implied
do-loop.  Errors are queued in that order so an error messagei
for a mangled complex constant is emitted.

Regression tested on x86_64-*-freebsd.

2018-03-07  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/56667
	* primary.c (match_sym_complex_part): Give the matcher for an implied
	do-loop a chance to run.

2018-03-07  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/56667
	* gfortran.dg/implied_do_2.f90: New test.
	* gfortran.dg/coarray_8.f90: Update for new error message.

-- 
Steve

[-- Attachment #2: pr56667.diff --]
[-- Type: text/x-diff, Size: 2264 bytes --]

Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 258227)
+++ gcc/fortran/primary.c	(working copy)
@@ -1248,8 +1248,22 @@ match_sym_complex_part (gfc_expr **result)
 
   if (sym->attr.flavor != FL_PARAMETER)
     {
-      gfc_error ("Expected PARAMETER symbol in complex constant at %C");
-      return MATCH_ERROR;
+      /* Give the matcher for implied do-loops a chance to run.  This yields
+	 a much saner error message for "write(*,*) (i, i=1, 6" where the 
+	 right parenthesis is missing.  */
+      char c;
+      gfc_gobble_whitespace ();
+      c = gfc_peek_ascii_char ();
+      if (c == '=' || c == ',')
+	{
+	  m = MATCH_NO;
+	}
+      else
+	{
+	  gfc_error ("Expected PARAMETER symbol in complex constant at %C");
+	  m = MATCH_ERROR;
+	}
+      return m;
     }
 
   if (!sym->value)
Index: gcc/testsuite/gfortran.dg/implied_do_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/implied_do_2.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/implied_do_2.f90	(working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/56667
+program error_message
+   implicit none
+   integer :: ir
+   write(*,*) ( ir, ir = 1,10    ! { dg-error "Expected a right parenthesis" }
+end program error_message 
Index: gcc/testsuite/gfortran.dg/coarray_8.f90
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_8.f90	(revision 258227)
+++ gcc/testsuite/gfortran.dg/coarray_8.f90	(working copy)
@@ -145,7 +145,7 @@ end module mmm4
 
 subroutine tfgh()
   integer :: i(2)
-  DATA i/(i, i=1,2)/ ! { dg-error "Expected PARAMETER symbol" }
+  DATA i/(i, i=1,2)/ ! { dg-error "Syntax error in DATA" }
   do i = 1, 5 ! { dg-error "cannot be an array" }
   end do ! { dg-error "Expecting END SUBROUTINE" }
 end subroutine tfgh
@@ -153,7 +153,7 @@ end subroutine tfgh
 subroutine tfgh2()
   integer, save :: x[*]
   integer :: i(2)
-  DATA i/(x, x=1,2)/ ! { dg-error "Expected PARAMETER symbol" }
+  DATA i/(x, x=1,2)/ ! { dg-error "Syntax error in DATA" }
   do x = 1, 5 ! { dg-error "cannot be a coarray" }
   end do ! { dg-error "Expecting END SUBROUTINE" }
 end subroutine tfgh2

             reply	other threads:[~2018-03-05 19:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-05 19:09 Steve Kargl [this message]
2018-03-06  7:40 ` Thomas Koenig

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=20180305190914.GA8963@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /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).