IO of derived types with pointers

Paul Brook paul@codesourcery.com
Tue Aug 10 02:20:00 GMT 2004


Patch below fixes IO of derived types containing pointers. We were passing the 
address of the pointer, not the pointer itself.

It also adds an error for arrays (still unimplemented).

Paul

2004-08-10  Paul Brook  <paul@codesourcery.com>

	* trans-io.c (transfer_expr): Handle pointters.
testsuite/
	* gfortran.dg/der_io_1.f90: New test.

Index: trans-io.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/trans-io.c,v
retrieving revision 1.8
diff -u -p -r1.8 trans-io.c
--- trans-io.c	29 Jun 2004 22:01:35 -0000	1.8
+++ trans-io.c	9 Aug 2004 23:55:33 -0000
@@ -1138,7 +1138,11 @@ transfer_expr (gfc_se * se, gfc_typespec
 	      se->string_length =
 		TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tmp)));
 	    }
-	  transfer_expr (se, &c->ts, gfc_build_addr_expr (NULL, tmp));
+	  if (c->dimension)
+	    gfc_todo_error ("IO of arrays in derived types");
+	  if (!c->pointer)
+	    tmp = gfc_build_addr_expr (NULL, tmp);
+	  transfer_expr (se, &c->ts, tmp);
 	}
       return;
 
-------------- next part --------------
! { dg-do run }
! IO of derived types containing pointers
program der_io_1
  type t
    integer, pointer :: p
  end type
  integer, target :: i
  type (t) v
  character(4) :: s

  v%p => i
  i = 42
  write (unit=s, fmt='(I2)'), v
  if (s .ne. '42') call abort ()
end program



More information about the Gcc-patches mailing list