[Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?

2020-10-30 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #5 from anlauf at gcc dot gnu.org ---
Should be fixed on master.

[Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?

2020-10-30 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Harald Anlauf :

https://gcc.gnu.org/g:667db6dedd80487663c29b21efa942f661b569a8

commit r11-4579-g667db6dedd80487663c29b21efa942f661b569a8
Author: Harald Anlauf 
Date:   Fri Oct 30 20:49:32 2020 +0100

PR libfortran/97581 - clean up size calculation of random generator state

The random number generator internal state may be saved to/restored from
an array of integers.  Clean up calculation of needed number of elements
to avoid redefiniton of auxiliary macro SZ.

libgfortran/ChangeLog:

* intrinsics/random.c (SZ_IN_INT_4): Define size of state in
int32_t.
(SZ_IN_INT_8): Define size of state in int64_t.
(SZ): Remove.
(random_seed_i4): Use size SZ_IN_INT_4 instead of SZ.
(random_seed_i8): Use size SZ_IN_INT_8 instead of SZ.

[Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?

2020-10-27 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |anlauf at gcc dot 
gnu.org
 Status|WAITING |ASSIGNED

--- Comment #3 from anlauf at gcc dot gnu.org ---
Patch submitted: https://gcc.gnu.org/pipermail/fortran/2020-October/055242.html

[Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?

2020-10-27 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

--- Comment #2 from David Binderman  ---
(In reply to anlauf from comment #1)
> No, this would be definitely wrong.

Agreed.

> If the original code does not make you happy, do you think sth. along
> 
> #define SZ (SZU64 * (sizeof (uint64_t) / sizeof (GFC_INTEGER_4)))
> 
> would be better?

I think it would. Using a more descriptive name than SZ would be even better.
Perhaps SZ_IN_INT_4 ? 

And so the other definition of SZ for random_seed_i8 could be SZ_IN_INT_8.

It might make the code slightly clearer and avoid having two different
# defines for SZ.

[Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?

2020-10-26 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2020-10-26
 Ever confirmed|0   |1

[Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?

2020-10-26 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 CC||anlauf at gcc dot gnu.org

--- Comment #1 from anlauf at gcc dot gnu.org ---
(In reply to David Binderman from comment #0)
> gcc has a new warning, so a problem is found in fortran library.
> 
> libgfortran/intrinsics/random.c:754:37: warning: expression does not compute
> the number of elements in this array; element type is ‘uint64_t’ {aka ‘long
> unsigned int’}, not ‘GFC_INTEGER_4’ {aka ‘int’} [-Wsizeof-array-div]
> 
> Source code is
> 
> #define SZ (sizeof (master_state.s) / sizeof (GFC_INTEGER_4))
> 
> Maybe better code
> 
> #define SZ (sizeof (master_state.s) / sizeof (master_state.s[0]))

No, this would be definitely wrong.

The purpose of RANDOM_SEED is to set/get the internal state of the PRNG in
an array of integers, with the size depending on the kind of the argument.
The function random_seed_i4 uses GFC_INTEGER_4 for that purpose.

If the original code does not make you happy, do you think sth. along

#define SZ (SZU64 * (sizeof (uint64_t) / sizeof (GFC_INTEGER_4)))

would be better?