public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ?
@ 2020-10-26 13:13 dcb314 at hotmail dot com
  2020-10-26 20:32 ` [Bug libfortran/97581] " anlauf at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2020-10-26 13:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

            Bug ID: 97581
           Summary: libgfortran/intrinsics/random.c:754: bad array size ?
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

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]))

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

* [Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?
  2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
@ 2020-10-26 20:32 ` anlauf at gcc dot gnu.org
  2020-10-26 20:35 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-26 20:32 UTC (permalink / raw)
  To: 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?

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

* [Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?
  2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
  2020-10-26 20:32 ` [Bug libfortran/97581] " anlauf at gcc dot gnu.org
@ 2020-10-26 20:35 ` anlauf at gcc dot gnu.org
  2020-10-27  7:37 ` dcb314 at hotmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-26 20:35 UTC (permalink / raw)
  To: 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

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

* [Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?
  2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
  2020-10-26 20:32 ` [Bug libfortran/97581] " anlauf at gcc dot gnu.org
  2020-10-26 20:35 ` anlauf at gcc dot gnu.org
@ 2020-10-27  7:37 ` dcb314 at hotmail dot com
  2020-10-27 21:14 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dcb314 at hotmail dot com @ 2020-10-27  7:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---
(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.

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

* [Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?
  2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2020-10-27  7:37 ` dcb314 at hotmail dot com
@ 2020-10-27 21:14 ` anlauf at gcc dot gnu.org
  2020-10-30 19:50 ` cvs-commit at gcc dot gnu.org
  2020-10-30 19:55 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-27 21:14 UTC (permalink / raw)
  To: 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

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

* [Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?
  2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
                   ` (3 preceding siblings ...)
  2020-10-27 21:14 ` anlauf at gcc dot gnu.org
@ 2020-10-30 19:50 ` cvs-commit at gcc dot gnu.org
  2020-10-30 19:55 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-30 19:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97581

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

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

commit r11-4579-g667db6dedd80487663c29b21efa942f661b569a8
Author: Harald Anlauf <anlauf@gmx.de>
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.

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

* [Bug libfortran/97581] libgfortran/intrinsics/random.c:754: bad array size ?
  2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
                   ` (4 preceding siblings ...)
  2020-10-30 19:50 ` cvs-commit at gcc dot gnu.org
@ 2020-10-30 19:55 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-10-30 19:55 UTC (permalink / raw)
  To: 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.

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

end of thread, other threads:[~2020-10-30 19:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 13:13 [Bug libfortran/97581] New: libgfortran/intrinsics/random.c:754: bad array size ? dcb314 at hotmail dot com
2020-10-26 20:32 ` [Bug libfortran/97581] " anlauf at gcc dot gnu.org
2020-10-26 20:35 ` anlauf at gcc dot gnu.org
2020-10-27  7:37 ` dcb314 at hotmail dot com
2020-10-27 21:14 ` anlauf at gcc dot gnu.org
2020-10-30 19:50 ` cvs-commit at gcc dot gnu.org
2020-10-30 19:55 ` anlauf at gcc dot gnu.org

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).