[patch, gfortran] PR 22607 again: Return-by-reference functions in modules

Erik Edelmann erik.edelmann@iki.fi
Thu Dec 29 22:38:00 GMT 2005


When I wrote a patch to fix PR 22607 some time ago
(http://gcc.gnu.org/ml/fortran/2005-11/msg00253.html), I forgot
to check if there were other places where functions were declared
to be "backend-pure", leaving external/module pure
return-by-reference functions still non-working.  This patch
should fix the problem once and for all (I hope).

Reg.tested on Linux/x86, on trunk, 4.1 and 4.0.  Ok to commit?


        Erik


2005-12-29  Erik Edelmann  <eedelman@gcc.gnu.org>

        PR fortran/22607
        * trans-decl.c(gfc_get_extern_function_decl): Don't set 
        DECL_IS_PURE (fndecl) = 1 for return-by-reference
        functions.


2005-12-29  Erik Edelmann  <eedelman@gcc.gnu.org>

        PR fortran/22607
        * gfortran-dg/pure_byref_3.f90: New.
-------------- next part --------------
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 109154)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1093,7 +1093,7 @@ gfc_get_extern_function_decl (gfc_symbol
      sense.  */
   if (sym->attr.pure || sym->attr.elemental)
     {
-      if (sym->attr.function)
+      if (sym->attr.function && !gfc_return_by_reference (sym))
 	DECL_IS_PURE (fndecl) = 1;
       /* TODO: check if pure SUBROUTINEs don't have INTENT(OUT)
 	 parameters and don't use alternate returns (is this
-------------- next part --------------
! { dg-do run }
! PR 22607: External/module pure return-by-reference functions

pure function hoj()
    integer :: hoj(3)
    hoj = (/1, 2, 3/)
end function hoj

module huj_mod
contains
    pure function huj()
        integer :: huj(3)
        huj = (/1, 2, 3/)
    end function huj
end module huj_mod

program pure_byref_3
    use huj_mod
    implicit none

    interface
        pure function hoj()
            integer :: hoj(3)
        end function hoj
    end interface
    integer :: a(3)

    a = huj()
    if (.not. all(a == (/1, 2, 3/))) call abort()

    a = hoj()
    if (.not. all(a == (/1, 2, 3/))) call abort()
end program pure_byref_3


More information about the Fortran mailing list