The run-time library has: static const GFC_INTEGER_4 kiss_size = sizeof(kiss_seed)/sizeof(kiss_seed[0]); if (((put->dim[0].ubound + 1 - put->dim[0].lbound)) < kiss_size) runtime_error ("Array size of PUT is too small."); It would be great if the size could already be checked at compile time: integer size(6) CALL RANDOM_SEED(size=size(1)) print *, size(1) CALL RANDOM_SEED(put=size) end $ ./a.out 8 Fortran runtime error: Array size of PUT is too small. Note: If HAVE_GFC_REAL_16 is set, size is larger than 8. Vector too small for argument PUT (no. 2) of intrinsic RANDOM_SEED NAG f95 checks things at compile time: Error: Vector too small for argument PUT (no. 2) of intrinsic RANDOM_SEED
Patch: http://gcc.gnu.org/ml/fortran/2008-08/msg00190.html
Confirmed.
Updated patch: http://gcc.gnu.org/ml/fortran/2008-09/msg00161.html Will be committed by Thomas Koenig as soon as my copyright assignment is done. How come I cannot add myself in the "assigned to" or change the status?
Subject: Bug 37159 Author: tkoenig Date: Sat Nov 1 10:24:15 2008 New Revision: 141511 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141511 Log: 2008-11-01 Dennis Wassel <dennis.wassel@gmail.com> PR fortran/37159 * fortran/check.c (gfc_check_random_seed): Check PUT size at compile time. 2008-11-01 Dennis Wassel <dennis.wassel@gmail.com> PR fortran/37159 * intrinsics/random.c: Added comment to adapt check.c, should kiss_size change. Few cosmetic changes to existing comments. 2008-11-01 Dennis Wassel <dennis.wassel@gmail.com> PR fortran/37159 * gfortran.dg/random_seed_1.f90: New testcase. Added: trunk/gcc/testsuite/gfortran.dg/random_seed_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/check.c trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/intrinsics/random.c
Committed patch. Not closing yet, as the GET array could also be checked, see http://gcc.gnu.org/ml/fortran/2008-10/msg00281.html . Thomas
> Not closing yet, as the GET array could also be checked, > see http://gcc.gnu.org/ml/fortran/2008-10/msg00281.html . Another item: If the default integer is 8 instead of 4, the array sizes are half as big (see also URL).
I get a compile-time error: mrichmon@msc545ux:~$ cat sort1.f90 PROGRAM sort1 INTEGER Count(1) !Current value of system clock CALL Random_Seed(Put=Count) END PROGRAM sort1 mrichmon@msc545ux:~$ gfortran sort1.f90 sort1.f90:3.23: CALL Random_Seed(Put=Count) 1 Error: Array PUT of intrinsic random_seed is too small (1/8) at (1)
If you check, the minimum size of count is 8 as returned by the size= argument if you use it. Try this. size is intent OUT. PROGRAM sort1 INTEGER Count(1) !Current value of system clock integer Size CALL Random_Seed(size=size) print *, size ! CALL Random_Seed(Put=Count) END PROGRAM sort1
(In reply to comment #8) > If you check, the minimum size of count is 8 as returned by the size= argument > if you use it. Try this. size is intent OUT. The documentation says only that the size argument has to be an integer. See http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html
Subject: Re: RANDOM_SEED: PUT= check array size at compile time > The documentation says only that the size argument has to be an integer. See > http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html On the contrary: The documentation clearly and concisely states SIZE (Optional) Shall be a scalar and of type default INTEGER, with INTENT(OUT). It specifies the minimum size of the arrays used with the PUT and GET arguments. Admitted, it does not say SIZE = 8, because this value may be compiler- and system-dependent (may also be 12 for gfortran on some platforms), which is why the standard provides the SIZE argument in the first place. I fail to see the problem - could you clarify?
(In reply to comment #10) > Admitted, it does not say SIZE = 8, because this value may be > compiler- and system-dependent (may also be 12 for gfortran on some > platforms), which is why the standard provides the SIZE argument in > the first place. > > I fail to see the problem - could you clarify? > A default integer on i386 is 4 bytes. The instruction "print sizeof(size)" prints 4. I assume it should also print 4 if I use: CALL Random_Seed(size=size) print *, size
(In reply to comment #11) > (In reply to comment #10) > > Admitted, it does not say SIZE = 8, because this value may be > > compiler- and system-dependent (may also be 12 for gfortran on some > > platforms), which is why the standard provides the SIZE argument in > > the first place. > > > > I fail to see the problem - could you clarify? > > > > A default integer on i386 is 4 bytes. The instruction "print sizeof(size)" > prints 4. I assume it should also print 4 if I use: > > CALL Random_Seed(size=size) > print *, size > 'SIZE' is the number of elements in the array that you need to use with PUT= and GET= program a integer, allocatable :: seeds(:) integer n call random_seed(size = n) allocate(seeds(n)) call random_seed(get = seeds) print*, seeds deallocate(seeds) end program It seems you need to revisit Metcalf and Reid or the Standard.
See comments #5 and #6 for remaining tasks.
Subject: Bug 37159 Author: dfranke Date: Mon Jan 5 19:34:02 2009 New Revision: 143089 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143089 Log: gcc/fortran: 2009-01-05 Daniel Franke <franke.daniel@gmail.com> PR fortran/37159 * check.c (gfc_check_random_seed): Added size check for GET dummy argument, reworded error messages to follow common pattern. gcc/testsuite: 2009-01-05 Daniel Franke <franke.daniel@gmail.com> PR fortran/37159 * gfortran.dg/random_seed_1.f90: Updated. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/check.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/random_seed_1.f90
Daniel, shouldn't this PR be closed?
Fixed in trunk. Closing.