This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran] PR34325 Wrong error message for syntax error
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 04 May 2008 17:27:32 -0700
- Subject: [patch, fortran] PR34325 Wrong error message for syntax error
This patch provides some additional checks for balanced parenthesis in a couple
of strategic locations. This will not catch all the possibilities, but is a
reasonable enhancement.
I noticed in some cases of double parens for array references such as:
r3((2,2)) = 4.3
gfortran correctly finds the error stating that the index must be integer. It
was not real clear that in the above (2,2) is a COMPLEX. Ifort and Sun F95 both
add additional info that a COMPLEX was found. I supplemented the gfortran error
to do similarly.
Regression tested on x86-64. Revised test case included in patch.
OK for trunk?
Regards,
Jerry
2008-05-04 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/34325
* decl.c (match_attr_spec): Check for matching pairs of parenthesis.
* expr.c (gfc_specification_expr): Supplement the error message with the
type that was found.
* resolve.c (gfc_resolve_index): Likewise.
* match.c (gfc_match_parens): Clarify error message with "at or before".
(gfc_match_do): Check for matching pairs of parenthesis.
Index: fortran/decl.c
===================================================================
--- fortran/decl.c (revision 134899)
+++ fortran/decl.c (working copy)
@@ -2931,6 +2931,13 @@ match_attr_spec (void)
goto cleanup;
}
+ /* Check to make sure any parens are paired up correctly. */
+ if (gfc_match_parens () == MATCH_ERROR)
+ {
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+
seen[d]++;
seen_at[d] = gfc_current_locus;
Index: fortran/expr.c
===================================================================
--- fortran/expr.c (revision 134899)
+++ fortran/expr.c (working copy)
@@ -2571,7 +2571,8 @@ gfc_specification_expr (gfc_expr *e)
if (e->ts.type != BT_INTEGER)
{
- gfc_error ("Expression at %L must be of INTEGER type", &e->where);
+ gfc_error ("Expression at %L must be of INTEGER type, found %s",
+ &e->where, gfc_basic_typename (e->ts.type));
return FAILURE;
}
Index: fortran/match.c
===================================================================
--- fortran/match.c (revision 134899)
+++ fortran/match.c (working copy)
@@ -153,12 +153,12 @@ gfc_match_parens (void)
if (count > 0)
{
- gfc_error ("Missing ')' in statement before %L", &where);
+ gfc_error ("Missing ')' in statement at or before %L", &where);
return MATCH_ERROR;
}
if (count < 0)
{
- gfc_error ("Missing '(' in statement before %L", &where);
+ gfc_error ("Missing '(' in statement at or before %L", &where);
return MATCH_ERROR;
}
@@ -525,7 +525,6 @@ gfc_match_name (char *buffer)
return MATCH_ERROR;
}
-
buffer[i] = '\0';
gfc_current_locus = old_loc;
@@ -1719,6 +1718,11 @@ gfc_match_do (void)
if (gfc_match_char (',') != MATCH_YES && gfc_match ("% ") != MATCH_YES)
return MATCH_NO;
+ /* Check for balanced parens. */
+
+ if (gfc_match_parens () == MATCH_ERROR)
+ return MATCH_ERROR;
+
/* See if we have a DO WHILE. */
if (gfc_match (" while ( %e )%t", &iter.end) == MATCH_YES)
{
Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c (revision 134899)
+++ fortran/resolve.c (working copy)
@@ -3510,8 +3510,8 @@ gfc_resolve_index (gfc_expr *index, int
if (index->ts.type != BT_INTEGER && index->ts.type != BT_REAL)
{
- gfc_error ("Array index at %L must be of INTEGER type",
- &index->where);
+ gfc_error ("Array index at %L must be of INTEGER type, found %s",
+ &index->where, gfc_basic_typename (index->ts.type));
return FAILURE;
}
Index: testsuite/gfortran.dg/missing_parens_1.f90
===================================================================
--- testsuite/gfortran.dg/missing_parens_1.f90 (revision 134845)
+++ testsuite/gfortran.dg/missing_parens_1.f90 (working copy)
@@ -3,6 +3,8 @@
program aa
implicit none
real(kind=8)::r1=0
+real(kind=8),dimension((1)::r2 ! { dg-error "Missing '\\)' in statement" }
+real(kind=8),dimension(3,3)::r3
character(25) :: a
a = 'I am not a )))))'')''.'
if ((((((a /= "I am not a )))))')'.")))))) call abort
@@ -11,4 +13,7 @@ a = "I am not a )))))"")""."
if ((((((a /= "I am not a )))))"")"".")))))) call abort
if (((3*r1)**2)>= 0) a = "good"
if ((3*r1)**2)>= 0) a = "bad" ! { dg-error "Missing '\\(' in statement" }
+r3((2,2)) = 4.3 ! { dg-error "found COMPLEX" }
+do while ((.true.) ! { dg-error "Missing '\\)' in statement" }
+do while (.true. ! { dg-error "Missing '\\)' in statement" }
end