Skip to contentSkip to conversation

spapr: Fix remaining compiler warnings

PATCH Applied Stefan Weil 3 participants 12 messages Jun 24, 2013 – Jul 2, 2013

lore
Share & tools
lore
#0 lore raw

cover spapr: Fix remaining compiler warnings

Hi Alex,

this mini series fixes the remaining compiler warnings in my w32/w64 cross build environment on Debian wheezy.

[PATCH 1/3] spapr: Use named enum for function remove_hpte [PATCH 2/3] spapr: Fix compiler warning for some versions of gcc [PATCH 3/3] spapr: Fix compiler warning for some versions of gcc

The modifications are nearly trivial, but this time it would be better if you could apply them to your patch queue.

Regards
Stefan

#1 lore raw

PATCH 1/3 spapr: Use named enum for function remove_hpte

The function returned a target_ulong which was made from unnamed enum values. The target_ulong was then assigned to an int variable which was used in a switch statement.

Using a named enum in both cases makes reviews easier.

---
 hw/ppc/spapr_hcall.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/ppc/spapr_hcall.c +4 -4
index 8f0b7e8..00f21f5 100644
@@ -121,14 +121,14 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
-enum {
+typedef enum {
     REMOVE_SUCCESS = 0,
     REMOVE_NOT_FOUND = 1,
     REMOVE_PARM = 2,
     REMOVE_HW = 3,
-};
+} RemoveResult;
 
-static target_ulong remove_hpte(CPUPPCState *env, target_ulong ptex,
+static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,
                                 target_ulong avpn,
                                 target_ulong flags,
                                 target_ulong *vp, target_ulong *rp)
@@ -165,7 +165,7 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     target_ulong flags = args[0];
     target_ulong pte_index = args[1];
     target_ulong avpn = args[2];
-    int ret;
+    RemoveResult ret;
 
     ret = remove_hpte(env, pte_index, avpn, flags,
                       &args[0], &args[1]);
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] spapr: Use named enum for function remove_hpte

Quoted 7 lines · Stefan Weil

The function returned a target_ulong which was made from unnamed enum values. The target_ulong was then assigned to an int variable which was used in a switch statement.

Using a named enum in both cases makes reviews easier.

Thanks, applied to ppc-next.

Alex

#3 lore raw

PATCH 2/3 spapr: Fix compiler warning for some versions of gcc (h_remove)

In reply to Stefan Weil

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_hcall.c:188:1: warning:
control reaches end of non-void function [-Wreturn-type]

Replacing the 4th case REMOVE_HW (which is currently unused) by the default case fixes this warning.

The assertion is dead code because all possible cases are handled in the switch statements, so remove it. This avoids future warnings from static code analyzers.

---
 hw/ppc/spapr_hcall.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/ppc/spapr_hcall.c +1 -3
index 00f21f5..d49ce53 100644
@@ -180,11 +180,9 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     case REMOVE_PARM:
         return H_PARAMETER;
 
-    case REMOVE_HW:
+    default: /* REMOVE_HW */
         return H_HARDWARE;
     }
-
-    assert(0);
 }
 
 #define H_BULK_REMOVE_TYPE             0xc000000000000000ULL
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] spapr: Fix compiler warning for some versions of gcc (h_remove)

Il 24/06/2013 19:48, Stefan Weil ha scritto:

Quoted 25 lines

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_hcall.c:188:1: warning:
control reaches end of non-void function [-Wreturn-type]

Replacing the 4th case REMOVE_HW (which is currently unused) by the default case fixes this warning.

The assertion is dead code because all possible cases are handled in the switch statements, so remove it. This avoids future warnings from static code analyzers.

---
 hw/ppc/spapr_hcall.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/ppc/spapr_hcall.c +0 -0
index 00f21f5..d49ce53 100644
@@ -180,11 +180,9 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     case REMOVE_PARM:
         return H_PARAMETER;

hw/ppc/spapr_hcall.c static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 188

Quoted 10 lines
hw/ppc/spapr_hcall.c +1 -3
 
-    case REMOVE_HW:
+    default: /* REMOVE_HW */
         return H_HARDWARE;
     }
