Bug 42090 - [4.3/4.4/4.5 Regression] I/O: Problems when reading partial records in formatted direct access files
Summary: [4.3/4.4/4.5 Regression] I/O: Problems when reading partial records in format...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.3.5
Assignee: Jerry DeLisle
URL:
Keywords: wrong-code
: 42089 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-11-18 09:04 UTC by Ian Bush
Modified: 2009-11-21 03:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2
Known to fail: 4.3.4 4.4.1 4.5.0
Last reconfirmed: 2009-11-19 03:49:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Bush 2009-11-18 09:04:33 UTC
Consider the following:

Wot now ? cat da.f90
Program da

  Implicit None

  Real :: a, b

  a = 1.111111111
  b = 2.222222222

  Open( 10, File = 't.dat', Form = 'Formatted', Access = 'Direct', Recl = 12 )
  Write( 10, rec = 1, fmt = '( f6.4, /, f6.4 )' ) a, b
  Close( 10 )

  a = -1.0
  b = -1.0

  Open( 10, File = 't.dat', Form = 'Formatted', Access = 'Direct', Recl = 12 )

  Read( 10, rec = 1, fmt = '( f6.4, /, f6.4 )' ) a, b
  Write( *, '( "Partial record 1", t25, 2( f6.4, 1x ) )' ) a, b

  Read( 10, rec = 1, fmt = '( f6.4 )' ) a, b
  Write( *, '( "Partial record 2", t25, 2( f6.4, 1x ) )' ) a, b

  Read( 10, rec = 1, fmt = '( f12.4, /, f12.4 )' ) a, b
  Write( *, '( "Full record 1", t25, 2( f6.4, 1x ) )' ) a, b

  Read( 10, rec = 1, fmt = '( f12.4 )' ) a, b
  Write( *, '( "Full record 2", t25, 2( f6.4, 1x ) )' ) a, b

  Read( 10, rec = 1, fmt = '( f6.4, 6x, /, f6.4, 6x )' ) a, b
  Write( *, '( "Full record with 6x", t25, 2( f6.4, 1x ) )' ) a, b

  Read( 10, rec = 1, fmt = '( f6.4 )' ) a
  Read( 10, rec = 2, fmt = '( f6.4 )' ) b
  Write( *, '( "Record at a time", t25, 2( f6.4, 1x ) )' ) a, b

End Program da
Wot now ? ~/Download/usr/local/gfortran/bin/gfortran --version
GNU Fortran (GCC) 4.5.0 20091116 (experimental) [trunk revision 154218]
Copyright (C) 2009 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

Wot now ? ~/Download/usr/local/gfortran/bin/gfortran -W -Wall -pedantic -fbounds-check -g -O2 da.f90
Wot now ? ./a.out
Partial record 1        1.1111 0.0000
Partial record 2        1.1111 0.0000
Full record 1           1.1111 2.2222
Full record 2           1.1111 2.2222
Full record with 6x     1.1111 2.2222
Record at a time        1.1111 2.2222
Wot now ? 

Note that when reading partial records gfortran gets the value of b wrong. Compare g95 and the sun fortran compiler:

Wot now ? g95 --version
G95 (GCC 4.0.3 (g95 0.92!) Mar 27 2009)
Copyright (C) 2002-2008 Free Software Foundation, Inc.

G95 comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of G95
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
Wot now ? g95 -W -Wall -pedantic -fbounds-check -g -O2 da.f90
Wot now ? ./a.out
Partial record 1        1.1111 2.2222
Partial record 2        1.1111 2.2222
Full record 1           1.1111 2.2222
Full record 2           1.1111 2.2222
Full record with 6x     1.1111 2.2222
Record at a time        1.1111 2.2222
Wot now ? f90 -V
f90: Sun Fortran 95 8.4 Linux_i386 2009/06/03
Usage: f90 [ options ] files.  Use 'f90 -flags' for details
Wot now ? f90 da.f90
Wot now ? ./a.out
Partial record 1        1.1111 2.2222
Partial record 2        1.1111 2.2222
Full record 1           1.1111 2.2222
Full record 2           1.1111 2.2222
Full record with 6x     1.1111 2.2222
Record at a time        1.1111 2.2222

