All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] linux-user: Fix clang warning for nios2-linux-user code
@ 2022-01-11  8:29 Peter Maydell
  2022-01-11  9:00 ` Laurent Vivier
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2022-01-11  8:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier, Warner Losh

The clang in Ubuntu 18.04 (10.0.0-4ubuntu1) produces a warning
on the code added in commit f5ef0e518d03 where we use a
shifted expression in a boolean context:

../../linux-user/elfload.c:2423:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
    } else if (LO_COMMPAGE) {
               ^
../../linux-user/elfload.c:1102:22: note: expanded from macro 'LO_COMMPAGE'
#define LO_COMMPAGE  TARGET_PAGE_SIZE
                     ^
/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/cpu-all.h:231:31: note: expanded from macro 'TARGET_PAGE_SIZE'
#define TARGET_PAGE_SIZE   (1 << TARGET_PAGE_BITS)
                              ^
1 error generated.

The warning is bogus because whether LO_COMMPAGE is zero or not
depends on compile-time ifdefs; shut the compiler up by adding
an explicit comparison to zero.

Fixes: f5ef0e518d0331 ("linux-user/nios2: Map a real kuser page")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
v1->v2: fix sense of comparison (oops!)

 linux-user/elfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 329b2375ef1..d3274edfdb7 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2420,7 +2420,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
         } else {
             offset = -(HI_COMMPAGE & -align);
         }
-    } else if (LO_COMMPAGE) {
+    } else if (LO_COMMPAGE != 0) {
         loaddr = MIN(loaddr, LO_COMMPAGE & -align);
     }
 
-- 
2.25.1



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

* Re: [PATCH v2] linux-user: Fix clang warning for nios2-linux-user code
  2022-01-11  8:29 [PATCH v2] linux-user: Fix clang warning for nios2-linux-user code Peter Maydell
@ 2022-01-11  9:00 ` Laurent Vivier
  2022-01-12 11:47   ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Vivier @ 2022-01-11  9:00 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Richard Henderson, Warner Losh

Le 11/01/2022 à 09:29, Peter Maydell a écrit :
> The clang in Ubuntu 18.04 (10.0.0-4ubuntu1) produces a warning
> on the code added in commit f5ef0e518d03 where we use a
> shifted expression in a boolean context:
> 
> ../../linux-user/elfload.c:2423:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
>      } else if (LO_COMMPAGE) {
>                 ^
> ../../linux-user/elfload.c:1102:22: note: expanded from macro 'LO_COMMPAGE'
> #define LO_COMMPAGE  TARGET_PAGE_SIZE
>                       ^
> /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/cpu-all.h:231:31: note: expanded from macro 'TARGET_PAGE_SIZE'
> #define TARGET_PAGE_SIZE   (1 << TARGET_PAGE_BITS)
>                                ^
> 1 error generated.
> 
> The warning is bogus because whether LO_COMMPAGE is zero or not
> depends on compile-time ifdefs; shut the compiler up by adding
> an explicit comparison to zero.
> 
> Fixes: f5ef0e518d0331 ("linux-user/nios2: Map a real kuser page")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> v1->v2: fix sense of comparison (oops!)
> 
>   linux-user/elfload.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 329b2375ef1..d3274edfdb7 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2420,7 +2420,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
>           } else {
>               offset = -(HI_COMMPAGE & -align);
>           }
> -    } else if (LO_COMMPAGE) {
> +    } else if (LO_COMMPAGE != 0) {
>           loaddr = MIN(loaddr, LO_COMMPAGE & -align);
>       }
>   

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


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

* Re: [PATCH v2] linux-user: Fix clang warning for nios2-linux-user code
  2022-01-11  9:00 ` Laurent Vivier
@ 2022-01-12 11:47   ` Peter Maydell
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2022-01-12 11:47 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Richard Henderson, qemu-devel, Warner Losh

On Tue, 11 Jan 2022 at 09:00, Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 11/01/2022 à 09:29, Peter Maydell a écrit :
> > The clang in Ubuntu 18.04 (10.0.0-4ubuntu1) produces a warning
> > on the code added in commit f5ef0e518d03 where we use a
> > shifted expression in a boolean context:
> >
> > ../../linux-user/elfload.c:2423:16: error: converting the result of '<<' to a boolean always evaluates to true [-Werror,-Wtautological-constant-compare]
> >      } else if (LO_COMMPAGE) {
> >                 ^
> > ../../linux-user/elfload.c:1102:22: note: expanded from macro 'LO_COMMPAGE'
> > #define LO_COMMPAGE  TARGET_PAGE_SIZE
> >                       ^
> > /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/exec/cpu-all.h:231:31: note: expanded from macro 'TARGET_PAGE_SIZE'
> > #define TARGET_PAGE_SIZE   (1 << TARGET_PAGE_BITS)
> >                                ^
> > 1 error generated.
> >
> > The warning is bogus because whether LO_COMMPAGE is zero or not
> > depends on compile-time ifdefs; shut the compiler up by adding
> > an explicit comparison to zero.
> >
> > Fixes: f5ef0e518d0331 ("linux-user/nios2: Map a real kuser page")
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > ---
> > v1->v2: fix sense of comparison (oops!)
> >
> >   linux-user/elfload.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> > index 329b2375ef1..d3274edfdb7 100644
> > --- a/linux-user/elfload.c
> > +++ b/linux-user/elfload.c
> > @@ -2420,7 +2420,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr,
> >           } else {
> >               offset = -(HI_COMMPAGE & -align);
> >           }
> > -    } else if (LO_COMMPAGE) {
> > +    } else if (LO_COMMPAGE != 0) {
> >           loaddr = MIN(loaddr, LO_COMMPAGE & -align);
> >       }
> >
>
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>

Thanks; applied to master as a build fix.

-- PMM


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

end of thread, other threads:[~2022-01-12 12:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11  8:29 [PATCH v2] linux-user: Fix clang warning for nios2-linux-user code Peter Maydell
2022-01-11  9:00 ` Laurent Vivier
2022-01-12 11:47   ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.