re PR libfortran/26735 ([4.1 only] -fconvert=swap and implied open)
authorThomas Koenig <Thomas.Koenig@online.de>
Sat, 25 Mar 2006 21:31:48 +0000 (21:31 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 25 Mar 2006 21:31:48 +0000 (21:31 +0000)
2006-03-25  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-25  Thomas Koenig  <Thomas.Koenig@online.de>

PR libfortran/26735
* gfortran.dg/convert_implied_open.f90:  New test case.

From-SVN: r112382

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/convert_implied_open.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/transfer.c

index fc7b98d..7bd5d1f 100644 (file)
@@ -1,5 +1,10 @@
 2006-03-25  Thomas Koenig  <Thomas.Koenig@online.de>
 
+       PR libfortran/26735
+       * gfortran.dg/convert_implied_open.f90:  New test case.
+
+2006-03-25  Thomas Koenig  <Thomas.Koenig@online.de>
+
        PR fortran/26769
        * gfortran.dg/transpose_reshape_r10.f90:  New test case.
 
diff --git a/gcc/testsuite/gfortran.dg/convert_implied_open.f90 b/gcc/testsuite/gfortran.dg/convert_implied_open.f90
new file mode 100644 (file)
index 0000000..4066f61
--- /dev/null
@@ -0,0 +1,15 @@
+! { 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
index 99daa8d..136556a 100644 (file)
@@ -1,5 +1,12 @@
 2006-03-25  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-25  Thomas Koenig  <Thomas.Koenig@online.de>
+
        PR fortran/26769
        * Makefile.am:  Add transpose_r10.c and reshape_r10.c.
        * aclocal.m4:  Regenerate using aclocal 1.9.3.
index 32e3881..5f5f323 100644 (file)
@@ -1390,6 +1390,8 @@ data_transfer_init (st_parameter_dt *dtp, int read_flag)
   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, int read_flag)
      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);