tools/perf: Do not set a variable unless it will be used
PATCH 1/1 tools/perf: Do not set a variable unless it will be used
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.
--- tools/perf/bench/inject-buildid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bench/inject-buildid.c +2 -2
@@ -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++) {
Signature · 1 line
2.32.0.rc1.229.g3e70b5a671-goog
Peter Zijlstra
maintainerQuoted 6 lines · 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.
My vote would be to kill that warning, what absolute shite.
Hi Peter
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · 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.
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.
Signature · 1 line
Ricardo Ribalda
Peter Zijlstra
maintainerQuoted 8 lines · Ricardo Ribalda
Hi Peter
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · 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]
clue here: ^^^^^^^^^^^^^
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
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.
Hi Peter
Quoted 16 lines · Peter Zijlstra
Quoted 8 lines · Ricardo Ribalda
Hi Peter
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · 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]clue here: ^^^^^^^^^^^^^Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
u64 len = 0;This patch sets the value to len only if it will be used afterwards.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
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 :)
Signature · 1 line
Ricardo Ribalda
From: Peter Zijlstra
Quoted 5 lines
Sent: 04 June 2021 10:36
Quoted 2 lines · Ricardo Ribalda
clang-13 triggers the following warning:
Quoted 7 lines
Quoted 1 line
bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
Quoted 3 lines
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)