-
-    assert(0);
 }
 
 #define H_BULK_REMOVE_TYPE             0xc000000000000000ULL

Does s/assert(0)/abort()/ fix the warning too? That's clearer.

Paolo

#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] spapr: Fix compiler warning for some versions of gcc (h_remove)

Am 24.06.2013 22:27, schrieb Paolo Bonzini:

Quoted 34 lines

Il 24/06/2013 19:48, Stefan Weil ha scritto:

Quoted 33 lines

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_hcall.c:188:1: warning:
control reaches end of non-void function [-Wreturn-type]

Replacing the 4th case REMOVE_HW (which is currently unused) by the default case fixes this warning.

The assertion is dead code because all possible cases are handled in the switch statements, so remove it. This avoids future warnings from static code analyzers.

---
 hw/ppc/spapr_hcall.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/ppc/spapr_hcall.c +1 -3
index 00f21f5..d49ce53 100644
@@ -180,11 +180,9 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     case REMOVE_PARM:
         return H_PARAMETER;
 
-    case REMOVE_HW:
+    default: /* REMOVE_HW */
         return H_HARDWARE;
     }
-
-    assert(0);
 }
 
Quoted 5 lines

hw/ppc/spapr_hcall.c static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 188

Quoted 2 lines
hw/ppc/spapr_hcall.c +0 -0
 #define H_BULK_REMOVE_TYPE             0xc000000000000000ULL

Does s/assert(0)/abort()/ fix the warning too? That's clearer.

Paolo

Yes, that also fixes this warning. A better compiler or a static code checker might then complain about dead code because all possible cases are handled in the switch statement.

Stefan

#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] spapr: Fix compiler warning for some versions of gcc (h_remove)

Il 24/06/2013 22:35, Stefan Weil ha scritto:

Quoted 35 lines

Am 24.06.2013 22:27, schrieb Paolo Bonzini:

Quoted 34 lines

Il 24/06/2013 19:48, Stefan Weil ha scritto:

Quoted 33 lines

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_hcall.c:188:1: warning:
control reaches end of non-void function [-Wreturn-type]

Replacing the 4th case REMOVE_HW (which is currently unused) by the default case fixes this warning.

The assertion is dead code because all possible cases are handled in the switch statements, so remove it. This avoids future warnings from static code analyzers.

---
 hw/ppc/spapr_hcall.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/ppc/spapr_hcall.c +1 -3
index 00f21f5..d49ce53 100644
@@ -180,11 +180,9 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     case REMOVE_PARM:
         return H_PARAMETER;
 
-    case REMOVE_HW:
+    default: /* REMOVE_HW */
         return H_HARDWARE;
     }
-
-    assert(0);
 }
 
Quoted 7 lines
Quoted 3 lines

