Bug 37159 - RANDOM_SEED: GET= check array size at compile time and respect -fdefault-integer-*
Summary: RANDOM_SEED: GET= check array size at compile time and respect -fdefault-in...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Daniel Franke
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2008-08-19 06:28 UTC by Tobias Burnus
Modified: 2009-05-01 15:21 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-08-24 18:34:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-08-19 06:28:20 UTC
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
Comment 1 Tobias Burnus 2008-08-24 06:36:41 UTC
Patch: http://gcc.gnu.org/ml/fortran/2008-08/msg00190.html
Comment 2 Thomas Koenig 2008-08-24 18:34:07 UTC
Confirmed.
Comment 3 Dennis Wassel 2008-09-18 21:00:07 UTC
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?
Comment 4 Thomas Koenig 2008-11-01 10:25:38 UTC
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

Comment 5 Thomas Koenig 2008-11-01 10:29:03 UTC
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
Comment 6 Tobias Burnus 2008-11-02 14:18:15 UTC
> 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).
Comment 7 Michael Richmond 2008-11-10 00:09:45 UTC
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)
Comment 8 Jerry DeLisle 2008-11-10 03:16:40 UTC
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
Comment 9 Michael Richmond 2008-11-10 12:59:43 UTC
(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
Comment 10 Dennis Wassel 2008-11-10 13:32:15 UTC
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?
Comment 11 Michael Richmond 2008-11-10 13:50:02 UTC
(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
Comment 12 kargls 2008-11-10 15:01:25 UTC
(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.
Comment 13 Daniel Franke 2008-12-09 22:36:12 UTC
See comments #5 and #6 for remaining tasks.
Comment 14 Daniel Franke 2009-01-05 19:34:17 UTC
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

Comment 15 Francois-Xavier Coudert 2009-05-01 15:10:24 UTC
Daniel, shouldn't this PR be closed?
Comment 16 Daniel Franke 2009-05-01 15:21:18 UTC
Fixed in trunk. Closing.