[patch, libfortran] Fix PR 26735: -fconvert=swap and implied open

Thomas Koenig Thomas.Koenig@online.de
Fri Mar 24 20:51:00 GMT 2006


On Fri, Mar 24, 2006 at 09:47:03PM +0100, Thomas Koenig wrote:

FAR Much better with the patch and with gcc-patches...

:ADDPATCH fortran:
 
Hello world,

here is the fix for PR 26735.  Regression-tested on i686-pc-linux-gnu.
OK for mainline and 4.1 ?
 
2006-03-24  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/26735
	* io/transfer.c (data_transfer_init):  Set u_flags.convert
	on an unopened unit if specified by environment variable
	(via get_unformatted_convert) or by compile-time option.

2006-03-24  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/26735
	* gfortran.dg/conv_implied_open.f90:  New test case.
-------------- next part --------------
Index: io/transfer.c
===================================================================
--- io/transfer.c	(revision 112290)
+++ io/transfer.c	(working copy)
@@ -1390,6 +1390,8 @@ data_transfer_init (st_parameter_dt *dtp
   if (dtp->u.p.current_unit->s == NULL)
   {  /* Open the unit with some default flags.  */
      st_parameter_open opp;
+     unit_convert conv;
+
      if (dtp->common.unit < 0)
      {
        close_unit (dtp->u.p.current_unit);
@@ -1413,6 +1415,35 @@ data_transfer_init (st_parameter_dt *dtp
      u_flags.blank = BLANK_UNSPECIFIED;
      u_flags.pad = PAD_UNSPECIFIED;
      u_flags.status = STATUS_UNKNOWN;
+
+     conv = get_unformatted_convert (dtp->common.unit);
+
+     if (conv == CONVERT_NONE)
+       conv = compile_options.convert;
+
+     /* We use l8_to_l4_offset, which is 0 on little-endian machines
+	and 1 on big-endian machines.  */
+     switch (conv)
+       {
+       case CONVERT_NATIVE:
+       case CONVERT_SWAP:
+	 break;
+	 
+       case CONVERT_BIG:
+	 conv = l8_to_l4_offset ? CONVERT_NATIVE : CONVERT_SWAP;
+	 break;
+      
+       case CONVERT_LITTLE:
+	 conv = l8_to_l4_offset ? CONVERT_SWAP : CONVERT_NATIVE;
+	 break;
+	 
+       default:
+	 internal_error (&opp.common, "Illegal value for CONVERT");
+	 break;
+       }
+
+     u_flags.convert = conv;
+
      opp.common = dtp->common;
      opp.common.flags &= IOPARM_COMMON_MASK;
      dtp->u.p.current_unit = new_unit (&opp, dtp->u.p.current_unit, &u_flags);
-------------- next part --------------
! { dg-do run }
! { dg-options "-fconvert=swap" }
! PR 26735 - implied open didn't use to honor -fconvert
program main
  implicit none
  integer (kind=8) :: i1, i2, i3
  write (10) 1_8
  close (10)
  open (10, form="unformatted", access="direct", recl=8)
  read (10,rec=1) i1
  read (10,rec=2) i2
  read (10,rec=3) i3
  if (i1 /= 8 .or. i2 /= 1 .or. i3 /= 8) call abort
  close (10,status="delete")
end program main


More information about the Fortran mailing list