[PATCH 04/16] compiler.h: add QEMU_{BEGIN, END}_IGNORE_INITIALIZER_OVERRIDES

marcandre.lureau@redhat.com posted 16 patches 3 years, 9 months ago
Maintainers: Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Konstantin Kostiuk <kkostiuk@redhat.com>, Alexander Bulekov <alxndr@bu.edu>, Paolo Bonzini <pbonzini@redhat.com>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Thomas Huth <thuth@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Laurent Vivier <lvivier@redhat.com>, Stefan Weil <sw@weilnetz.de>
There is a newer version of this series
[PATCH 04/16] compiler.h: add QEMU_{BEGIN, END}_IGNORE_INITIALIZER_OVERRIDES
Posted by marcandre.lureau@redhat.com 3 years, 9 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

clang has this default warning which QEMU codes triggers in many
situations. However, other projects in general may not want to disable
globally the warning but only in limited specific code blocks.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu/compiler.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index f20a76e4a286..ea0797959641 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -184,4 +184,15 @@
 #define QEMU_DISABLE_CFI
 #endif
 
+#if defined (__clang__)
+#define QEMU_BEGIN_IGNORE_INITIALIZER_OVERRIDES                     \
+    _Pragma("clang diagnostic push")                                \
+    _Pragma("clang diagnostic ignored \"-Winitializer-overrides\"")
+#define QEMU_END_IGNORE_INITIALIZER_OVERRIDES \
+    _Pragma("clang diagnostic pop")
+#else
+#define QEMU_BEGIN_IGNORE_INITIALIZER_OVERRIDES
+#define QEMU_END_IGNORE_INITIALIZER_OVERRIDES
+#endif
+
 #endif /* COMPILER_H */
-- 
2.36.0.44.g0f828332d5ac


Re: [PATCH 04/16] compiler.h: add QEMU_{BEGIN, END}_IGNORE_INITIALIZER_OVERRIDES
Posted by Peter Maydell 3 years, 9 months ago
On Wed, 4 May 2022 at 18:36, <marcandre.lureau@redhat.com> wrote:
>
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> clang has this default warning which QEMU codes triggers in many
> situations. However, other projects in general may not want to disable
> globally the warning but only in limited specific code blocks.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> +#if defined (__clang__)
> +#define QEMU_BEGIN_IGNORE_INITIALIZER_OVERRIDES                     \
> +    _Pragma("clang diagnostic push")                                \
> +    _Pragma("clang diagnostic ignored \"-Winitializer-overrides\"")
> +#define QEMU_END_IGNORE_INITIALIZER_OVERRIDES \
> +    _Pragma("clang diagnostic pop")
> +#else
> +#define QEMU_BEGIN_IGNORE_INITIALIZER_OVERRIDES
> +#define QEMU_END_IGNORE_INITIALIZER_OVERRIDES
> +#endif

We use pragma diagnostic controls generally sparingly and
only when we need to briefly disable an otherwise widely
useful warning. In this case the clang warning is just
broken (because it doesn't correctly handle the array
range initializer extension we use), and so we turn off
the warning altogether in configure, so that we get the
behaviour we want everywhere in the source tree, not just
if we mark it up with special macros.

If other projects want to borrow bits of QEMU code then
they need to either (a) abide by our conventions for
what compiler warnings to enable or disable, or else
(b) fork the code and fiddle with their own copy.

I don't really want to see QEMU's source code get littered
with a pile of extra macros hiding diagnostic pragmas.
(If we stop passing -Wno-initializer-overrides to the
compiler then we set a bunch of new "built on gcc on the
developer's machine but fails to build on clang in the
CI jobs" traps for ourselves, and if we don't stop passing
that then the places that should be marked up with the
macros won't reliably be marked up.)

thanks
-- PMM
Re: [PATCH 04/16] compiler.h: add QEMU_{BEGIN, END}_IGNORE_INITIALIZER_OVERRIDES
Posted by Paolo Bonzini 3 years, 9 months ago


>If other projects want to borrow bits of QEMU code then
>they need to either (a) abide by our conventions for
>what compiler warnings to enable or disable, or else
>(b) fork the code and fiddle with their own copy.

Agreed, it's not a huge deal if a single add_project_arguments call is duplicated across a couple meson subprojects.

Paolo

>
>I don't really want to see QEMU's source code get littered
>with a pile of extra macros hiding diagnostic pragmas.
>(If we stop passing -Wno-initializer-overrides to the
>compiler then we set a bunch of new "built on gcc on the
>developer's machine but fails to build on clang in the
>CI jobs" traps for ourselves, and if we don't stop passing
>that then the places that should be marked up with the
>macros won't reliably be marked up.)
>
>thanks
>-- PMM
>