qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/2] -Wshadow=local patches for 2023-11-13
@ 2023-11-13  9:36 Markus Armbruster
  2023-11-13  9:36 ` [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local Markus Armbruster
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Markus Armbruster @ 2023-11-13  9:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

The following changes since commit 69680740eafa1838527c90155a7432d51b8ff203:

  Merge tag 'qdev-array-prop' of https://repo.or.cz/qemu/kevin into staging (2023-11-11 11:23:25 +0800)

are available in the Git repository at:

  https://repo.or.cz/qemu/armbru.git tags/pull-shadow-2023-11-13

for you to fetch changes up to 569205e4e92f802cf409fe03dd2ac41dd0b54aae:

  meson: Enable -Wshadow=local (2023-11-13 10:32:57 +0100)

----------------------------------------------------------------
-Wshadow=local patches for 2023-11-13

----------------------------------------------------------------
Markus Armbruster (1):
      meson: Enable -Wshadow=local

Thomas Huth (1):
      block/snapshot: Fix compiler warning with -Wshadow=local

 meson.build      | 1 +
 block/snapshot.c | 6 ++----
 2 files changed, 3 insertions(+), 4 deletions(-)

-- 
2.41.0



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

* [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local
  2023-11-13  9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
@ 2023-11-13  9:36 ` Markus Armbruster
  2023-11-13  9:36 ` [PULL 2/2] meson: Enable -Wshadow=local Markus Armbruster
  2023-11-13 19:27 ` [PULL 0/2] -Wshadow=local patches for 2023-11-13 Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2023-11-13  9:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha, Thomas Huth

From: Thomas Huth <thuth@redhat.com>

No need to declare a new variable in the the inner code block
here, we can re-use the "ret" variable that has been declared
at the beginning of the function. With this change, the code
can now be successfully compiled with -Wshadow=local again.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20231023175038.111607-1-thuth@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/snapshot.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/block/snapshot.c b/block/snapshot.c
index 6e16eb803a..55974273ae 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -629,7 +629,6 @@ int bdrv_all_goto_snapshot(const char *name,
     while (iterbdrvs) {
         BlockDriverState *bs = iterbdrvs->data;
         AioContext *ctx = bdrv_get_aio_context(bs);
-        int ret = 0;
         bool all_snapshots_includes_bs;
 
         aio_context_acquire(ctx);
@@ -637,9 +636,8 @@ int bdrv_all_goto_snapshot(const char *name,
         all_snapshots_includes_bs = bdrv_all_snapshots_includes_bs(bs);
         bdrv_graph_rdunlock_main_loop();
 
-        if (devices || all_snapshots_includes_bs) {
-            ret = bdrv_snapshot_goto(bs, name, errp);
-        }
+        ret = (devices || all_snapshots_includes_bs) ?
+              bdrv_snapshot_goto(bs, name, errp) : 0;
         aio_context_release(ctx);
         if (ret < 0) {
             bdrv_graph_rdlock_main_loop();
-- 
2.41.0



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

* [PULL 2/2] meson: Enable -Wshadow=local
  2023-11-13  9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
  2023-11-13  9:36 ` [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local Markus Armbruster
@ 2023-11-13  9:36 ` Markus Armbruster
  2023-11-13 19:27 ` [PULL 0/2] -Wshadow=local patches for 2023-11-13 Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2023-11-13  9:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha, Thomas Huth, Philippe Mathieu-Daudé

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 <armbru@redhat.com>
Message-ID: <20231026053115.2066744-2-armbru@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 meson.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/meson.build b/meson.build
index d7d841e71e..ec01f8b138 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'
-- 
2.41.0



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

* Re: [PULL 0/2] -Wshadow=local patches for 2023-11-13
  2023-11-13  9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
  2023-11-13  9:36 ` [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local Markus Armbruster
  2023-11-13  9:36 ` [PULL 2/2] meson: Enable -Wshadow=local Markus Armbruster
@ 2023-11-13 19:27 ` Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2023-11-13 19:27 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, stefanha

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

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2023-11-13 19:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-13  9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
2023-11-13  9:36 ` [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local Markus Armbruster
2023-11-13  9:36 ` [PULL 2/2] meson: Enable -Wshadow=local Markus Armbruster
2023-11-13 19:27 ` [PULL 0/2] -Wshadow=local patches for 2023-11-13 Stefan Hajnoczi

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