diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2010-03-18 02:43:10 +0000 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2010-03-18 02:43:10 +0000 |
commit | 29e8b716ec7b005ec5bb63cc56e13e716f677f50 (patch) | |
tree | f7df763461ba0432a0f53bcb0827ff033a18a1b4 | |
parent | 59011a60c01403fec67e08bc6b94bb44da920482 (diff) | |
download | gcc-29e8b716ec7b005ec5bb63cc56e13e716f677f50.zip gcc-29e8b716ec7b005ec5bb63cc56e13e716f677f50.tar.gz gcc-29e8b716ec7b005ec5bb63cc56e13e716f677f50.tar.bz2 |
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: r157528
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/namelist_27.f90 | 8 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/namelist_28.f90 | 10 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/read_empty_file.f | 7 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/read_eof_all.f90 | 71 |
5 files changed, 96 insertions, 8 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d89de6c..da5166f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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-17 Michael Matz <matz@suse.de> * gcc.dg/pr43300.c: Add -w. diff --git a/gcc/testsuite/gfortran.dg/namelist_27.f90 b/gcc/testsuite/gfortran.dg/namelist_27.f90 index 35fe032..06381b1 100644 --- a/gcc/testsuite/gfortran.dg/namelist_27.f90 +++ b/gcc/testsuite/gfortran.dg/namelist_27.f90 @@ -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 !---------------------------------------- diff --git a/gcc/testsuite/gfortran.dg/namelist_28.f90 b/gcc/testsuite/gfortran.dg/namelist_28.f90 index 53b1f0f..22bddf6 100644 --- a/gcc/testsuite/gfortran.dg/namelist_28.f90 +++ b/gcc/testsuite/gfortran.dg/namelist_28.f90 @@ -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 diff --git a/gcc/testsuite/gfortran.dg/read_empty_file.f b/gcc/testsuite/gfortran.dg/read_empty_file.f new file mode 100644 index 0000000..d407748 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/read_empty_file.f @@ -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 diff --git a/gcc/testsuite/gfortran.dg/read_eof_all.f90 b/gcc/testsuite/gfortran.dg/read_eof_all.f90 new file mode 100644 index 0000000..db6def4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/read_eof_all.f90 @@ -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 + + |