Bug 24276 - Components of a derived type array not passed as an array
Summary: Components of a derived type array not passed as an array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-10-08 17:30 UTC by Paul Thomas
Modified: 2006-01-28 21:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-02 07:07:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Thomas 2005-10-08 17:30:03 UTC
program test_lex
  type :: dtype
    integer :: n
    character*12 :: word
  end type dtype
  
  type(dtype), dimension(2) :: list
  list(1) = dtype (1 , "one")
  list(2) = dtype (2 , "two")
  
  call foo (list%word)
  
contains

  subroutine foo (slist)
    character*12, dimension(*) :: slist
    print *, ("\n",slist(i), i=1,2)
  end subroutine foo

end program test_lex

produces the output

[prt@localhost meissner]# ./a.out

one
    two

Examination of the code shows that the size of the derived type is not being used to determine the stride of the array in the function.  This is one and the same as the problem with pointer arrays pointing to same kind components of a derived type array, which Tobi is fond of.
Comment 1 Andrew Pinski 2005-10-08 17:32:41 UTC
Confirmed.
Comment 2 Andrew Pinski 2006-01-09 23:24:41 UTC
the parse tree is correct:
      CALL foo ((MAIN__:list(FULL) % word))

So this is just a trans issue as far as I can tell.

Also it is even worse with, were we print way wrong stuff:
program test_lex
  type :: dtype
    character*12 :: word
    integer :: n
  end type dtype

  type(dtype), dimension(2) :: list
  list(1) = dtype ( "one", 1)
  list(2) = dtype ( "two", 2)

  call foo (list%n)

contains

  subroutine foo (slist)
    integer, dimension(*) :: slist
    print *, ("\n",slist(i), i=1,2)
  end subroutine foo

end program test_lex
Comment 3 Paul Thomas 2006-01-10 05:16:43 UTC
Subject: Re:  Components of a derived type array not passed
 as an array

pinskia at gcc dot gnu dot org wrote:

>------- Comment #2 from pinskia at gcc dot gnu dot org  2006-01-09 23:24 -------
>the parse tree is correct:
>      CALL foo ((MAIN__:list(FULL) % word))
>
>So this is just a trans issue as far as I can tell.
>  
>
Yes it is.  Since we do not have aliassed descriptors and size is not in 
bytes, the offset and the step size cannot be transmitted, in general.  
I have a patch most of the way ready that transfers a temporary to 
procedure and copies it back again to the derived type upon return.  I 
have wrinkle to sort out, which is that the temporary descriptor is zero 
based and my code is not picking that up. The result is that the 
elements get shifted down one place.  I was doing this, when I got 
distracted by the global references and plan to return to it asap.

Paul

Comment 4 Paul Thomas 2006-01-27 22:16:27 UTC
Subject: Bug 24276

Author: pault
Date: Fri Jan 27 22:16:04 2006
New Revision: 110310

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110310
Log:
2005-01-28  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/25964
	* resolve.c (resolve_function): Exclude statement functions from
	global reference checking.

	PR fortran/25084
	PR fortran/20852
	PR fortran/25085
	PR fortran/25086
	* resolve.c (resolve_function): Declare a gfc_symbol to replace the
	references through the symtree to the symbol associated with the
	function expresion. Give error on reference to an assumed character
	length function is defined in an interface or an external function
	that is not a dummy argument.
	(resolve_symbol): Give error if an assumed character length function
	is array-valued, pointer-valued, pure or recursive. Emit warning
	that character(*) value functions are obsolescent in F95.

	PR fortran/25416
	* trans-expr.c (gfc_conv_function_call): The above patch to resolve.c
	prevents any assumed character length function call from getting here
	except intrinsics such as SPREAD. In this case, ensure that no
	segfault occurs from referencing non-existent charlen->length->
	expr_type and provide a backend_decl for the charlen from the charlen
	of the first actual argument.

	Cure temp name confusion.
	* trans-expr.c (gfc_get_interface_mapping_array): Change name of
	temporary from "parm" to "ifm" to avoid clash with temp coming from
	trans-array.c.

	PR fortran/25124
	PR fortran/25625
	* decl.c (get_proc_name): If there is an existing
	symbol in the encompassing namespace, call errors
	if it is a procedure of the same name or the kind
	field is set, indicating a type declaration.

	PR fortran/20881
	PR fortran/23308
	PR fortran/25538
	PR fortran/25710
	* decl.c (add_global_entry): New function to check
	for existing global symbol with this name and to
	create new one if none exists.
	(gfc_match_entry): Call add_global_entry before
	matching argument lists for subroutine and function
	entries.
	* gfortran.h: Prototype for existing function, global_used.
	* resolve.c (resolve_global_procedure): New function
	to check global symbols for procedures.
	(resolve_call, resolve_function): Calls to this
	new function for non-contained and non-module
	procedures.
	* match.c (match_common): Add check for existing
	global symbol, creat one if none exists and emit
	error if there is a clash.
	* parse.c (global_used): Remove static and use the
	gsymbol name rather than the new_block name, so that
	the function can be called from resolve.c.
	(parse_block_data, parse_module, add_global_procedure):
	Improve checks for existing gsymbols.  Emit error if
	already defined or if references were to another type.
	Set defined flag.

	PR fortran/24276
	* trans-expr.c (gfc_conv_aliased_arg): New function called by 
	gfc_conv_function_call that coverts an expression for an aliased
	component reference to a derived type array into a temporary array
	of the same type as the component.  The temporary is passed as an
	actual argument for the procedure call and is copied back to the
	derived type after the call.
	(is_aliased_array): New function that detects an array reference
	that is followed by a component reference.
	(gfc_conv_function_call): Detect an aliased actual argument with
	is_aliased_array and convert it to a temporary and back again
	using gfc_conv_aliased_arg.

	PR fortran/25124
	PR fortran/25625
	* gfortran.dg/internal_references_1.f90: New test.

	PR fortran/25901
	* gfortran.dg/internal references_2.f90: New test.

	PR fortran/20881
	PR fortran/23308
	PR fortran/25538
	PR fortran/25710
	* gfortran.dg/global_references_1.f90: New test.
	* gfortran.dg/g77/19990905-1.f: Restore the error that
	there is a clash between the common block name and
	the name of a subroutine reference.

	PR fortran/25964
	* gfortran.dg/global_references_2.f90: New test.

	PR fortran/24276
	* gfortran.dg/aliasing_dummy_1.f90: New test.

	PR fortran/25084
	PR fortran/20852
	PR fortran/25085
	PR fortran/25086
	* gfortran.dg/assumed_charlen_function_1.f90: New test.
	* gfortran.dg/assumed_charlen_function_3.f90: New test.

	PR fortran/25416
	* gfortran.dg/assumed_charlen_function_2.f90: New test.

	PR fortran/25964
	* gfortran.dg/assumed_size_refs_3.f90: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/aliasing_dummy_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_charlen_function_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_charlen_function_2.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_charlen_function_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/assumed_size_refs_3.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/global_references_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/global_references_2.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/internal_references_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/internal_references_2.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/decl.c
    branches/gcc-4_1-branch/gcc/fortran/gfortran.h
    branches/gcc-4_1-branch/gcc/fortran/match.c
    branches/gcc-4_1-branch/gcc/fortran/parse.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/fortran/symbol.c
    branches/gcc-4_1-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/g77/19990905-1.f

Comment 5 Paul Thomas 2006-01-27 22:34:24 UTC
Fixed on trunk and 4.1

Paul