hw/ppc/spapr_hcall.c static target_ulong h_remove(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 188

Quoted 2 lines
hw/ppc/spapr_hcall.c +0 -0
 #define H_BULK_REMOVE_TYPE             0xc000000000000000ULL

Does s/assert(0)/abort()/ fix the warning too? That's clearer.

Yes, that also fixes this warning. A better compiler or a static code checker might then complain about dead code because all possible cases are handled in the switch statement.

We'll get there when we see it... and such a compiler can well learn to ignore a dead abort().

Paolo

#7 lore raw

PATCH 3/3 spapr: Fix compiler warning for some versions of gcc (spapr_io_read)

In reply to Stefan Weil

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_pci.c:454:1: warning:
control reaches end of non-void function [-Wreturn-type]

Adding a default case to the switch statement satisfies the compiler. This modification requires moving the assert statement.

---
 hw/ppc/spapr_pci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +2 -1
index 04e8362..c04086c 100644
@@ -448,9 +448,10 @@ static uint64_t spapr_io_read(void *opaque, hwaddr addr,
     case 2:
         return cpu_inw(addr);
     case 4:
+    default:
+        assert(size == 4);
         return cpu_inl(addr);
     }
-    assert(0);
 }
 
 static void spapr_io_write(void *opaque, hwaddr addr,
Signature · 1 line
1.7.10.4
#8 lore raw

Re: [Qemu-devel] [PATCH 3/3] spapr: Fix compiler warning for some versions of gcc (spapr_io_read)

Quoted 18 lines · Stefan Weil

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_pci.c:454:1: warning:
control reaches end of non-void function [-Wreturn-type]

Adding a default case to the switch statement satisfies the compiler. This modification requires moving the assert statement.

---
  hw/ppc/spapr_pci.c |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +0 -0
index 04e8362..c04086c 100644

hw/ppc/spapr_pci.c static uint64_t spapr_io_read(void *opaque, hwaddr addr, · line 453

Quoted 6 lines
hw/ppc/spapr_pci.c +2 -0
@@ -448,9 +448,10 @@ static uint64_t spapr_io_read(void *opaque, hwaddr addr,
      case 2:
          return cpu_inw(addr);
      case 4:
+    default:
+        assert(size == 4);
          return cpu_inl(addr);

Please fix this one up with g_assert_not_reached() as well.

Alex

#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] spapr: Fix compiler warning for some versions of gcc (spapr_io_read)

Am 02.07.2013 14:45, schrieb Alexander Graf:

Quoted 30 lines · Stefan Weil
Quoted 19 lines

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_pci.c:454:1: warning:
control reaches end of non-void function [-Wreturn-type]

Adding a default case to the switch statement satisfies the compiler. This modification requires moving the assert statement.

---
  hw/ppc/spapr_pci.c |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +0 -0
index 04e8362..c04086c 100644

hw/ppc/spapr_pci.c static uint64_t spapr_io_read(void *opaque, · line 454

Quoted 7 lines
hw/ppc/spapr_pci.c +2 -0
@@ -448,9 +448,10 @@ static uint64_t spapr_io_read(void *opaque,
 hwaddr addr,
      case 2:
          return cpu_inw(addr);
      case 4:
+    default:
+        assert(size == 4);
          return cpu_inl(addr);

Please fix this one up with g_assert_not_reached() as well.

Quoted 1 line

Alex

I did, and you applied it to ppc-next. :-)

See http://patchwork.ozlabs.org/patch/255738/.

Cheers
Stefan

#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] spapr: Fix compiler warning for some versions of gcc (spapr_io_read)

Am 02.07.2013 um 22:22 schrieb Stefan Weil <[email protected]>:

Quoted 31 lines

Am 02.07.2013 14:45, schrieb Alexander Graf:

Quoted 30 lines · Stefan Weil
Quoted 19 lines

i686-w64-mingw32-gcc (GCC) 4.6.3 from Debian wheezy reports this warning:

hw/ppc/spapr_pci.c:454:1: warning:
control reaches end of non-void function [-Wreturn-type]

Adding a default case to the switch statement satisfies the compiler. This modification requires moving the assert statement.

---
 hw/ppc/spapr_pci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/spapr_pci.c +0 -0
index 04e8362..c04086c 100644

hw/ppc/spapr_pci.c static uint64_t spapr_io_read(void *opaque, · line 454

Quoted 7 lines
hw/ppc/spapr_pci.c +2 -0
@@ -448,9 +448,10 @@ static uint64_t spapr_io_read(void *opaque,
 hwaddr addr,
     case 2:
         return cpu_inw(addr);
     case 4:
+    default:
+        assert(size == 4);
         return cpu_inl(addr);

Please fix this one up with g_assert_not_reached() as well.

Quoted 5 lines
Quoted 1 line

Alex

I did, and you applied it to ppc-next. :-)

See http://patchwork.ozlabs.org/patch/255738/.

Oops, just consider me stupid then :)

Alex

Quoted 4 lines

Cheers
Stefan

#11 lore raw
In reply to Stefan Weil

Il 24/06/2013 19:48, Stefan Weil ha scritto:

Quoted 11 lines

Hi Alex,

this mini series fixes the remaining compiler warnings in my w32/w64 cross build environment on Debian wheezy.

[PATCH 1/3] spapr: Use named enum for function remove_hpte [PATCH 2/3] spapr: Fix compiler warning for some versions of gcc [PATCH 3/3] spapr: Fix compiler warning for some versions of gcc

The modifications are nearly trivial, but this time it would be better if you could apply them to your patch queue.

I think these patches are a bit backwards.

The right fix is just to use abort() instead of assert(0).

Paolo