public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/105171] New: `local_tick` can overflow and become -1
@ 2022-04-05 22:37 jason at zx2c4 dot com
  2022-04-05 22:52 ` [Bug driver/105171] gcc/toplev.c: " jason at zx2c4 dot com
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: jason at zx2c4 dot com @ 2022-04-05 22:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105171
           Summary: `local_tick` can overflow and become -1
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jason at zx2c4 dot com
  Target Milestone: ---

In gcc/toplev.c, there's the comment:

    /* A local time stamp derived from the time of compilation. It will be
       zero if the system cannot provide a time.  It will be -1u, if the
       user has specified a particular random seed.  */
    unsigned local_tick;

This is affirmed by init_local_tick()'s comment:

    /* Initialize local_tick with the time of day, or -1 if
       flag_random_seed is set.  */
    static void init_local_tick (void)

And indeed we see it assigned -1 when flag_random_seed != NULL:

    else
      local_tick = -1;

So far so good. However, in the case where flag_random_seed == NULL, local_tick
is assigned like this:

    struct timeval tv;
    gettimeofday (&tv, NULL);
    local_tick = (unsigned) tv.tv_sec * 1000 + tv.tv_usec / 1000;

Recall that local_tick is of type "unsigned". Somewhat often, that expression
calculates to be 0xffffffff, which means local_tick winds up being -1 even when
flag_random_seed == NULL.

This is a problem for plugins that follow the documentation comments in order
to determine whether -frandom-seed is being used. To work around this bug,
these plugins should just call get_random_seed(noinit=true) in their plugin
init functions and check there whether the return value is zero. If they use a
local_tick==-1 check, once in a blue moon, it'll be wrong.

Probably, though, the type of local_tick should be changed to a HOST_WIDE_INT,
or something similar to that.

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

end of thread, other threads:[~2022-04-19 19:15 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 22:37 [Bug driver/105171] New: `local_tick` can overflow and become -1 jason at zx2c4 dot com
2022-04-05 22:52 ` [Bug driver/105171] gcc/toplev.c: " jason at zx2c4 dot com
2022-04-05 23:02 ` [Bug plugins/105171] " pinskia at gcc dot gnu.org
2022-04-05 23:02 ` pinskia at gcc dot gnu.org
2022-04-05 23:06 ` jason at zx2c4 dot com
2022-04-06  5:44 ` pinskia at gcc dot gnu.org
2022-04-06  7:10 ` pageexec at gmail dot com
2022-04-06  7:26 ` pinskia at gcc dot gnu.org
2022-04-06  7:50 ` jakub at gcc dot gnu.org
2022-04-06  8:01 ` pageexec at gmail dot com
2022-04-06  8:16 ` pinskia at gcc dot gnu.org
2022-04-06  8:22 ` jakub at gcc dot gnu.org
2022-04-06  8:34 ` pageexec at gmail dot com
2022-04-06  8:37 ` jakub at gcc dot gnu.org
2022-04-06  8:59 ` pageexec at gmail dot com
2022-04-06 22:46 ` jason at zx2c4 dot com
2022-04-06 22:52 ` pinskia at gcc dot gnu.org
2022-04-06 23:02 ` pinskia at gcc dot gnu.org
2022-04-06 23:11 ` jason at zx2c4 dot com
2022-04-06 23:13 ` pinskia at gcc dot gnu.org
2022-04-07 13:01 ` rguenth at gcc dot gnu.org
2022-04-14 12:18 ` jason at zx2c4 dot com
2022-04-14 13:22 ` jakub at gcc dot gnu.org
2022-04-19 19:15 ` jason at zx2c4 dot com

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