This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran,patch] Fix undue compile-time error message
- From: FX Coudert <fxcoudert at gmail dot com>
- To: François-Xavier Coudert <fxcoudert at gmail dot com>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 19 Jun 2006 20:19:57 +0200
- Subject: Re: [gfortran,patch] Fix undue compile-time error message
- References: <19c433eb0606190447u50133c9du9fd6219d09106844@mail.gmail.com>
Regtested on i686-linux, comes with a testcase. OK for mainline and 4.1?
In fact, one of our testcases needs to be updated for the new error
message, so here is the complete patch. Sorry.
FX
2006-06-19 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR fortran/28081
* resolve.c (resolve_substring): Don't issue out-of-bounds
error messages when the range has zero size.
2006-06-19 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR fortran/28081
* gfortran.dg/substr_3.f: New test.
* gfortran.dg/equiv_2.f90: Update expected error message.
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 114721)
+++ gcc/fortran/resolve.c (working copy)
@@ -2542,7 +2542,9 @@
return FAILURE;
}
- if (compare_bound_int (ref->u.ss.start, 1) == CMP_LT)
+ if (compare_bound_int (ref->u.ss.start, 1) == CMP_LT
+ && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ
+ || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT))
{
gfc_error ("Substring start index at %L is less than one",
&ref->u.ss.start->where);
@@ -2570,9 +2572,11 @@
}
if (ref->u.ss.length != NULL
- && compare_bound (ref->u.ss.end, ref->u.ss.length->length) == CMP_GT)
+ && compare_bound (ref->u.ss.end, ref->u.ss.length->length) == CMP_GT
+ && (compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_EQ
+ || compare_bound (ref->u.ss.end, ref->u.ss.start) == CMP_GT))
{
- gfc_error ("Substring end index at %L is out of bounds",
+ gfc_error ("Substring end index at %L exceeds the string length",
&ref->u.ss.start->where);
return FAILURE;
}
Index: gcc/testsuite/gfortran.dg/substr_3.f
===================================================================
--- gcc/testsuite/gfortran.dg/substr_3.f (revision 0)
+++ gcc/testsuite/gfortran.dg/substr_3.f (revision 0)
@@ -0,0 +1,12 @@
+! { dg-do run }
+! Check that substrings behave correctly even when zero-sized
+ implicit none
+ character(len=10) :: s, t
+ integer :: i, j
+
+ s = "abcdefghij"
+ t(:10) = s(1:)
+ s(16:15) = "foo"
+ s(0:-1) = "foo"
+ if (s /= t) call abort
+ end
Index: gcc/testsuite/gfortran.dg/equiv_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/equiv_2.f90 (revision 114721)
+++ gcc/testsuite/gfortran.dg/equiv_2.f90 (working copy)
@@ -7,7 +7,7 @@
subroutine broken_equiv2
character*4 j
character*2 k
- equivalence (j(2:3), k(1:5)) ! { dg-error "out of bounds" }
+ equivalence (j(2:3), k(1:5)) ! { dg-error "exceeds the string length" }
end subroutine
subroutine broken_equiv3