public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44478]  New: -Wunused- but-set-variable is incredible noisy in kernel builds
@ 2010-06-09  9:41 andi-gcc at firstfloor dot org
  2010-06-09  9:50 ` [Bug c/44478] " paolo dot carlini at oracle dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2010-06-09  9:41 UTC (permalink / raw)
  To: gcc-bugs

When building a Linux kernel the new default of having
-Wunused-but-set-variable is incredibly noisy in kernel build. I get hundreds
of new warnings from that.

I looked at some of the circumstances and it's typically

int var = VALUE;

#ifdef SYMBOL
if (do something)
  var = other value
#endif

with SYMBOL being undefined in this build.

I don't think it's feasible to avoid the warning short of turning it off.
I suspect other code bases will have the same problem.
Can the warning be removed from -Wall please?


-- 
           Summary: -Wunused- but-set-variable is incredible noisy in kernel
                    builds
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: andi-gcc at firstfloor dot org
  GCC host triplet: x86_64-linux
GCC target triplet: x86_64-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/44478] -Wunused- but-set-variable is incredible noisy in kernel builds
  2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
@ 2010-06-09  9:50 ` paolo dot carlini at oracle dot com
  2010-06-09  9:54 ` jakub at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-06-09  9:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from paolo dot carlini at oracle dot com  2010-06-09 09:49 -------
I'm sure you are right, but I don't understand your explanation: even when
SYMBOL
is undefined, why no code actually uses (roughly speaking, reads) var? That's
the point of the warning and your example doesn't seem to shed any special
light on that.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/44478] -Wunused- but-set-variable is incredible noisy in kernel builds
  2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
  2010-06-09  9:50 ` [Bug c/44478] " paolo dot carlini at oracle dot com
@ 2010-06-09  9:54 ` jakub at gcc dot gnu dot org
  2010-06-09 10:13 ` andi-gcc at firstfloor dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-06-09  9:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2010-06-09 09:53 -------
The warning is useful and can find (and already found) several real bugs e.g.
in gcc itself.  Icc has similar warning.
If kernel has lots of useless code like that and doesn't wish to use this
warning, it can add -Wno-unused-but-set-{variable,parameter} to CFLAGS it uses.

Note that in the snippet you mentioned -Wunused would warn always, no matter
whether SYMBOL is defined or not.  When it is not defined, var is unused (also
warned with 4.5 and earlier), when it is defined, var is only set but never
used.

I guess what you really mean is that kernel has lots of snippets that set some
variable to some value and then only conditionally (in #ifdef guarded code)
uses it.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/44478] -Wunused- but-set-variable is incredible noisy in kernel builds
  2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
  2010-06-09  9:50 ` [Bug c/44478] " paolo dot carlini at oracle dot com
  2010-06-09  9:54 ` jakub at gcc dot gnu dot org
@ 2010-06-09 10:13 ` andi-gcc at firstfloor dot org
  2010-06-09 10:52 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2010-06-09 10:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from andi-gcc at firstfloor dot org  2010-06-09 10:13 -------
Sorry my example was not very good.

Anyways this typically happens with #ifdefs, so the some ifdef path
is actually using the variable, it's just not enabled in the current build.
In theory the ifdefs could be put around the variables too, but
it would increase the ifdef frequency a lot.

Another case i've also seen is to use it as a dummy output variable of inline
assembler, where the assembler is in a macro and it's sometimes used
and sometimes not.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/44478] -Wunused- but-set-variable is incredible noisy in kernel builds
  2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
                   ` (2 preceding siblings ...)
  2010-06-09 10:13 ` andi-gcc at firstfloor dot org
@ 2010-06-09 10:52 ` jakub at gcc dot gnu dot org
  2010-06-09 11:09 ` andi-gcc at firstfloor dot org
  2010-06-09 11:37 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-06-09 10:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2010-06-09 10:52 -------
We don't warn on
void foo (void)
{
  int dummy;
  asm ("" : "=r" (dummy));
}
- the use in the asm is considered as a use, not just set.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/44478] -Wunused- but-set-variable is incredible noisy in kernel builds
  2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
                   ` (3 preceding siblings ...)
  2010-06-09 10:52 ` jakub at gcc dot gnu dot org
@ 2010-06-09 11:09 ` andi-gcc at firstfloor dot org
  2010-06-09 11:37 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: andi-gcc at firstfloor dot org @ 2010-06-09 11:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from andi-gcc at firstfloor dot org  2010-06-09 11:08 -------
Hmm yes there was another temporary and a inline inbetween

unsigned inlinefunc(void)
{
   unsigned var;
   asm(" ... " : "=r" (var));
   return var;
}

#define macro(x,y)
{ 
unsigned var = inlinefunc();
x = var;
y = var >> 16;
};

caller macro(x,y)      y is just a dummy


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/44478] -Wunused- but-set-variable is incredible noisy in kernel builds
  2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
                   ` (4 preceding siblings ...)
  2010-06-09 11:09 ` andi-gcc at firstfloor dot org
@ 2010-06-09 11:37 ` jakub at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-06-09 11:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2010-06-09 11:36 -------
Then it has nothing to do with the asm.
If the macro is widely used and very often sets a var that isn't used, all
you can do is add (void) cast to shut the warning up.
(void) (y = var >> 16);
in this case.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44478


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-06-09 11:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-09  9:41 [Bug c/44478] New: -Wunused- but-set-variable is incredible noisy in kernel builds andi-gcc at firstfloor dot org
2010-06-09  9:50 ` [Bug c/44478] " paolo dot carlini at oracle dot com
2010-06-09  9:54 ` jakub at gcc dot gnu dot org
2010-06-09 10:13 ` andi-gcc at firstfloor dot org
2010-06-09 10:52 ` jakub at gcc dot gnu dot org
2010-06-09 11:09 ` andi-gcc at firstfloor dot org
2010-06-09 11:37 ` jakub at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).