Bug 29606 - Internal Error: Derived type I/O should have been handled via the frontend
Summary: Internal Error: Derived type I/O should have been handled via the frontend
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: rejects-valid, wrong-code
Depends on:
Blocks: 32834 30625
  Show dependency treegraph
 
Reported: 2006-10-26 16:57 UTC by Daniel Franke
Modified: 2007-09-16 09:40 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-09-03 11:47:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Franke 2006-10-26 16:57:06 UTC
A somewhat similar issue was described in (fixed?) PR #24862.

$> cat ie.f90
PROGRAM ie
  TYPE foo
    INTEGER :: value
  END TYPE

  TYPE foo_array
    TYPE(foo), DIMENSION(:), POINTER :: array
  END TYPE

  TYPE(foo_array)                :: array_holder
  INTEGER, DIMENSION(:), POINTER :: array_ptr

  ALLOCATE( array_holder%array(3) )
  array_holder%array = (/ foo(1), foo(2), foo(3) /)
  WRITE(*,*) array_holder%array%value

  array_ptr => array_holder%array%value
  WRITE(*,*) array_ptr
END PROGRAM

$> gfortran-svn -g -Wall ie.f90
$> ./a.out
           1           2           3
At line 18 of file ie.f90
Internal Error: Derived type I/O should have been handled via the frontend.

$> gfortran-svn -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../svn/gcc/configure --prefix=$(localpath) --disable-nls --enable-threads=posix --enable-shared --enable-bootstrap --with-system-zlib --enable-languages=c,c++,fortran --program-suffix=-svn
Thread model: posix
gcc version 4.3.0 20061023 (experimental)
Comment 1 Paul Thomas 2006-10-27 23:05:01 UTC
Daniel,

This is a general problem for gfortran.  A pointer to a component of an array of derived types cannot, at the moment be represented. Some brave soul need to come up with a proposal as to how to do it and then to change every single client for array descriptors in gfortran.  I periodically contemplate how to do it and recoil in horror at the size of the job.

Confirmed

Paul
Comment 2 Joost VandeVondele 2007-07-04 06:25:08 UTC
(In reply to comment #1)
> This is a general problem for gfortran.  A pointer to a component of an array
> of derived types cannot, at the moment be represented. Some brave soul need to
> come up with a proposal as to how to do it and then to change every single
> client for array descriptors in gfortran.  I periodically contemplate how to do
> it and recoil in horror at the size of the job.

If this would require an ABI change, 4.3.0 would be the right time to fix this. This looks like rather important functionality.
Comment 3 Paul Thomas 2007-09-16 09:18:19 UTC
Subject: Bug 29606

Author: pault
Date: Sun Sep 16 09:17:49 2007
New Revision: 128523

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128523
Log:
2007-09-16  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29396
	PR fortran/29606
	PR fortran/30625
	PR fortran/30871
	* trans.h : Add extra argument to gfc_build_array_ref. Rename
	gfc_conv_aliased_arg to gfc_conv_subref_array_arg.  Move
	prototype of is_aliased_array to gfortran.h and rename it
	gfc_is_subref_array.  Add field span to lang_decl, add a new
	decl lang specific flag accessed by GFC_DECL_SUBREF_ARRAY_P
	and a new type flag GFC_DECL_SUBREF_ARRAY_P.
	* trans.c (gfc_build_array_ref): Add the new argument, decl.
	If this is a subreference array pointer, use the lang_decl
	field 'span' to calculate the offset in bytes and use pointer
	arithmetic to address the element.
	* trans-array.c (gfc_conv_scalarized_array_ref,
	gfc_conv_array_ref): Add the backend declaration as the third
	field, if it is likely to be a subreference array pointer.
	(gfc_conv_descriptor_dimension, gfc_trans_array_ctor_element,
	gfc_trans_array_constructor_element, structure_alloc_comps,
	gfc_conv_array_index_offset): For all other references to
	gfc_build_array_ref, set the third argument to NULL.
	(gfc_get_dataptr_offset): New function.
	(gfc_conv_expr_descriptor): If the rhs of a pointer assignment
	is a subreference array, then calculate the offset to the
	subreference of the first element and set the descriptor data
	pointer to this, using gfc_get_dataptr_offset.
	trans-expr.c (gfc_get_expr_charlen): Use the expression for the
	character length for a character subreference.
	(gfc_conv_substring, gfc_conv_subref_array_arg): Add NULL for
	third argument in call to gfc_build_array_ref.
	(gfc_conv_aliased_arg): Rename to gfc_conv_subref_array_arg.
	(is_aliased_array): Remove.
	(gfc_conv_function_call): Change reference to is_aliased_array
	to gfc_is_subref_array and reference to gfc_conv_aliased_arg to
	gfc_conv_subref_array_arg.
	(gfc_trans_pointer_assignment): Add the array element length to
	the lang_decl 'span' field.
	* gfortran.h : Add subref_array_pointer to symbol_attribute and
	add the prototype for gfc_is_subref_array.
	* trans-stmt.c : Add NULL for third argument in all references
	to gfc_build_array_ref.
	* expr.c (gfc_is_subref_array): Renamed is_aliased_array.
	If this is a subreference array pointer, return true.
	(gfc_check_pointer_assign): If the rhs is a subreference array,
	set the lhs subreference_array_pointer attribute.
	* trans-decl.c (gfc_get_symbol_decl): Allocate the lang_decl
	field if the symbol is a subreference array pointer and set an
	initial value of zero for the 'span' field.
	* trans-io.c (set_internal_unit): Refer to is_subref_array and
	gfc_conv_subref_array_arg.
	(nml_get_addr_expr): Add NULL third argument to
	gfc_build_array_ref. 
	(gfc_trans_transfer): Use the scalarizer for a subreference
	array.

2007-09-16  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29396
	PR fortran/29606
	PR fortran/30625
	PR fortran/30871
	* gfortran.dg/subref_array_pointer_1.f90: New test.
	* gfortran.dg/subref_array_pointer_2.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/subref_array_pointer_1.f90
    trunk/gcc/testsuite/gfortran.dg/subref_array_pointer_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog

Comment 4 Paul Thomas 2007-09-16 09:40:08 UTC
Fixed on trunk

Paul