re PR fortran/43265 (No EOF condition if reading with '(x)' from an empty file)

2010-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/43265
	*gfortran.dg/read_empty_file.f: New test.
	*gfortran.dg/read_eof_all.f90: New test.
	*gfortran.dg/namelist_27.f90: Eliminate infinite loop posibility.
	*gfortran.dg/namelist_28.f90: Eliminate infinite loop posibility.

From-SVN: r157533
This commit is contained in:
Jerry DeLisle 2010-03-18 03:55:52 +00:00
parent ee878d8858
commit 1a22a56cf2
5 changed files with 101 additions and 13 deletions

View File

@ -1,3 +1,11 @@
2010-03-17 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/43265
*gfortran.dg/read_empty_file.f: New test.
*gfortran.dg/read_eof_all.f90: New test.
*gfortran.dg/namelist_27.f90: Eliminate infinite loop posibility.
*gfortran.dg/namelist_28.f90: Eliminate infinite loop posibility.
2010-03-13 H.J. Lu <hongjiu.lu@intel.com>
Backport from mainline:
@ -522,8 +530,8 @@
2010-02-04 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/42901
*gfortran.dg/namelist_60.f90: New test.
*gfortran.dg/namelist_59.f90: New test.
* gfortran.dg/namelist_60.f90: New test.
* gfortran.dg/namelist_59.f90: New test.
2010-02-04 Richard Guenther <rguenther@suse.de>

View File

@ -1,4 +1,4 @@
! { dg-do run { target fd_truncate } }
! { dg-do run }
! PR31052 Bad IOSTAT values when readings NAMELISTs past EOF.
! Patch derived from PR, submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
program gfcbug61
@ -41,14 +41,14 @@ contains
character(len=*), intent(in) :: name
character(len=255) :: line
integer :: ios, idx
integer :: ios, idx, k
logical :: first
first = .true.
status = 0
ios = 0
line = ""
do
do k=1,10
read (unit,'(a)',iostat=ios) line
if (first) then
first = .false.
@ -74,7 +74,7 @@ contains
subroutine read_report (unit, status)
integer :: unit, status
integer :: iuse, ios
integer :: iuse, ios, k
!------------------
! Namelist 'REPORT'
!------------------
@ -85,7 +85,7 @@ contains
! Loop to read namelist multiple times
!-------------------------------------
iuse = 0
do
do k=1,5
!----------------------------------------
! Preset namelist variables with defaults
!----------------------------------------
@ -103,4 +103,4 @@ contains
status = ios
end subroutine read_report
end program gfcbug61
end program gfcbug61

View File

@ -1,4 +1,4 @@
! { dg-do run { target fd_truncate } }
! { dg-do run }
! PR31052 Bad IOSTAT values when readings NAMELISTs past EOF.
! Patch derived from PR, submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
program gfcbug61
@ -27,12 +27,12 @@ contains
character(len=*), intent(in) :: name
character(len=255) :: line
integer :: ios, idx
integer :: ios, idx, k
logical :: first
first = .true.
status = 0
do
do k=1,25
line = ""
read (unit,'(a)',iostat=ios) line
if (ios < 0) then
@ -51,12 +51,13 @@ contains
return
end if
end do
if (k.gt.10) call abort
end subroutine position_nml
subroutine read_report (unit, status)
integer :: unit, status
integer :: iuse, ios
integer :: iuse, ios, k
!------------------
! Namelist 'REPORT'
!------------------
@ -66,7 +67,7 @@ contains
! Loop to read namelist multiple times
!-------------------------------------
iuse = 0
do
do k=1,25
!----------------------------------------
! Preset namelist variables with defaults
!----------------------------------------
@ -84,6 +85,7 @@ contains
if (ios /= 0) exit
iuse = iuse + 1
end do
if (k.gt.10) call abort
status = ios
end subroutine read_report

View File

@ -0,0 +1,7 @@
! { dg-do run }
! PR43320 Missing EOF on read from empty file.
open(8,status='scratch',form='formatted') ! Create empty file
read(8,'(a80)', end=123) ! Reading from an empty file should be an EOF
call abort
123 continue
end

View File

@ -0,0 +1,71 @@
! { dg-do run }
! PR43265 Followup patch for miscellaneous EOF conditions.
! Eaxamples from Tobius Burnus
use iso_fortran_env
character(len=2) :: str, str2(2)
integer :: a, b, c, ios
str = ''
str2 = ''
open(99,file='test.dat',access='stream',form='unformatted', status='replace')
write(99) ' '
close(99)
open(99,file='test.dat')
read(99, '(T7,i2)') i
close(99, status="delete")
if (i /= 0) call abort
read(str(1:0), '(T7,i1)') i
if (i /= 0) call abort
read(str,'(i2,/,i2)',end=111) a, b
call abort !stop 'ERROR: Expected EOF error (1)'
111 continue
read(str2,'(i2,/,i2)',end=112) a, b
read(str2,'(i2,/,i2,/,i2)',end=113) a, b, c
call abort !stop 'ERROR: Expected EOF error (2)'
112 call abort !stop 'ERROR: Unexpected EOF (3)'
113 continue
read(str,'(i2,/,i2)',end=121,pad='no') a, b
call abort !stop 'ERROR: Expected EOF error (1)'
121 continue
read(str2(:),'(i2,/,i2)', end=122, pad='no') a, b
goto 125
122 call abort !stop 'ERROR: Expected no EOF error (2)'
125 continue
read(str2(:),'(i2,/,i2,/,i2)',end=123,pad='no') a, b, c
call abort !stop 'ERROR: Expected EOF error (3)'
123 continue
read(str(2:1),'(i2,/,i2)',end=131, pad='no') a, b
call abort !stop 'ERROR: Expected EOF error (1)'
131 continue
read(str2(:)(2:1),'(i2,/,i2)',end=132, pad='no') a, b
call abort !stop 'ERROR: Expected EOF error (2)'
132 continue
read(str2(:)(2:1),'(i2,/,i2,/,i2)',end=133,pad='no') a, b, c
call abort !stop 'ERROR: Expected EOF error (3)'
133 continue
read(str(2:1),'(i2,/,i2)',iostat=ios, pad='no') a, b
if (ios /= IOSTAT_END) call abort !stop 'ERROR: expected iostat /= 0 (1)'
read(str2(:)(2:1),'(i2,/,i2)',iostat=ios, pad='no') a, b
if (ios /= IOSTAT_END) call abort !stop 'ERROR: expected iostat /= 0 (2)'
read(str2(:)(2:1),'(i2,/,i2,/,i2)',iostat=ios,pad='no') a, b, c
if (ios /= IOSTAT_END) call abort !stop 'ERROR: expected iostat /= 0 (2)'
! print *, "success"
end