This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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);
     ^~~~~~~~~~~~~~~~~~

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]