[PATCH] PR fortran/30799 -- Fix missed invalid logical kinds
Steve Kargl
sgk@troutmask.apl.washington.edu
Thu Feb 15 00:37:00 GMT 2007
The patch should be self-explanatory, but why leave anything chance.
For a bad kind parameter suffix on a logical constant, e.g., .TRUE._123,
gfortran was check that 123 was valid, queue an error, and then procede
without return a MATCH_ERROR. Thus, 123 was accepted as valid.
logical_2.f90 is a dejagnu-ified version of the reporters code.
Regression tested on x86_64-*-freebsd with no new failures.
OK for mainline and 4.2 (and 4.1 when re-opened)?
2007-02-14 Steven G. Kargl <kargl@gcc.gnu.org>
* primary.c (match_logical_constant): Return MATCH_ERROR on invalid kind.
* gfortran.dg/logical_2.f90: New test.
--
Steve
-------------- next part --------------
Index: primary.c
===================================================================
--- primary.c (revision 121973)
+++ primary.c (working copy)
@@ -1025,7 +1025,10 @@ match_logical_constant (gfc_expr **resul
kind = gfc_default_logical_kind;
if (gfc_validate_kind (BT_LOGICAL, kind, true) < 0)
- gfc_error ("Bad kind for logical constant at %C");
+ {
+ gfc_error ("Bad kind for logical constant at %C");
+ return MATCH_ERROR;
+ }
e = gfc_get_expr ();
-------------- next part --------------
! { dg-do compile }
! PR fortran/30799
! Inconsistent handling of bad (invalid) LOGICAL kinds
! Reporter: Harald Anlauf <anlauf@gmx.de>
! Testcase altered by Steven G. Kargl
program gfcbug57
implicit none
!
! These are logical kinds known by gfortran and many other compilers:
!
print *, kind (.true._1) ! This prints "1"
print *, kind (.true._2) ! This prints "2"
print *, kind (.true._4) ! This prints "4"
print *, kind (.true._8) ! This prints "8"
!
! These are very strange (read: bad (invalid?)) logical kinds,
! handled inconsistently by gfortran (there's no logical(kind=0) etc.)
!
print *, kind (.true._0) ! { dg-error "kind for logical constant" }
print *, kind (.true._3) ! { dg-error "kind for logical constant" }
print *, kind (.true._123) ! { dg-error "kind for logical constant" }
!
! Here gfortran bails out with a runtime error:
!
print *, .true._3 ! { dg-error "kind for logical constant" }
end program gfcbug57
More information about the Fortran
mailing list