On 26/10/23 08:12, Thomas Huth wrote:
On 26/10/2023 07.58, Philippe Mathieu-Daudé wrote:
On 26/10/23 07:31, Markus Armbruster wrote:
Local variables shadowing other local variables or parameters make the
code needlessly hard to understand. Bugs love to hide in such code.
Evidence: commit bbde656263d (migration/rdma: Fix save_page method to
fail on polling error).
Enable -Wshadow=local to prevent such issues. Possible thanks to
recent cleanups. Enabling -Wshadow would prevent more issues, but
we're not yet ready for that.
As usual, the warning is only enabled when the compiler recognizes it.
GCC does, Clang doesn't.
Some shadowed locals remain in bsd-user. Since BSD prefers Clang,
let's not wait for its cleanup.
Signed-off-by: Markus Armbruster <arm...@redhat.com>
---
meson.build | 1 +
1 file changed, 1 insertion(+)
diff --git a/meson.build b/meson.build
index dcef8b1e79..89220443b8 100644
--- a/meson.build
+++ b/meson.build
@@ -462,6 +462,7 @@ warn_flags = [
'-Wno-tautological-type-limit-compare',
'-Wno-psabi',
'-Wno-gnu-variable-sized-type-not-at-end',
+ '-Wshadow=local',
]
if targetos != 'darwin'
Using Clang on Darwin:
$ ../configure
The Meson build system
Version: 1.2.1
Build type: native build
Project name: qemu
Project version: 8.1.50
C compiler for the host machine: cc (clang 15.0.0 "Apple clang version
15.0.0 (clang-1500.0.40.1)")
C linker for the host machine: cc ld64 1015.7
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program sh found: YES (/bin/sh)
Objective-C compiler for the host machine: clang (clang 15.0.0)
Objective-C linker for the host machine: clang ld64 1015.7
Compiler for Objective-C supports arguments -Wshadow=local: NO
So:
Tested-by: Philippe Mathieu-Daudé <phi...@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>
Now don't blame me for posting patches with trigger shadow=local
warnings because I am not testing that locally.
I find it a bit unfair to force me rely on CI or other machines
rather than my host machine to check for warnings. I'd have
rather waited this option support lands first in Clang before
enabling this flag.
Huh, that situation is already pre-existing, e.g. with
-Wimplicit-fallthrough=2 ... and if you're too afraid, you can always
install gcc via homebrew to check.
OK, fine.