This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/34545] ICE when compiling Fortran 95 code
- From: "kargl at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Dec 2007 22:07:39 -0000
- Subject: [Bug fortran/34545] ICE when compiling Fortran 95 code
- References: <bug-34545-15536@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #8 from kargl at gcc dot gnu dot org 2007-12-26 22:07 -------
(In reply to comment #7)
> Maybe this should best be described as:
> "ICE when function returns array of values to dynamically allocated array"
> If the LHS is a 'statically allocated' array, the function returns array of
> values without problem. If the LHS is a dynamically allocated array,
> attempting to assign the array of values from the functions causes an ICE.
Well, no. A better description probably involves the use of stack
memory for a function result gets trashed when you return from
the function.
I can assure that gfortran can assign array function results to
allocated memory. You appear to have stumbled on a bug.
>
> So gfortran fails to implement an essential feature of Fortran 95.
>
This statement is in rather poor taste, and is an example of why I
quit working on gfortran. But, thanks for the bug report.
> Workaround is to call a subroutine and have the array of values
> returned in the argument list.
One can also learn to do proper memory management.
module kmeans_aux
implicit none
contains
function get_nfirst( ) result(fnres)
use const_mod, only: mp
use blk1_mod, only: numclusters
implicit none
! real(mp) :: fnres(numbcluster) ! This uses the stack instead of heap.
real(mp), allocatable :: fnres(:) ! Properly manage heap memory
if (allocated(fnres) .eqv. .true.) deallocate(fnres)
allocate(fnres(numclusters))
fnres = 1
end function get_nfirst
end module kmeans_aux
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34545