OSDN Git Service

2010-03-17 Jerry DeLisle <jvdelisle@gcc.gnu.org>
authorjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Mar 2010 02:43:10 +0000 (02:43 +0000)
committerjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Mar 2010 02:43:10 +0000 (02:43 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157528 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/namelist_27.f90
gcc/testsuite/gfortran.dg/namelist_28.f90
gcc/testsuite/gfortran.dg/read_empty_file.f [new file with mode: 0644]
gcc/testsuite/gfortran.dg/read_eof_all.f90 [new file with mode: 0644]

index d89de6c..da5166f 100644 (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-17  Michael Matz  <matz@suse.de>
 
        * gcc.dg/pr43300.c: Add -w.
index 35fe032..06381b1 100644 (file)
@@ -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
        !----------------------------------------
index 53b1f0f..22bddf6 100644 (file)
@@ -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 (file)
index 0000000..d407748
--- /dev/null
@@ -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 (file)
index 0000000..db6def4
--- /dev/null
@@ -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
+
+