This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/86940] False positive with -Wuninitialized
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 14 Aug 2018 02:28:56 +0000
- Subject: [Bug middle-end/86940] False positive with -Wuninitialized
- Auto-submitted: auto-generated
- References: <bug-86940-4@http.gcc.gnu.org/bugzilla/>
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);
^~~~~~~~~~~~~~~~~~