[PATCH 0/5] Clean up header guards again

Markus Armbruster posted 5 patches 2 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260119100537.463312-1-armbru@redhat.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, "Daniel P. Berrangé" <berrange@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Eduardo Habkost <eduardo@habkost.net>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Jason Wang <jasowang@redhat.com>, Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, "Alex Bennée" <alex.bennee@linaro.org>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Samuel Tardieu <sam@rfc1149.net>, Gerd Hoffmann <kraxel@redhat.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Ninad Palsule <ninad@linux.ibm.com>, "Cédric Le Goater" <clg@kaod.org>, Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Beniamino Galvani <b.galvani@gmail.com>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Francisco Iglesias <francisco.iglesias@amd.com>, Vikram Garhwal <vikram.garhwal@bytedance.com>, Bernhard Beschow <shentey@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Aditya Gupta <adityag@linux.ibm.com>, Glenn Miles <milesg@linux.ibm.com>, Stefano Garzarella <sgarzare@redhat.com>, Viresh Kumar <viresh.kumar@linaro.org>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, Paul Durrant <paul@xen.org>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Hyman Huang <yong.huang@smartx.com>, Peter Xu <peterx@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Kostiantyn Kostiuk <kkostiuk@redhat.com>, Alessandro Di Federico <ale@rev.ng>, Anton Johansson <anjo@rev.ng>, Zhao Liu <zhao1.liu@intel.com>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Wei Liu <wei.liu@kernel.org>, David Woodhouse <dwmw2@infradead.org>, Marcelo Tosatti <mtosatti@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Max Filippov <jcmvbkbc@gmail.com>
accel/accel-internal.h                      | 2 +-
accel/tcg/tb-internal.h                     | 4 ++--
backends/tpm/tpm_ioctl.h                    | 7 ++++---
bsd-user/bsd-proc.h                         | 6 +++---
crypto/akcipherpriv.h                       | 2 +-
crypto/der.h                                | 2 +-
crypto/tlscredsbox.h                        | 6 +++---
hw/i386/tdvf-hob.h                          | 4 ++--
hw/net/e1000x_regs.h                        | 2 +-
hw/net/igb_regs.h                           | 4 ++--
hw/riscv/riscv-iommu-bits.h                 | 2 +-
hw/riscv/riscv-iommu.h                      | 4 ++--
include/accel/accel-cpu-target.h            | 2 +-
include/exec/page-protection.h              | 5 +++--
include/exec/replay-core.h                  | 4 ++--
include/exec/target_long.h                  | 6 +++---
include/exec/tb-flush.h                     | 7 ++++---
include/exec/tlb-common.h                   | 3 ++-
include/exec/tswap.h                        | 2 +-
include/gdbstub/helpers.h                   | 6 +++---
include/gdbstub/syscalls.h                  | 6 +++---
include/hw/acpi/ich9_tco.h                  | 6 +++---
include/hw/arm/raspberrypi-fw-defs.h        | 7 +++----
include/hw/arm/stm32l4x5_soc.h              | 4 ++--
include/hw/audio/virtio-snd.h               | 4 ++--
include/hw/char/max78000_uart.h             | 2 +-
include/hw/core/hw-error.h                  | 4 ++--
include/hw/core/qdev.h                      | 4 ++--
include/hw/core/sysemu-cpu-ops.h            | 6 +++---
include/hw/fsi/fsi-master.h                 | 3 ++-
include/hw/gpio/pcf8574.h                   | 6 +++---
include/hw/intc/loongarch_extioi_common.h   | 2 +-
include/hw/intc/loongarch_pic_common.h      | 2 +-
include/hw/loongarch/virt.h                 | 4 ++--
include/hw/misc/allwinner-a10-ccm.h         | 2 +-
include/hw/misc/sifive_e_aon.h              | 4 ++--
include/hw/misc/xlnx-cfi-if.h               | 3 ++-
include/hw/misc/xlnx-versal-cfu.h           | 5 +++--
include/hw/net/xlnx-versal-canfd.h          | 4 ++--
include/hw/pci-bridge/cxl_upstream_port.h   | 7 ++++---
include/hw/pci-host/fsl_imx8m_phy.h         | 4 ++--
include/hw/ppc/pnv_n1_chiplet.h             | 2 +-
include/hw/ppc/pnv_nest_pervasive.h         | 6 +++---
include/hw/ssi/pnv_spi_regs.h               | 4 ++--
include/hw/virtio/vdpa-dev.h                | 5 +++--
include/hw/virtio/vhost-user-gpio.h         | 6 +++---
include/hw/virtio/vhost-user-scmi.h         | 6 +++---
include/hw/xen/xen-pvh-common.h             | 4 ++--
include/io/channel-null.h                   | 4 ++--
include/qapi/qmp-registry.h                 | 4 ++--
include/qemu/mem-reentrancy.h               | 2 +-
include/qemu/target-info-qapi.h             | 4 ++--
include/semihosting/uaccess.h               | 2 +-
include/system/cpu-timers-internal.h        | 6 +++---
include/system/dirtylimit.h                 | 5 +++--
include/system/ioport.h                     | 2 +-
include/system/spdm-socket.h                | 4 ++--
include/tcg/insn-start-words.h              | 6 +++---
include/tcg/tcg-temp-internal.h             | 2 +-
include/user/tswap-target.h                 | 5 +++--
qga/cutils.h                                | 6 +++---
target/arm/cpu-features.h                   | 4 ++--
target/arm/tcg/mte_helper.h                 | 6 +++---
target/hexagon/idef-parser/parser-helpers.h | 2 +-
target/i386/confidential-guest.h            | 5 +++--
target/i386/emulate/x86.h                   | 4 ++--
target/i386/emulate/x86_decode.h            | 4 ++--
target/i386/emulate/x86_flags.h             | 6 +++---
target/i386/kvm/xen-compat.h                | 2 +-
target/loongarch/cpu-mmu.h                  | 2 +-
target/loongarch/tcg/tcg_loongarch.h        | 4 +++-
target/riscv/cpu_vendorid.h                 | 2 +-
target/sparc/translate.h                    | 5 +++--
target/xtensa/core-lx106/core-isa.h         | 7 +++----
scripts/clean-header-guards.pl              | 5 +++--
75 files changed, 163 insertions(+), 149 deletions(-)
[PATCH 0/5] Clean up header guards again
Posted by Markus Armbruster 2 weeks, 4 days ago
Our use of header guards is rather sloppy.  Sloppiness there can lead
to confusing compilation errors.  This series cleans up existing
header guards.  In particular, it normalizes guard symbols to follow a
common pattern, in the hope of making clashes less likely.  It doesn't
add new header guards.  We have more than 300 headers without a
recognizable header guard.  A few of them are for multiple inclusion,
many don't need header guards because they don't do anything but
include, but quite a few probably should have one.  Left for another
day.

