[lkml]   [2015]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: gcc doesn't warn about uninitialized variable use in switch/case with -O (was: Re: [PATCH] Staging: dgnc: Using temporary value for repeated dereferences)
On Mon, 2015-04-20 at 03:42 -0700, Joe Perches wrote:
> On Mon, 2015-04-20 at 11:33 +0300, Dan Carpenter wrote:
> > You would hope that GCC would warn about the uninitialized variable but
> > it doesn't.
> That's odd. So I filed this new gcc bugzilla:
> gcc 4.9.1 doesn't warn about uninitialized variable use
> declared in a switch/case statement when compiled with -O

Hey Dan/Yorick

A bit more investigation:

It's true that gcc doesn't report the uninitialized
variable for the code I showed, but that's probably not
the reason the "may be used uninitialized" warning is not
shown for the dgnc code as patched by Yorick.

The example code doesn't show the "uninitialized" warning
because gcc's dead code elimination is set by -O and the
sample code foo_2 function switch/case is eliminated.

Perhaps the warning is not shown for this dgnc patch
because your .config has CONFIG_GCOV_PROFILE_ALL set.

That enables the gcc -fprofile-arcs option which masks the
warning, I don't know why.

Maybe see:

commit 2521f2c228ad750701ba4702484e31d876dbc386
Author: Peter Oberparleiter <>
Date: Wed Jun 17 16:28:08 2009 -0700

gcov: add gcov profiling infrastructure

Enable the use of GCC's coverage testing tool gcov [1] with the Linux
kernel. gcov may be useful for:

* debugging (has this code been reached at all?)
* test improvement (how do I change my test to cover these lines?)
* minimizing kernel configurations (do I need this option if the
associated code is never run?)

The profiling patch incorporates the following changes:

* change kbuild to include profiling flags
* provide functions needed by profiling code
* present profiling data as files in debugfs

Note that on some architectures, enabling gcc's profiling option
"-fprofile-arcs" for the entire kernel may trigger compile/link/
run-time problems, some of which are caused by toolchain bugs and
others which require adjustment of architecture code.

For this reason profiling the entire kernel is initially restricted
to those architectures for which it is known to work without changes.
This restriction can be lifted once an architecture has been tested
and found compatible with gcc's profiling. Profiling of single files
or directories is still available on all platforms (see config help


 \ /
  Last update: 2015-04-20 15:01    [W:0.053 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site