I've also checked against the intel, portland group, pathscale and cray compilers and they all give what I think is the correct result, i.e. the same as g95 and the sun compiler

Also sorry about screwing up the first attempt at submission !
Comment 1 Tobias Burnus 2009-11-18 10:57:35 UTC
*** Bug 42089 has been marked as a duplicate of this bug. ***
Comment 2 Tobias Burnus 2009-11-18 11:03:41 UTC
It's a regression with regards to 4.1.2. Jerry can you have a look?
Comment 3 Jerry DeLisle 2009-11-18 18:04:25 UTC
Yes, I will have a look tonight.
Comment 4 Jerry DeLisle 2009-11-19 03:49:04 UTC
Confirmed and have a patch.
Comment 5 Jerry DeLisle 2009-11-19 04:50:26 UTC
Subject: Bug 42090

Author: jvdelisle
Date: Thu Nov 19 04:50:04 2009
New Revision: 154316

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154316
Log:
2009-11-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/42090
	* io/transfer.c (skip_record): Set bytes_left_subrecord to zero after
	skipping the remaining bytes in the record.
	(next_record_r): Call skip_record with the number of bytes_left to be
	skipped.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/transfer.c

Comment 6 Jerry DeLisle 2009-11-19 05:27:31 UTC
Subject: Bug 42090

Author: jvdelisle
Date: Thu Nov 19 05:27:15 2009
New Revision: 154317

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154317
Log:
2009-11-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/42090
	* gfortran.dg/direct_io_11.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/direct_io_11.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 7 Jerry DeLisle 2009-11-20 04:00:27 UTC
Subject: Bug 42090

Author: jvdelisle
Date: Fri Nov 20 04:00:03 2009
New Revision: 154355

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154355
Log:
2009-11-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/42090
	Backport from trunk.
	* io/transfer.c (skip_record): Set bytes_left_subrecord to zero after
	skipping the remaining bytes in the record.
	(next_record_r): Call skip_record with the number of bytes_left to be
	skipped.

Modified:
    branches/gcc-4_4-branch/libgfortran/ChangeLog
    branches/gcc-4_4-branch/libgfortran/io/transfer.c

Comment 8 Jerry DeLisle 2009-11-20 04:02:51 UTC
Subject: Bug 42090

Author: jvdelisle
Date: Fri Nov 20 04:02:33 2009
New Revision: 154356

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154356
Log:
2009-11-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/42090
	* gfortran.dg/direct_io_11.f90: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/direct_io_11.f90
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 9 Jerry DeLisle 2009-11-21 02:44:14 UTC
Subject: Bug 42090

Author: jvdelisle
Date: Sat Nov 21 02:44:01 2009
New Revision: 154397

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154397
Log:
2009-11-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/42090
	Backport from trunk.
	* io/transfer.c (skip_record): Set bytes_left_subrecord to zero after
	skipping the remaining bytes in the record.
	(next_record_r): Call skip_record with the number of bytes_left to be
	skipped.

Modified:
    branches/gcc-4_3-branch/libgfortran/ChangeLog
    branches/gcc-4_3-branch/libgfortran/io/transfer.c

Comment 10 Jerry DeLisle 2009-11-21 02:46:00 UTC
Subject: Bug 42090

Author: jvdelisle
Date: Sat Nov 21 02:45:48 2009
New Revision: 154398

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154398
Log:
2009-11-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/42090
	* gfortran.dg/direct_io_11.f90: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/direct_io_11.f90
Modified:
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 11 Jerry DeLisle 2009-11-21 03:33:36 UTC
Fixed and closing.