https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85301
Bug ID: 85301 Summary: bitfield check causes maybe-uninitialized warning Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: arnd at linaro dot org Target Milestone: --- A Linux kernel patch that changed a few flags from type 'int' to a single-bit bitfield caused a false-positive warning. I reduced a test case to struct tick_sched { #ifdef USE_BITFIELD unsigned int tick_stopped : 1; unsigned int idle_active : 1; #else int tick_stopped; int idle_active; #endif }; long ktime_get(); void __tick_nohz_idle_restart_tick(long); struct tick_sched tick_nohz_idle_exit_ts; void tick_nohz_idle_exit(void) { long now; if (tick_nohz_idle_exit_ts.idle_active || tick_nohz_idle_exit_ts.tick_stopped) now = ktime_get(); if (tick_nohz_idle_exit_ts.tick_stopped) __tick_nohz_idle_restart_tick(now); } $ gcc -c tick-sched.c -Wall -O2 -DUSE_BITFIELD tick-sched.c: In function ‘tick_nohz_idle_exit’: tick-sched.c:19:5: warning: ‘now’ may be used uninitialized in this function [-Wmaybe-uninitialized] __tick_nohz_idle_restart_tick(now); $ gcc -c tick-sched.c -Wall -O2 # no warning It's easy to work around the warning, e.g. by copying the flag into a temporary variable, but it looks like this is something that gcc could handle better. I looked through the list of false-positive Wmaybe-uninitialized bug reports, but couldn't find one that looks related to this particular one.