linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used
       [not found] <202109110214.oh62aoIq-lkp@intel.com>
@ 2021-09-11 12:20 ` Peter Zijlstra
  2021-09-11 21:30   ` Segher Boessenkool
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2021-09-11 12:20 UTC (permalink / raw)
  To: kernel test robot; +Cc: Yafang Shao, kbuild-all, linux-kernel, linux-toolchains

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...

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

* Re: [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Segher Boessenkool @ 2021-09-11 21:30 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: kernel test robot, Yafang Shao, kbuild-all, linux-kernel,
	linux-toolchains

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

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

* Re: [peterz-queue:sched/core 13/19] kernel/sched/fair.c:892:34: warning: variable 'stats' set but not used
  2021-09-11 21:30   ` Segher Boessenkool
@ 2021-09-11 22:33     ` Peter Zijlstra
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2021-09-11 22:33 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: kernel test robot, Yafang Shao, kbuild-all, linux-kernel,
	linux-toolchains

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.


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

end of thread, other threads:[~2021-09-11 22:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 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).