From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28588 invoked by alias); 26 Dec 2007 22:07:50 -0000 Received: (qmail 28536 invoked by uid 48); 26 Dec 2007 22:07:39 -0000 Date: Wed, 26 Dec 2007 22:07:00 -0000 Message-ID: <20071226220739.28535.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/34545] ICE when compiling Fortran 95 code In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "kargl at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-12/txt/msg02257.txt.bz2 ------- 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