Commit 68b1c5e1 by Paul Thomas

re PR fortran/57522 ([F03] ASSOCIATE construct creates array descriptor with…

re PR fortran/57522 ([F03] ASSOCIATE construct creates array descriptor with incorrect stride for derived type array component)

2014-02-09  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/57522
	* resolve.c (resolve_assoc_var): Set the subref_array_pointer
	attribute for the 'associate-name' if necessary.
	* trans-stmt.c (trans_associate_var): If the 'associate-name'
	is a subref_array_pointer, assign the element size of the
	associate variable to 'span'.

2014-02-09  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/57522
	* gfortran.dg/associated_target_5.f03 : New test

From-SVN: r207646
parent 56c78e5c
2014-02-09 Paul Thomas <pault@gcc.gnu.org>
PR fortran/57522
* resolve.c (resolve_assoc_var): Set the subref_array_pointer
attribute for the 'associate-name' if necessary.
* trans-stmt.c (trans_associate_var): If the 'associate-name'
is a subref_array_pointer, assign the element size of the
associate variable to 'span'.
2014-02-09 Paul Thomas <pault@gcc.gnu.org>
PR fortran/59026
* trans-expr.c (gfc_conv_procedure_call): Pass the value of the
actual argument to a formal argument with the value attribute
......
......@@ -7820,6 +7820,8 @@ resolve_assoc_var (gfc_symbol* sym, bool resolve_target)
sym->attr.target = tsym->attr.target
|| gfc_expr_attr (target).pointer;
if (is_subref_array (target))
sym->attr.subref_array_pointer = 1;
}
/* Get type if this was not already set. Note that it can be
......
......@@ -1192,6 +1192,17 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block)
dim, gfc_index_one_node);
}
/* If this is a subreference array pointer associate name use the
associate variable element size for the value of 'span'. */
if (sym->attr.subref_array_pointer)
{
gcc_assert (e->expr_type == EXPR_VARIABLE);
tmp = e->symtree->n.sym->backend_decl;
tmp = gfc_get_element_type (TREE_TYPE (tmp));
tmp = fold_convert (gfc_array_index_type, size_in_bytes (tmp));
gfc_add_modify (&se.pre, GFC_DECL_SPAN(desc), tmp);
}
/* Done, register stuff as init / cleanup code. */
gfc_add_init_cleanup (block, gfc_finish_block (&se.pre),
gfc_finish_block (&se.post));
......
2014-02-09 Paul Thomas <pault@gcc.gnu.org>
PR fortran/57522
* gfortran.dg/associated_target_5.f03 : New test
2014-02-09 Paul Thomas <pault@gcc.gnu.org>
PR fortran/59026
* gfortran.dg/elemental_by_value_1.f90 : New test
......
! { dg-do run }
! Test the fix for PR57522, in which the associate name had a
! 'span' of an INTEGER rather than that of 'mytype'.
!
! Contributed by A Briolat <alan.briolat@gmail.com>
!
program test_associate
type mytype
integer :: a = 1, b = 2
end type
type(mytype) :: t(4), u(2,2)
integer :: c(4)
t%a = [0, 1, 2, 3]
t%b = [4, 5, 6, 7]
associate (a => t%a)
! Test 'a' is OK on lhs and/or rhs of assignments
c = a - 1
if (any (c .ne. [-1,0,1,2])) call abort
a = a + 1
if (any (a .ne. [1,2,3,4])) call abort
a = t%b
if (any (a .ne. t%b)) call abort
! Test 'a' is OK as an actual argument
c = foo(a)
if (any (c .ne. t%b + 10)) call abort
end associate
! Make sure that the fix works for multi-dimensional arrays...
associate (a => u%a)
if (any (a .ne. reshape ([1,1,1,1],[2,2]))) call abort
end associate
! ...and sections
associate (a => t(2:3)%b)
if (any (a .ne. [5,6])) call abort
end associate
contains
function foo(arg) result(res)
integer :: arg(4), res(4)
res = arg + 10
end function
end program
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment