linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/perf: Do not set a variable unless it will be used
@ 2021-06-04  9:26 Ricardo Ribalda
  2021-06-04  9:36 ` Peter Zijlstra
  0 siblings, 1 reply; 6+ messages in thread
From: Ricardo Ribalda @ 2021-06-04  9:26 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo
  Cc: Ricardo Ribalda

clang-13 triggers the following warning:

bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
        u64 len = 0;

This patch sets the value to len only if it will be used afterwards.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 tools/perf/bench/inject-buildid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-buildid.c
index 55d373b75791..fee69ac787b2 100644
--- a/tools/perf/bench/inject-buildid.c
+++ b/tools/perf/bench/inject-buildid.c
@@ -348,13 +348,13 @@ static int inject_build_id(struct bench_data *data, u64 *max_rss)
 	int status;
 	unsigned int i, k;
 	struct rusage rusage;
-	u64 len = 0;
+	u64 len;
 
 	/* this makes the child to run */
 	if (perf_header__write_pipe(data->input_pipe[1]) < 0)
 		return -1;
 
-	len += synthesize_attr(data);
+	len = synthesize_attr(data);
 	len += synthesize_fork(data);
 
 	for (i = 0; i < nr_mmaps; i++) {
-- 
2.32.0.rc1.229.g3e70b5a671-goog


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

* Re: [PATCH] tools/perf: Do not set a variable unless it will be used
  2021-06-04  9:26 [PATCH] tools/perf: Do not set a variable unless it will be used Ricardo Ribalda
@ 2021-06-04  9:36 ` Peter Zijlstra
  2021-06-04 19:24   ` Ricardo Ribalda
  2021-06-08 11:12   ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Zijlstra @ 2021-06-04  9:36 UTC (permalink / raw)
  To: Ricardo Ribalda
  Cc: linux-kernel, linux-perf-users, Ingo Molnar, Arnaldo Carvalho de Melo

On Fri, Jun 04, 2021 at 11:26:38AM +0200, Ricardo Ribalda wrote:
> clang-13 triggers the following warning:
> 
> bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
>         u64 len = 0;
> 
> This patch sets the value to len only if it will be used afterwards.

My vote would be to kill that warning, what absolute shite.

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

* Re: [PATCH] tools/perf: Do not set a variable unless it will be used
  2021-06-04  9:36 ` Peter Zijlstra
@ 2021-06-04 19:24   ` Ricardo Ribalda
  2021-06-08 11:28     ` Peter Zijlstra
  2021-06-08 11:12   ` David Laight
  1 sibling, 1 reply; 6+ messages in thread
From: Ricardo Ribalda @ 2021-06-04 19:24 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linux Kernel Mailing List, linux-perf-users, Ingo Molnar,
	Arnaldo Carvalho de Melo

Hi Peter

On Fri, 4 Jun 2021 at 11:36, Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Fri, Jun 04, 2021 at 11:26:38AM +0200, Ricardo Ribalda wrote:
> > clang-13 triggers the following warning:
> >
> > bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
> >         u64 len = 0;
> >
> > This patch sets the value to len only if it will be used afterwards.
>
> My vote would be to kill that warning, what absolute shite.

My knowledge of llvm codebase is close to NULL, so it is much easier
for me to "fix" the code.

I would assume that the static analyser has found a magic condition
where the previous if always returns false, and has managed to
"optimize" the code.





-- 
Ricardo Ribalda

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

* RE: [PATCH] tools/perf: Do not set a variable unless it will be used
  2021-06-04  9:36 ` Peter Zijlstra
  2021-06-04 19:24   ` Ricardo Ribalda
@ 2021-06-08 11:12   ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2021-06-08 11:12 UTC (permalink / raw)
  To: 'Peter Zijlstra', Ricardo Ribalda
  Cc: linux-kernel, linux-perf-users, Ingo Molnar, Arnaldo Carvalho de Melo

From: Peter Zijlstra
> Sent: 04 June 2021 10:36
> 
> On Fri, Jun 04, 2021 at 11:26:38AM +0200, Ricardo Ribalda wrote:
> > clang-13 triggers the following warning:
> >
> > bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-
> variable]
> >         u64 len = 0;
> >
> > This patch sets the value to len only if it will be used afterwards.
> 
> My vote would be to kill that warning, what absolute shite.

The compiler folk need their heads examining.

On one hand they are adding code to initialise everything
to avoid leaking information, and on the other they moan
when you do defensive coding.

There might be a justification for:
	foo = complex_expression;
where, maybe, you might have assigned it to the wrong variable.
But for simple constants (especially on declarations)
it is really silly.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] tools/perf: Do not set a variable unless it will be used
  2021-06-04 19:24   ` Ricardo Ribalda
@ 2021-06-08 11:28     ` Peter Zijlstra
  2021-06-09 14:15       ` Ricardo Ribalda
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2021-06-08 11:28 UTC (permalink / raw)
  To: Ricardo Ribalda
  Cc: Linux Kernel Mailing List, linux-perf-users, Ingo Molnar,
	Arnaldo Carvalho de Melo

On Fri, Jun 04, 2021 at 09:24:23PM +0200, Ricardo Ribalda wrote:
> Hi Peter
> 
> On Fri, 4 Jun 2021 at 11:36, Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Fri, Jun 04, 2021 at 11:26:38AM +0200, Ricardo Ribalda wrote:
> > > clang-13 triggers the following warning:
> > >
> > > bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
                                                                         clue here: ^^^^^^^^^^^^^

> > >         u64 len = 0;
> > >
> > > This patch sets the value to len only if it will be used afterwards.
> >
> > My vote would be to kill that warning, what absolute shite.
> 
> My knowledge of llvm codebase is close to NULL, so it is much easier
> for me to "fix" the code.

That's what -Wno-unused-but-set-variable is for, which is trivial to add
to the Makefile.

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

* Re: [PATCH] tools/perf: Do not set a variable unless it will be used
  2021-06-08 11:28     ` Peter Zijlstra
@ 2021-06-09 14:15       ` Ricardo Ribalda
  0 siblings, 0 replies; 6+ messages in thread
From: Ricardo Ribalda @ 2021-06-09 14:15 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linux Kernel Mailing List, linux-perf-users, Ingo Molnar,
	Arnaldo Carvalho de Melo

Hi Peter

On Tue, 8 Jun 2021 at 13:29, Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Fri, Jun 04, 2021 at 09:24:23PM +0200, Ricardo Ribalda wrote:
> > Hi Peter
> >
> > On Fri, 4 Jun 2021 at 11:36, Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Fri, Jun 04, 2021 at 11:26:38AM +0200, Ricardo Ribalda wrote:
> > > > clang-13 triggers the following warning:
> > > >
> > > > bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
>                                                                          clue here: ^^^^^^^^^^^^^
>
> > > >         u64 len = 0;
> > > >
> > > > This patch sets the value to len only if it will be used afterwards.
> > >
> > > My vote would be to kill that warning, what absolute shite.
> >
> > My knowledge of llvm codebase is close to NULL, so it is much easier
> > for me to "fix" the code.
>
> That's what -Wno-unused-but-set-variable is for, which is trivial to add
> to the Makefile.

Yes, that is quite easy to add, the problem is that we might hide real
bugs.  I completely agree that this one is borderline :)



-- 
Ricardo Ribalda

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

end of thread, other threads:[~2021-06-09 14:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04  9:26 [PATCH] tools/perf: Do not set a variable unless it will be used Ricardo Ribalda
2021-06-04  9:36 ` Peter Zijlstra
2021-06-04 19:24   ` Ricardo Ribalda
2021-06-08 11:28     ` Peter Zijlstra
2021-06-09 14:15       ` Ricardo Ribalda
2021-06-08 11:12   ` David Laight

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