[patch,gfortran] PR 22607: PURE return-by-reference functions
Erik Edelmann
erik.edelmann@iki.fi
Tue Nov 8 21:54:00 GMT 2005
:ADDPATCH fortran:
Here's a patch for PR 22607; PURE (including ELEMENTAL)
return-by-reference functions don't currently work. If we
avoid setting
DECL_IS_PURE (fndecl) = 1;
in trans-decl.c(build_function_decl), the problem is fixed.
I do, however, not know much about the backend. Among the things
I don't know is whether DECL_IS_PURE (fndecl) = 1 is supposed to
work for return-by-ref. functions or not (might this actually be
a backend bug?). Comments from people with better understanding
of the backend are wellcome.
Bootstrapped & tested on Linux/x86, Ok?
Erik
2005-11-08 Erik Edelmann <eedelman@gcc.gnu.org>
PR fortran/22607
* trans-decl.c(build_function_decl): Don't set
DECL_IS_PURE (fndecl) = 1 for return-by-reference
functions.
2005-11-08 Erik Edelmann <eedelman@gcc.gnu.org>
PR fortran/22607
* gfortran-dg/pure_byref_1.f90: New.
* gfortran-dg/pure_byref_2.f90: New.
-------------- next part --------------
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c (revision 106653)
+++ gcc/fortran/trans-decl.c (working copy)
@@ -1203,7 +1203,7 @@
/* TODO: check if a pure SUBROUTINE has no INTENT(OUT) arguments
including a alternate return. In that case it can also be
marked as PURE. See also in gfc_get_extern_function_decl(). */
- if (attr.function)
+ if (attr.function && !gfc_return_by_reference (sym))
DECL_IS_PURE (fndecl) = 1;
TREE_SIDE_EFFECTS (fndecl) = 0;
}
-------------- next part --------------
! { dg-do compile }
! PR 22607: PURE/ELEMENTAL return-by-reference functions
program main
implicit none
character(2), dimension(2) :: a, b
a = 'ok'
b = fun(a)
if (.not.all(b == 'ok')) call abort()
contains
elemental function fun(a)
character(*), intent(in) :: a
character(len(a)) :: fun
fun = a
end function fun
end program main
-------------- next part --------------
! { dg-do compile }
! PR 22607: PURE return-by-reference functions
program main
implicit none
integer, dimension(2) :: b
b = fun(size(b))
if (b(1) /= 1 .or. b(2) /= 2) call abort()
contains
pure function fun(n)
integer, intent(in) :: n
integer :: fun(n)
integer :: i
do i = 1, n
fun(i) = i
end do
end function fun
end program main
More information about the Fortran
mailing list