This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/81897] New: spurious -Wmaybe-uninitialized warning
- From: "arnd at linaro dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Aug 2017 19:44:50 +0000
- Subject: [Bug middle-end/81897] New: spurious -Wmaybe-uninitialized warning
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81897
Bug ID: 81897
Summary: spurious -Wmaybe-uninitialized warning
Product: gcc
Version: 7.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: arnd at linaro dot org
Target Milestone: ---
I keep seeing a class of false-positive -Wmaybe-uninitialized in the linux
kernel and have done countless kernel patches to work around them. The latest
one triggered me to look a little deeper. The general pattern I see is that
when one variable is conditionally initialized and conditionally used based on
the same variable, but any form of lock (mutex, semaphore, spinlock, ...)
release happens in-between, the compiler no longer knows if the initialization
was correct, and produces a spurious warning.
This particular instance of the warning I saw today reduced to a relatively
simple function between the initialization and the use:
int f(void);
static inline void rcu_read_unlock(void)
{
static _Bool __warned;
if (f() && !__warned && !f()) {
__warned = 1;
}
}
int inet6_rtm_getroute(void)
{
int dst;
int fibmatch = f();
if (!fibmatch)
dst = f();
rcu_read_unlock();
if (fibmatch)
dst = 0;
return dst;
}
Clearly, 'dst' is initialized here when it gets returned.
I can reproduce the warning in gcc-4.7 through 7.1.1, which is the latest I
tried.