qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user: avoid -Werror=int-in-bool-context
@ 2025-09-19  8:36 Paolo Bonzini
  2025-09-19  9:31 ` Daniel P. Berrangé
  2025-09-19  9:33 ` Peter Maydell
  0 siblings, 2 replies; 5+ messages in thread
From: Paolo Bonzini @ 2025-09-19  8:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-stable, Richard Henderson

linux-user is failing to compile on Fedora 43:

../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
   57 | #define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }

The warning does not seem to useful and we could even disable it, but
the workaround is simple in this case.

Cc: qemu-stable@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 linux-user/strace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 1233ebceb08..758c5d32b6c 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -54,7 +54,7 @@ struct flags {
 };
 
 /* No 'struct flags' element should have a zero mask. */
-#define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
+#define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO((M) == 0), N }
 
 /* common flags for all architectures */
 #define FLAG_GENERIC_MASK(V, M)  FLAG_BASIC(V, M, #V)
-- 
2.51.0



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

* Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
  2025-09-19  8:36 [PATCH] linux-user: avoid -Werror=int-in-bool-context Paolo Bonzini
@ 2025-09-19  9:31 ` Daniel P. Berrangé
  2025-09-19  9:33 ` Peter Maydell
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel P. Berrangé @ 2025-09-19  9:31 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, qemu-stable, Richard Henderson

On Fri, Sep 19, 2025 at 10:36:12AM +0200, Paolo Bonzini wrote:
> linux-user is failing to compile on Fedora 43:
> 
> ../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
>    57 | #define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
> 
> The warning does not seem to useful and we could even disable it, but
> the workaround is simple in this case.
> 
> Cc: qemu-stable@nongnu.org
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  linux-user/strace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


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 :|



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

* Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
  2025-09-19  8:36 [PATCH] linux-user: avoid -Werror=int-in-bool-context Paolo Bonzini
  2025-09-19  9:31 ` Daniel P. Berrangé
@ 2025-09-19  9:33 ` Peter Maydell
  2025-09-19  9:45   ` Markus Armbruster
  2025-09-19  9:45   ` Paolo Bonzini
  1 sibling, 2 replies; 5+ messages in thread
From: Peter Maydell @ 2025-09-19  9:33 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, qemu-stable, Richard Henderson

On Fri, 19 Sept 2025 at 09:37, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> linux-user is failing to compile on Fedora 43:
>
> ../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
>    57 | #define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
>
> The warning does not seem to useful and we could even disable it, but
> the workaround is simple in this case.

I'm surprised this is the only place in the codebase
where we treat an int as a bool...

-- PMM


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

* Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
  2025-09-19  9:33 ` Peter Maydell
@ 2025-09-19  9:45   ` Markus Armbruster
  2025-09-19  9:45   ` Paolo Bonzini
  1 sibling, 0 replies; 5+ messages in thread
From: Markus Armbruster @ 2025-09-19  9:45 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Paolo Bonzini, qemu-devel, qemu-stable, Richard Henderson

Peter Maydell <peter.maydell@linaro.org> writes:

> On Fri, 19 Sept 2025 at 09:37, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> linux-user is failing to compile on Fedora 43:
>>
>> ../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
>>    57 | #define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
>>
>> The warning does not seem to useful and we could even disable it, but
>> the workaround is simple in this case.
>
> I'm surprised this is the only place in the codebase
> where we treat an int as a bool...

It definitely isn't.  Idiomatic C...



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

* Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
  2025-09-19  9:33 ` Peter Maydell
  2025-09-19  9:45   ` Markus Armbruster
@ 2025-09-19  9:45   ` Paolo Bonzini
  1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2025-09-19  9:45 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, qemu-stable, Richard Henderson

On 9/19/25 11:33, Peter Maydell wrote:
> On Fri, 19 Sept 2025 at 09:37, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> linux-user is failing to compile on Fedora 43:
>>
>> ../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
>>     57 | #define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
>>
>> The warning does not seem to useful and we could even disable it, but
>> the workaround is simple in this case.
> 
> I'm surprised this is the only place in the codebase
> where we treat an int as a bool...
There are some heuristics about suspicious uses.  Examples in the 
documentation include "if (a <= b ? 2 : 3)" and "1 << a" in boolean context.

Paolo



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

end of thread, other threads:[~2025-09-19  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-19  8:36 [PATCH] linux-user: avoid -Werror=int-in-bool-context Paolo Bonzini
2025-09-19  9:31 ` Daniel P. Berrangé
2025-09-19  9:33 ` Peter Maydell
2025-09-19  9:45   ` Markus Armbruster
2025-09-19  9:45   ` Paolo Bonzini

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