All of lore.kernel.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Peter Zijlstra <peterz@infradead.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: Sat, 11 Sep 2021 16:30:41 -0500	[thread overview]
Message-ID: <20210911213041.GD1583@gate.crashing.org> (raw)
In-Reply-To: <20210911122049.GW4323@worktop.programming.kicks-ass.net>

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.

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


Segher

WARNING: multiple messages have this Message-ID (diff)
From: Segher Boessenkool <segher@kernel.crashing.org>
To: kbuild-all@lists.01.org
Subject: Re: [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used
Date: Sat, 11 Sep 2021 16:30:41 -0500	[thread overview]
Message-ID: <20210911213041.GD1583@gate.crashing.org> (raw)
In-Reply-To: <20210911122049.GW4323@worktop.programming.kicks-ass.net>

[-- Attachment #1: Type: text/plain, Size: 1301 bytes --]

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.

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


Segher

  reply	other threads:[~2021-09-11 21:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 18:21 [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used kernel test robot
2021-09-10 18:21 ` kernel test robot
2021-09-11  1:46 ` Yafang Shao
2021-09-11  1:46   ` Yafang Shao
2021-09-11 12:20 ` Peter Zijlstra
2021-09-11 12:20   ` Peter Zijlstra
2021-09-11 21:30   ` Segher Boessenkool [this message]
2021-09-11 21:30     ` Segher Boessenkool
2021-09-11 22:33     ` Peter Zijlstra
2021-09-11 22:33       ` Peter Zijlstra

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=20210911213041.GD1583@gate.crashing.org \
    --to=segher@kernel.crashing.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=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.