[Bug middle-end/86940] False positive with -Wuninitialized

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Aug 14 02:29:00 GMT 2018


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Aritz Erkiaga from comment #4)

GCC does have knowledge about many libc functions but rand() isn't one of them
(yet).  It would be possible to add rand() to the list but it would only solve
this one test case (i.e., involving rand()).  I don't think adding a built-in
just to avoid a -Wuninitialized in this case is worth it.  There may be other
reasons to add it, such as constraining its return value to [0, RAND_MAX].  If
you can make a more compelling case for it there's a decent chance that it will
be added.

Barring that, the test case reduces to:

$ cat pr86940.c && gcc -O2 -S -Wall pr86940.c
int f (void);

void g (void)
{
  void *p;
  if (f ())
    p = __builtin_malloc (8);

  if (f ()) 
    __builtin_free (p);
}
pr86940.c: In function ‘g’:
pr86940.c:10:5: warning: ‘p’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
     __builtin_free (p);
     ^~~~~~~~~~~~~~~~~~


More information about the Gcc-bugs mailing list