[patch, fortran] More on allocatable dummy arguments.
Erik Edelmann
erik.edelmann@iki.fi
Thu Mar 9 00:15:00 GMT 2006
:ADDPATCH:
Thanks to Paul and Steve for looking at my 'allocatable function
result' patch. In the meantime, I've found a bug for allocatable
dummy arguments in functions returning arrays. (I'm pretty sure I
tested that, but appearantly not).
Fix in short: Treat allocatable dummy arguments in trans-expr.c
(gfc_add_interface_mapping) the same way as pointer dummy
arguments.
Tested on trunk, Linux/x86. Ok to commit?
Erik
fortran/
2006-03-09 Erik Edelmann <eedelman@gcc.gnu.org>
* trans-expr.c (gfc_add_interface_mapping): Set the 'allocatable'
attribute for new_sym. Call build_fold_indirect_ref() for
allocatable arguments.
testsuite/
2006-03-09 Erik Edelmann <eedelman@gcc.gnu.org>
* gfortran.dg/allocatable_dummy_1.f90: Test for functions returning
pointers too.
-------------- next part --------------
Index: gcc/testsuite/gfortran.dg/allocatable_dummy_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/allocatable_dummy_1.f90 (revision 111842)
+++ gcc/testsuite/gfortran.dg/allocatable_dummy_1.f90 (working copy)
@@ -13,6 +13,8 @@ program alloc_dummy
call useit(a, b)
if (.NOT.all(b == [ 1, 2, 3 ])) call abort()
+ if (.NOT.all(whatever(a) == [ 1, 2, 3 ])) call abort()
+
call kill(a)
if (allocated(a)) call abort()
@@ -35,6 +37,13 @@ contains
y = x
end subroutine useit
+ function whatever(x)
+ integer, allocatable :: x(:)
+ integer :: whatever(size(x))
+
+ whatever = x
+ end function whatever
+
subroutine kill(x)
integer, allocatable, intent(out) :: x(:)
end subroutine kill
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c (revision 111842)
+++ gcc/fortran/trans-expr.c (working copy)
@@ -1316,6 +1316,7 @@ gfc_add_interface_mapping (gfc_interface
new_sym->attr.referenced = 1;
new_sym->attr.dimension = sym->attr.dimension;
new_sym->attr.pointer = sym->attr.pointer;
+ new_sym->attr.allocatable = sym->attr.allocatable;
new_sym->attr.flavor = sym->attr.flavor;
/* Create a fake symtree for it. */
@@ -1367,8 +1368,9 @@ gfc_add_interface_mapping (gfc_interface
value = build_fold_indirect_ref (value);
}
- /* If the argument is a scalar or a pointer to an array, dereference it. */
- else if (!sym->attr.dimension || sym->attr.pointer)
+ /* If the argument is a scalar, a pointer to an array or an allocatable,
+ dereference it. */
+ else if (!sym->attr.dimension || sym->attr.pointer || sym->attr.allocatable)
value = build_fold_indirect_ref (se->expr);
/* For character(*), use the actual argument's descriptor. */
More information about the Fortran
mailing list