OSDN Git Service

libgfortran/
authortobi <tobi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 2 Dec 2004 19:39:15 +0000 (19:39 +0000)
committertobi <tobi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 2 Dec 2004 19:39:15 +0000 (19:39 +0000)
PR fortran/18710
* io/transfer.c (unformatted_read, unformatted_write): width of
a COMPLEX is twice its kind.

gcc/testsuite/
PR fortran/18170
* gfortran.dg/direct_io_3.f90: New test.

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

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

index 42c4c5b..7cb1ad6 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-02  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/18170
+       * gfortran.dg/direct_io_3.f90: New test.
+
 2004-12-02  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR 18758
diff --git a/gcc/testsuite/gfortran.dg/direct_io_3.f90 b/gcc/testsuite/gfortran.dg/direct_io_3.f90
new file mode 100644 (file)
index 0000000..8603a83
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do run }
+! PR 18710 : We used to not read and write the imaginary part of 
+! complex numbers
+       COMPLEX C, D
+       DOUBLE COMPLEX E, F
+
+       OPEN(UNIT=9,FILE='PR18710',ACCESS='DIRECT',RECL=132)
+
+       C = (120.0,240.0)
+       WRITE(9,REC=1)C
+       READ(9,REC=1)D
+       if (c /= d) call abort()
+
+       E = (120.0,240.0)
+       WRITE(9,REC=1)E
+       READ(9,REC=1)F
+       if (E /= F) call abort()
+
+       CLOSE(UNIT=9,STATUS='DELETE')
+       END
index 2ee79b2..4dfb335 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-02  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/18710
+       * io/transfer.c (unformatted_read, unformatted_write): width of
+       a COMPLEX is twice its kind.
+
 2004-12-02  Richard Sandiford  <rsandifo@redhat.com>
 
        * configure.ac: Use TL_AC_GCC_VERSION to set gcc_version.
index ceff76f..c27f0f7 100644 (file)
@@ -271,6 +271,13 @@ unformatted_read (bt type, void *dest, int length)
 {
   void *source;
   int w;
+
+  /* Transfer functions get passed the kind of the entity, so we have
+     to fix this for COMPLEX data which are twice the size of their
+     kind.  */
+  if (type == BT_COMPLEX)
+    length *= 2;
+
   w = length;
   source = read_block (&w);
 
@@ -288,9 +295,14 @@ static void
 unformatted_write (bt type, void *source, int length)
 {
   void *dest;
-   dest = write_block (length);
-   if (dest != NULL)
-     memcpy (dest, source, length);
+
+  /* Correction for kind vs. length as in unformatted_read.  */
+  if (type == BT_COMPLEX)
+    length *= 2;
+
+  dest = write_block (length);
+  if (dest != NULL)
+    memcpy (dest, source, length);
 }