Skip to content

Steps towards enabling -Wshadow=local

Markus Armbruster qemu-devel xen-devel 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest7 patches 2 repliesIn review
  2. v27 patches 8 repliesSuperseded
  3. v17 patches 31 repliesSuperseded

Changes in v3 from the cover letter

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

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7migration/rdma: Fix save_page method to fail on polling errormigration/rdma.c+4 -20 replies
2/7migration: Clean up local variable shadowingmigration/block.c migration/ram.c migration/rdma.c +1 more+11 -110 replies
3/7ui: Clean up local variable shadowingui/gtk.c ui/spice-display.c ui/vnc-enc-zrle.c.inc +2 more+22 -240 replies
4/7block/dirty-bitmap: Clean up local variable shadowingblock/monitor/bitmap-qmp-cmds.c block/qcow2-bitmap.c+11 -110 replies
5/7block/vdi: Clean up local variable shadowingblock/vdi.c+3 -40 replies
6/7block: Clean up local variable shadowingblock.c block/rbd.c block/stream.c +2 more+27 -260 replies
7/7qobject atomics osdep: Make a few macros more hygienicinclude/qapi/qmp/qobject.h include/qemu/atomic.h include/qemu/compiler.h +1 more+43 -141 reply

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchEric BlakePeter XuLi ZhijianStefan HajnocziKevin WolfPeter MaydellAnthony PERARDIlya DryomovPhilippe Mathieu-Daudé
1/7R-b R-b R-b
2/7R-b R-b
3/7R-b
4/7R-b
5/7R-b R-b
6/7R-b R-b A-b A-b
7/7R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 9 reviewers.

Read the v3 thread

Cover letter [PATCH v3 0/7] Steps towards enabling -Wshadow=local

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:

meson.build +3 -0
index 98e68ef0b1..9fc4c7ac9d 100644
@@ -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(-)
Signature · 1 line
2.41.0