Previously cleaned up in merge commit ec11dc41eec (2022), merge commit
01807c8b0e9 (2019), and merge commit ca3d87d4c84 (2016).

Markus Armbruster (5):
  scripts/clean-header-guards: Update exclusions
  Clean up header guards that don't match their file name
  Clean up ill-advised or unusual header guards
  Normalize header guard symbol definition
  Clean up decorations and whitespace around header guards

 accel/accel-internal.h                      | 2 +-
 accel/tcg/tb-internal.h                     | 4 ++--
 backends/tpm/tpm_ioctl.h                    | 7 ++++---
 bsd-user/bsd-proc.h                         | 6 +++---
 crypto/akcipherpriv.h                       | 2 +-
 crypto/der.h                                | 2 +-
 crypto/tlscredsbox.h                        | 6 +++---
 hw/i386/tdvf-hob.h                          | 4 ++--
 hw/net/e1000x_regs.h                        | 2 +-
 hw/net/igb_regs.h                           | 4 ++--
 hw/riscv/riscv-iommu-bits.h                 | 2 +-
 hw/riscv/riscv-iommu.h                      | 4 ++--
 include/accel/accel-cpu-target.h            | 2 +-
 include/exec/page-protection.h              | 5 +++--
 include/exec/replay-core.h                  | 4 ++--
 include/exec/target_long.h                  | 6 +++---
 include/exec/tb-flush.h                     | 7 ++++---
 include/exec/tlb-common.h                   | 3 ++-
 include/exec/tswap.h                        | 2 +-
 include/gdbstub/helpers.h                   | 6 +++---
 include/gdbstub/syscalls.h                  | 6 +++---
 include/hw/acpi/ich9_tco.h                  | 6 +++---
 include/hw/arm/raspberrypi-fw-defs.h        | 7 +++----
 include/hw/arm/stm32l4x5_soc.h              | 4 ++--
 include/hw/audio/virtio-snd.h               | 4 ++--
 include/hw/char/max78000_uart.h             | 2 +-
 include/hw/core/hw-error.h                  | 4 ++--
 include/hw/core/qdev.h                      | 4 ++--
 include/hw/core/sysemu-cpu-ops.h            | 6 +++---
 include/hw/fsi/fsi-master.h                 | 3 ++-
 include/hw/gpio/pcf8574.h                   | 6 +++---
 include/hw/intc/loongarch_extioi_common.h   | 2 +-
 include/hw/intc/loongarch_pic_common.h      | 2 +-
 include/hw/loongarch/virt.h                 | 4 ++--
 include/hw/misc/allwinner-a10-ccm.h         | 2 +-
 include/hw/misc/sifive_e_aon.h              | 4 ++--
 include/hw/misc/xlnx-cfi-if.h               | 3 ++-
 include/hw/misc/xlnx-versal-cfu.h           | 5 +++--
 include/hw/net/xlnx-versal-canfd.h          | 4 ++--
 include/hw/pci-bridge/cxl_upstream_port.h   | 7 ++++---
 include/hw/pci-host/fsl_imx8m_phy.h         | 4 ++--
 include/hw/ppc/pnv_n1_chiplet.h             | 2 +-
 include/hw/ppc/pnv_nest_pervasive.h         | 6 +++---
 include/hw/ssi/pnv_spi_regs.h               | 4 ++--
 include/hw/virtio/vdpa-dev.h                | 5 +++--
 include/hw/virtio/vhost-user-gpio.h         | 6 +++---
 include/hw/virtio/vhost-user-scmi.h         | 6 +++---
 include/hw/xen/xen-pvh-common.h             | 4 ++--
 include/io/channel-null.h                   | 4 ++--
 include/qapi/qmp-registry.h                 | 4 ++--
 include/qemu/mem-reentrancy.h               | 2 +-
 include/qemu/target-info-qapi.h             | 4 ++--
 include/semihosting/uaccess.h               | 2 +-
 include/system/cpu-timers-internal.h        | 6 +++---
 include/system/dirtylimit.h                 | 5 +++--
 include/system/ioport.h                     | 2 +-
 include/system/spdm-socket.h                | 4 ++--
 include/tcg/insn-start-words.h              | 6 +++---
 include/tcg/tcg-temp-internal.h             | 2 +-
 include/user/tswap-target.h                 | 5 +++--
 qga/cutils.h                                | 6 +++---
 target/arm/cpu-features.h                   | 4 ++--
 target/arm/tcg/mte_helper.h                 | 6 +++---
 target/hexagon/idef-parser/parser-helpers.h | 2 +-
 target/i386/confidential-guest.h            | 5 +++--
 target/i386/emulate/x86.h                   | 4 ++--
 target/i386/emulate/x86_decode.h            | 4 ++--
 target/i386/emulate/x86_flags.h             | 6 +++---
 target/i386/kvm/xen-compat.h                | 2 +-
 target/loongarch/cpu-mmu.h                  | 2 +-
 target/loongarch/tcg/tcg_loongarch.h        | 4 +++-
 target/riscv/cpu_vendorid.h                 | 2 +-
 target/sparc/translate.h                    | 5 +++--
 target/xtensa/core-lx106/core-isa.h         | 7 +++----
 scripts/clean-header-guards.pl              | 5 +++--
 75 files changed, 163 insertions(+), 149 deletions(-)

-- 
2.52.0
Re: [PATCH 0/5] Clean up header guards again
Posted by Daniel P. Berrangé 2 weeks, 4 days ago
On Mon, Jan 19, 2026 at 11:05:32AM +0100, Markus Armbruster wrote:
> Our use of header guards is rather sloppy.  Sloppiness there can lead
> to confusing compilation errors.  This series cleans up existing
> header guards.  In particular, it normalizes guard symbols to follow a
> common pattern, in the hope of making clashes less likely.  It doesn't
> add new header guards.  We have more than 300 headers without a
> recognizable header guard.  A few of them are for multiple inclusion,
> many don't need header guards because they don't do anything but
> include, but quite a few probably should have one.  Left for another
> day.
> 
> Previously cleaned up in merge commit ec11dc41eec (2022), merge commit
> 01807c8b0e9 (2019), and merge commit ca3d87d4c84 (2016).

No objection to applying these fixups since you've done the work
already.

Based on the repeated cleanups, and your notes above that we still
have many problems though, can I again suggest we just adopt the
GCC/CLang extension of adding

  #pragma once

at the top of every header and burn all the #ifdefs.

It is easy & cheap to verify that it is present on every single .h file,
and there are no style variations to get wrong, or closing statements to
make inconsistent.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|