[PATCH] linux-user: avoid -Werror=int-in-bool-context

Paolo Bonzini posted 1 patch 1 month, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250919083612.86546-1-pbonzini@redhat.com
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/strace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] linux-user: avoid -Werror=int-in-bool-context
Posted by Paolo Bonzini 1 month, 3 weeks ago
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
Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
Posted by Peter Maydell 1 month, 3 weeks ago
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
Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
Posted by Paolo Bonzini 1 month, 3 weeks ago
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
Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
Posted by Markus Armbruster 1 month, 3 weeks ago
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...
Re: [PATCH] linux-user: avoid -Werror=int-in-bool-context
Posted by Daniel P. Berrangé 1 month, 3 weeks ago
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 :|