public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/35959]  New: Recursive function with allocatable array
@ 2008-04-16 20:05 michael dot baudin at gmail dot com
  2008-04-17  6:00 ` [Bug fortran/35959] " pault at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: michael dot baudin at gmail dot com @ 2008-04-16 20:05 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3388 bytes --]

Problem with gfortran while developing a recursive function
which allocates an array stored in a derived-type.
This is the sample test :

module testmod

#define _DYNAMIC_TYPE allocatable
!#define _DYNAMIC_TYPE pointer

 type, public :: t_type
    integer, dimension(:), _DYNAMIC_TYPE :: chars
 end type t_type
 integer, save :: callnb = 0
contains
 recursive function recursivefunc ( this ) result ( match )
   type(t_type), intent(in) :: this
   type(t_type) :: subpattern
   logical :: thisalloc
   integer :: thislength
   logical :: match
   write ( * , * ) "recursivefunc [" , callnb , "]"
   thislength = size ( this % chars )
   write ( * , * ) "length :", thislength
   callnb = callnb + 1
   thisalloc = allocated ( this % chars )
!    thisalloc = associated ( this % chars )
   if ( .NOT. thisalloc ) then
      write ( 6 , * ) "STOP with error !"
      stop
   endif
   if ( thislength == 0 ) then
      match = .true.
      return
   endif
   allocate ( subpattern % chars ( thislength - 1 ) )
   match = recursivefunc ( subpattern )
 end function recursivefunc
end module testmod

program testprog
 use testmod
 implicit none
 type(t_type) :: this
 logical :: match
 allocate ( this % chars ( 10 ))
 match = recursivefunc ( this )
 print * , "match :", match
end program testprog

Compile it with :

gfortran -x f95-cpp-input testZeroSizeRecursive2.f90 -o
testZeroSizeRecursive2.exe
(flibs-workbench) 60 % testZeroSizeRecursive2.exe
 recursivefunc [           0 ]
 length :          10
 recursivefunc [           1 ]
 length :           9
 STOP with error !

This is because the allocated statement return .false., even
 if the array is really allocated.
Trying the "pointer" version by modifying the #define preprocessing statement
and the "allocated" to associated" make the problem disappear :

 recursivefunc [           0 ]
 length :          10
 recursivefunc [           1 ]
 length :           9
 recursivefunc [           2 ]
 length :           8
 recursivefunc [           3 ]
 length :           7
 recursivefunc [           4 ]
 length :           6
 recursivefunc [           5 ]
 length :           5
 recursivefunc [           6 ]
 length :           4
 recursivefunc [           7 ]
 length :           3
 recursivefunc [           8 ]
 length :           2
 recursivefunc [           9 ]
 length :           1
 recursivefunc [          10 ]
 length :           0
 match : T

This is the version of gfortran I currently use ( I downloaded it today
and I think that it is up-todate ) :

(flibs-workbench) 61 % gfortran -v
Using built-in specs.
Target: i586-pc-mingw32
Configured with: ../trunk/configure --prefix=/mingw
--enable-languages=c,fortran --with-gmp=/home/FX/local
--with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror
--enable-bootstrap --enable-threads --disable-nls
--build=i586-pc-mingw32 --enable-libgomp --disable-shared
Thread model: win32
gcc version 4.4.0 20080312 (experimental) [trunk revision 133139] (GCC)

Regards,

Michaël Baudin


-- 
           Summary: Recursive function with allocatable array
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: michael dot baudin at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35959


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-04-24 19:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-16 20:05 [Bug fortran/35959] New: Recursive function with allocatable array michael dot baudin at gmail dot com
2008-04-17  6:00 ` [Bug fortran/35959] " pault at gcc dot gnu dot org
2008-04-17 20:38 ` pault at gcc dot gnu dot org
2008-04-18  8:14 ` michael dot baudin at gmail dot com
2008-04-18 14:05 ` jvdelisle at gcc dot gnu dot org
2008-04-18 14:12 ` michael dot baudin at gmail dot com
2008-04-18 15:07 ` michael dot baudin at gmail dot com
2008-04-19 21:57 ` pault at gcc dot gnu dot org
2008-04-19 22:31 ` pault at gcc dot gnu dot org
2008-04-19 22:33 ` pault at gcc dot gnu dot org
2008-04-24 19:56 ` michael dot baudin at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).