linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: kernel test robot <lkp@intel.com>,
	Yafang Shao <laoar.shao@gmail.com>,
	kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
	linux-toolchains@vger.kernel.org
Subject: Re: [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used
Date: Sun, 12 Sep 2021 00:33:13 +0200	[thread overview]
Message-ID: <20210911223313.GC4323@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20210911213041.GD1583@gate.crashing.org>

On Sat, Sep 11, 2021 at 04:30:41PM -0500, Segher Boessenkool wrote:
> Hi!
> 
> On Sat, Sep 11, 2021 at 02:20:49PM +0200, Peter Zijlstra wrote:
> > On Sat, Sep 11, 2021 at 02:21:26AM +0800, kernel test robot wrote:
> > > compiler: m68k-linux-gcc (GCC) 11.2.0
> > 
> > >    kernel/sched/fair.c: In function 'update_curr':
> > >    kernel/sched/fair.c:860:42: warning: unused variable 'stats' [-Wunused-variable]
> > >      860 |                 struct sched_statistics *stats = __schedstats_from_se(curr);
> > >          |                                          ^~~~~
> > 
> > OK, compiler guys, this code reads like:
> > 
> > #define schedstats_enabled()	(0)
> > #define __schedstat_set(x, y)	do { } while (0)
> > 
> > 
> > 	if (schedstats_enabled()) {
> > 		struct sched_statistics *stats = __schedstats_from_se(curr);
> > 
> > 		__schedstat_set(stats->exec_max,
> > 				max(delta_exec, stats->exec_max));
> > 	}
> > 
> > So yes, we initialize a variable that then isn't used, but the whole
> > bloody thing is inside if (0) which will not ever get ran *anyway*.
> > 
> > This is a crap warning if ever I saw one...
> 
> Yes, we really should warn "do not use a preprocessor macro if what you
> want is a function"?  The variable really *is* unused, with this macro.

Why would I want to write a bunch of one-off functions and preprocessor
guard them? That's going to be a mess.

> If we would remove dead code before warning about unused variables
> there would be many *more* false positives, fwiw.

Not if you also remove any variables declared in dead code and all
variables only used in the dead code.


      reply	other threads:[~2021-09-11 22:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <202109110214.oh62aoIq-lkp@intel.com>
2021-09-11 12:20 ` [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used Peter Zijlstra
2021-09-11 21:30   ` Segher Boessenkool
2021-09-11 22:33     ` Peter Zijlstra [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210911223313.GC4323@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=kbuild-all@lists.01.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).