size and ubound are lost when passing an array as argument of a procedure
Created attachment 13283 [details] program showing the bug
$ FC=gfortran; $FC -v; $FC -o test test.f; echo; ./test Lecture des spécification à partir de /usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/specs Target: x86_64-pc-linux-gnu Configuré avec: /usr/src/gcc-4.1.2/configure --host=x86_64-pc-linux-gnu --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --enable-threads=posix --with-system-zlib --enable-languages=f95 --disable-multilib Modèle de thread: posix version gcc 4.1.2 size= 5 size= 25 ubound= 5 ubound= 5 5 size= 0 size= 0 ubound= 0 ubound= 2193121 0 FC=/usr/local/bin/gfortran; $FC -v; $FC -o test test.f; echo; ./test Utilisation des specs internes. Target: x86_64-unknown-linux-gnu Configuré avec: ../gcc-4.3-20070316/configure --enable-languages=fortran --disable-multilib Modèle de thread: posix version gcc 4.3.0 20070316 (experimental) size= 5 size= 25 ubound= 5 ubound= 5 5 size= -250 size= 0 ubound= 0 ubound= 5222132 0
Created attachment 13286 [details] the working case The problem arise when the subroutine is not defined in a contains statement in the main program. I haven't seen anything in the Fortran 2003 standard forcing the subroutines to be in the contains statement. But even if it is the case, the compiler should report an error.
(In reply to comment #3) > I haven't seen anything in the Fortran 2003 standard forcing the subroutines to > be in the contains statement. In this case the interface is said to be implicit and the standard does not require the programme to do the right thing. Use an INTERFACE, as below, or put the subroutine in a module. In either case the interface will be made explicit. > But even if it is the case, the compiler should report an error. This is not a requirement of the standard but is a long standing regression, relative to g77. Confirmed and marked as "diagnostic" Nous t'en remercions Cordialement Paul program test interface subroutine test1(x,y) real(kind=8), dimension(:) :: x real(kind=8), dimension(:,:) :: y end subroutine end interface real(kind=8), dimension(5) :: test_array real(kind=8), dimension(5,5) :: test_array2 real(kind=8) :: taille write(6,*) 'size=', size(test_array) write(6,*) 'size=', size(test_array2) write(6,*) 'ubound=', ubound(test_array) write(6,*) 'ubound=', ubound(test_array2) call test1(test_array, test_array2) end program >
(In reply to comment #4) > (In reply to comment #3) > > But even if it is the case, the compiler should report an error. > > This is not a requirement of the standard but is a long standing regression, > relative to g77. Really? From how I read the standard (F2K draft), UBOUND(ARRAY, DIM) has (in this case) "a value equal to the upper bound for subscript DIM of ARRAY". I can't see it allowing returning random values such as 2193121.
(In reply to comment #5) > Really? From how I read the standard (F2K draft), UBOUND(ARRAY, DIM) has (in > this case) "a value equal to the upper bound for subscript DIM of ARRAY". I > can't see it allowing returning random values such as 2193121. The program shown is not valid Fortran, the processor can do whatever it wants. A most sensible choice would be to reject it, of course: that's what g95 does (and g77 also, according to Paul) but others have chosen to segfault (Intel, Sun).
I don't see how this can be a regression wrt g77, which doesn't have assumed-shape arrays or even UBOUND!
We fail to catch the invalid code $ cat whole.f90 program main real, dimension(2) :: a call foo(a) end program main subroutine foo(a) real, dimension(:) :: a end subroutine foo $ gfortran -fwhole-file -O3 whole.f90 $
*** Bug 36553 has been marked as a duplicate of this bug. ***
The dupe had accepts-invalid, adding it here. Pushing back from enhancement to normal.
Subject: Bug 31346 Author: dfranke Date: Tue May 25 18:10:01 2010 New Revision: 159838 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159838 Log: gcc/fortran/: 2010-05-25 Daniel Franke <franke.daniel@gmail.com> PR fortran/30668 PR fortran/31346 PR fortran/34260 * resolve.c (resolve_global_procedure): Add check for global procedures with implicit interfaces and assumed-shape or optional dummy arguments. Verify that function return type, kind and string lengths match. gcc/testsuite/: 2010-05-25 Daniel Franke <franke.daniel@gmail.com> PR fortran/30668 PR fortran/31346 PR fortran/34260 * gfortran.dg/pr40999.f: Fix function type. * gfortran.dg/whole_file_5.f90: Likewise. * gfortran.dg/whole_file_6.f90: Likewise. * gfortran.dg/whole_file_16.f90: New. * gfortran.dg/whole_file_17.f90: New. * gfortran.dg/whole_file_18.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/whole_file_16.f90 trunk/gcc/testsuite/gfortran.dg/whole_file_17.f90 trunk/gcc/testsuite/gfortran.dg/whole_file_18.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/pr40999.f trunk/gcc/testsuite/gfortran.dg/whole_file_5.f90 trunk/gcc/testsuite/gfortran.dg/whole_file_6.f90
Subject: Bug 31346 Author: dfranke Date: Sun Jul 18 20:49:30 2010 New Revision: 162287 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162287 Log: gcc/fortran/: 2010-07-18 Daniel Franke <franke.daniel@gmail.com> Paul Thomas <pault@gcc.gnu.org> PR fortran/30668 PR fortran/31346 PR fortran/34260 * resolve.c (resolve_global_procedure): Improved checking if an explicit interface is required. PR fortran/40011 * resolve.c (resolve_global_procedure): Resolve the gsymbol's namespace before trying to reorder the gsymbols. gcc/testsuite/: 2010-07-18 Daniel Franke <franke.daniel@gmail.com> Paul Thomas <pault@gcc.gnu.org> PR fortran/30668 PR fortran/31346 PR fortran/34260 PR fortran/40011 * gfortran.dg/pr40999.f: Fix function type. * gfortran.dg/whole_file_5.f90: Likewise. * gfortran.dg/whole_file_6.f90: Likewise. * gfortran.dg/whole_file_16.f90: New. * gfortran.dg/whole_file_17.f90: New. * gfortran.dg/whole_file_18.f90: New. * gfortran.dg/whole_file_19.f90: New. Added: branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_16.f90 branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_17.f90 branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_18.f90 branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_19.f90 Modified: branches/gcc-4_5-branch/gcc/fortran/ChangeLog branches/gcc-4_5-branch/gcc/fortran/resolve.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/pr40999.f branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_5.f90 branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/whole_file_6.f90
Fixed in trunk and 4.5. Closing.