Skip to contentSkip to conversation

linux-user: Fix clang warning for nios2-linux-user code

PATCH Superseded Peter Maydell 3 participants 4 messages Jan 10, 2022 – Jan 11, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Fix clang warning for nios2-linux-user code

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

---
I'm probably going to apply this directly once it's reviewed, because it fixes a build-break on one of my machines.

 linux-user/elfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/elfload.c +1 -1
index 329b2375ef1..2993b01e60c 100644
@@ -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);
     }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Peter Maydell

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.

Quoted 8 lines
Fixes f5ef0e518d0331 ("linux-user/nios2: Map a real kuser page")

---
I'm probably going to apply this directly once it's reviewed, because it fixes a build-break on one of my machines.

linux-user/elfload.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
linux-user/elfload.c +1 -1
index 329b2375ef1..2993b01e60c 100644
@@ -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);
    }
 
Signature · 1 line
2.25.1
#2 lore raw
In reply to Peter Maydell

Le 10/01/2022 à 20:17, Peter Maydell a écrit :

Quoted 33 lines

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

---
I'm probably going to apply this directly once it's reviewed, because it fixes a build-break on one of my machines.

  linux-user/elfload.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/elfload.c +0 -0
index 329b2375ef1..2993b01e60c 100644

linux-user/elfload.c static void pgb_static(const char *image_name, abi_ulong orig_loaddr, · line 2423

Quoted 5 lines
linux-user/elfload.c +1 -1
@@ -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) {

It seems to revert the logic should it be "(LO_COMMPAGE != 0)"?

Thanks,
Laurent

Quoted 3 lines
linux-user/elfload.c +0 -0
          loaddr = MIN(loaddr, LO_COMMPAGE & -align);
      }
 
#3 lore raw
Quoted 30 lines · Laurent Vivier
Quoted 28 lines · Peter Maydell

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

---
I'm probably going to apply this directly once it's reviewed, because it fixes a build-break on one of my machines.

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

linux-user/elfload.c static void pgb_static(const char *image_name, abi_ulong orig_loaddr, · line 2423

Quoted 10 lines
linux-user/elfload.c +1 -1
index 329b2375ef1..2993b01e60c 100644
@@ -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) {

It seems to revert the logic should it be "(LO_COMMPAGE != 0)"?

You're right, it should -- I was too hasty in writing this fix, clearly...

-- PMM