qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/7] Steps towards enabling -Wshadow=local
@ 2023-09-21 12:13 Markus Armbruster
  2023-09-21 12:13 ` [PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error Markus Armbruster
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Markus Armbruster @ 2023-09-21 12:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, hreitz, eblake, vsementsov, jsnow, idryomov, pl, sw,
	sstabellini, anthony.perard, paul, pbonzini, marcandre.lureau,
	berrange, thuth, philmd, stefanha, fam, quintela, peterx, leobras,
	kraxel, qemu-block, xen-devel, alex.bennee, peter.maydell

Local variables shadowing other local variables or parameters make the
code needlessly hard to understand.  Bugs love to hide in such code.
Evidence: PATCH 1.

Enabling -Wshadow would prevent bugs like this one.  But we'd have to
clean up all the offenders first.  We got a lot of them.

Enabling -Wshadow=local should be less work for almost as much gain.
I took a stab at it.  There's a small, exciting part, and a large,
boring part.

The exciting part is dark preprocessor sorcery to let us nest macro
calls without shadowing: PATCH 7.

The boring part is cleaning up all the other warnings.  I did some
[PATCH 2-6], but ran out of steam long before finishing the job.  Some
160 unique warnings remain.

To see them, enable -Wshadow=local like so:

diff --git a/meson.build b/meson.build
index 98e68ef0b1..9fc4c7ac9d 100644
--- a/meson.build
+++ b/meson.build
@@ -466,6 +466,9 @@ warn_flags = [
   '-Wno-tautological-type-limit-compare',
   '-Wno-psabi',
   '-Wno-gnu-variable-sized-type-not-at-end',
+  '-Wshadow=local',
+  '-Wno-error=shadow=local',
+  '-Wno-error=shadow=compatible-local',
 ]
 
 if targetos != 'darwin'

You may want to drop the -Wno-error lines.

v3:
* PATCH 7: Comment typo [Eric], peel off a pair of parenthesis [Eric],
  revert accidental line breaks [Kevin]

v2:
* PATCH 3+6: Mollify checkpatch
* PATCH 4: Redo for clearer code, R-bys dropped [Kevin]
* PATCH 5: Rename tweaked [Kevin]
* PATCH 6: Rename local @tran instead of the parameter [Kevin]
* PATCH 7: Drop PASTE(), use glue() instead [Richard]; pass
  identifiers instead of __COUNTER__ for readability [Eric]; add
  comments

Markus Armbruster (7):
  migration/rdma: Fix save_page method to fail on polling error
  migration: Clean up local variable shadowing
  ui: Clean up local variable shadowing
  block/dirty-bitmap: Clean up local variable shadowing
  block/vdi: Clean up local variable shadowing
  block: Clean up local variable shadowing
  qobject atomics osdep: Make a few macros more hygienic

 include/qapi/qmp/qobject.h      | 10 ++++++++--
 include/qemu/atomic.h           | 17 +++++++++++-----
 include/qemu/compiler.h         |  3 +++
 include/qemu/osdep.h            | 27 ++++++++++++++++++-------
 block.c                         |  9 +++++----
 block/monitor/bitmap-qmp-cmds.c | 19 +++++++++---------
 block/qcow2-bitmap.c            |  3 +--
 block/rbd.c                     |  2 +-
 block/stream.c                  |  1 -
 block/vdi.c                     |  7 +++----
 block/vvfat.c                   | 35 +++++++++++++++++----------------
 hw/block/xen-block.c            |  6 +++---
 migration/block.c               |  4 ++--
 migration/ram.c                 |  8 +++-----
 migration/rdma.c                | 14 ++++++++-----
 migration/vmstate.c             |  2 +-
 ui/gtk.c                        | 14 ++++++-------
 ui/spice-display.c              |  9 +++++----
 ui/vnc-palette.c                |  2 --
 ui/vnc.c                        | 12 +++++------
 ui/vnc-enc-zrle.c.inc           |  9 ++++-----
 21 files changed, 121 insertions(+), 92 deletions(-)

-- 
2.41.0



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

end of thread, other threads:[~2023-09-29  5:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-21 12:13 [PATCH v3 0/7] Steps towards enabling -Wshadow=local Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 2/7] migration: Clean up local variable shadowing Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 3/7] ui: " Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 4/7] block/dirty-bitmap: " Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 5/7] block/vdi: " Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 6/7] block: " Markus Armbruster
2023-09-21 12:13 ` [PATCH v3 7/7] qobject atomics osdep: Make a few macros more hygienic Markus Armbruster
2023-09-21 12:41   ` Philippe Mathieu-Daudé
2023-09-29  5:56 ` [PATCH v3 0/7] Steps towards enabling -Wshadow=local Markus Armbruster

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