Skip to contentSkip to conversation

target/i386: Remove compilation errors when -Werror=maybe-uninitialized

PATCH Superseded Eric Auger 6 participants 12 messages Dec 21, 2022 – Dec 22, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH v2 1/1 target/i386: Remove compilation errors when -Werror=maybe-uninitialized

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

   2495 |     d->Q(3) = r3;
        |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
   2494 |     d->Q(2) = r2;
        |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
   2493 |     d->Q(1) = r1;
        |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
   2492 |     d->Q(0) = r0;
        |     ~~~~~~~~^~~~
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")
---
 target/i386/ops_sse.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +2 -2
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
         r0 = s->Q(0);
         r1 = s->Q(1);
         break;
-    case 3:
+    default:
         r0 = s->Q(2);
         r1 = s->Q(3);
         break;
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
         r2 = s->Q(0);
         r3 = s->Q(1);
         break;
-    case 3:
+    default:
         r2 = s->Q(2);
         r3 = s->Q(3);
         break;
Signature · 1 line
2.37.3
Reviewed-by Stefan Weil on v2 1/1
#1 lore raw

Am 21.12.22 um 17:36 schrieb Eric Auger:

Quoted 44 lines

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

    2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
    2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
    2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
    2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")
---
  target/i386/ops_sse.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
          r0 = s->Q(0);
          r1 = s->Q(1);
          break;
-    case 3:
+    default:
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2490

Quoted 8 lines
target/i386/ops_sse.h +1 -1
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
          r2 = s->Q(0);
          r3 = s->Q(1);
          break;
-    case 3:
+    default:
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;

Thank you and merry Christmas!

#2 lore raw
In reply to Eric Auger
Quoted 44 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

    2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
    2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
    2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
    2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")
---
  target/i386/ops_sse.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
          r0 = s->Q(0);
          r1 = s->Q(1);
          break;
-    case 3:
+    default:
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2490

Quoted 8 lines
target/i386/ops_sse.h +1 -1
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
          r2 = s->Q(0);
          r3 = s->Q(1);
          break;
-    case 3:
+    default:
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;

Queued, but this compiler sucks. :)

Paolo

#3 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

With what compiler? Is that a supported one?

Quoted 25 lines
Quoted 25 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
  target/i386/ops_sse.h | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, 
 uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);

          break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, 
 uint32_t order)
           r2 = s->Q(0);
           r3 = s->Q(1);
Quoted 8 lines
Quoted 6 lines
target/i386/ops_sse.h +1 -1
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);

          break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +4 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
         r0 = s->Q(2);
         r1 = s->Q(3);
         break;
+    default:
+        qemu_build_not_reached();
     }
     switch ((order >> 4) & 3) {
     case 0:
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
         r2 = s->Q(2);
         r3 = s->Q(3);
         break;
+    default:
+        qemu_build_not_reached();
     }
     d->Q(0) = r0;
     d->Q(1) = r1;

---

author
#4 lore raw

Hi Philippe,

Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 52 lines
Quoted 26 lines
Quoted 26 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
  target/i386/ops_sse.h | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);

          break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r2 = s->Q(0);
           r3 = s->Q(1);
Quoted 8 lines
Quoted 6 lines
target/i386/ops_sse.h +1 -1
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);

          break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }
      switch ((order >> 4) & 3) {

     case 0:

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, · line 2496

Quoted 7 lines
target/i386/ops_sse.h +2 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

Thanks

Eric

Quoted 4 lines
target/i386/ops_sse.h +0 -0
      d->Q(0) = r0;

     d->Q(1) = r1;
---

#5 lore raw
Quoted 28 lines · Eric Auger

Hi Philippe,

Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

Quoted 2 lines
Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Adding the compiler version in the commit description would help:

--
Using GCC 11.3.1 "cc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)" we get:
--

Quoted 51 lines
Quoted 51 lines
Quoted 25 lines
Quoted 25 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")
---
   target/i386/ops_sse.h | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);

          break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r2 = s->Q(0);
           r3 = s->Q(1);
Quoted 8 lines
Quoted 6 lines
target/i386/ops_sse.h +1 -1
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);

          break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }
      switch ((order >> 4) & 3) {

     case 0:

target/i386/ops_sse.h +0 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2495

Quoted 7 lines
target/i386/ops_sse.h +2 -0
 uint32_t order)
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

Well my compiler (Apple clang version 14.0.0 (clang-1400.0.29.202)) doesn't display the warning, I don't have yours handy to test it :)

#6 lore raw
In reply to Eric Auger
Quoted 82 lines · Eric Auger

Hi Philippe,

Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 52 lines
Quoted 26 lines
Quoted 26 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
  target/i386/ops_sse.h | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);

          break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r2 = s->Q(0);
           r3 = s->Q(1);
Quoted 8 lines
Quoted 6 lines
target/i386/ops_sse.h +1 -1
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);

          break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }
      switch ((order >> 4) & 3) {

     case 0:

target/i386/ops_sse.h +0 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2495

Quoted 7 lines
target/i386/ops_sse.h +2 -0
 uint32_t order)
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

This ultimately expands to assert() and the compiler should see that it terminates the control flow at this point, so shouldn't have a reason to warn.

With regards,
Daniel

Signature · 3 lines
|: 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 :|
author
#7 lore raw

Hi All,

Quoted 87 lines · Daniel P. Berrangé
Quoted 78 lines · Eric Auger

Hi Philippe,

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 49 lines
Quoted 24 lines
Quoted 24 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
  target/i386/ops_sse.h | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);

          break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r2 = s->Q(0);
Quoted 8 lines
Quoted 7 lines
target/i386/ops_sse.h +1 -1
           r3 = s->Q(1);
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);

          break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }
      switch ((order >> 4) & 3) {

     case 0:

target/i386/ops_sse.h +0 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2495

Quoted 7 lines
target/i386/ops_sse.h +2 -0
 uint32_t order)
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

Quoted 3 lines

This ultimately expands to assert() and the compiler should see that it terminates the control flow at this point, so shouldn't have a reason to warn.

OK so with qemu_build_not_reached(); I get

/home/augere/UPSTREAM/qemu/include/qemu/osdep.h:184:35: error: call to ‘qemu_build_not_reached_always’ declared with attribute error: code path is reachable
  184 | #define qemu_build_not_reached()  qemu_build_not_reached_always() |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

However with g_assert_not_reached(), it does not complain and errors are removed. So I will respin with g_assert_not_reached() if nobody advises me against that.

Thanks

Eric

Quoted 4 lines

With regards,
Daniel

#8 lore raw
Quoted 103 lines · Eric Auger

Hi All,

Quoted 87 lines · Daniel P. Berrangé
Quoted 78 lines · Eric Auger

Hi Philippe,

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~
../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 49 lines
Quoted 24 lines
Quoted 24 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")
---
   target/i386/ops_sse.h | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);

          break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
           r2 = s->Q(0);
Quoted 8 lines
Quoted 7 lines
target/i386/ops_sse.h +1 -1
           r3 = s->Q(1);
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);

          break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
          r0 = s->Q(2);
          r1 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }
      switch ((order >> 4) & 3) {

     case 0:

target/i386/ops_sse.h +0 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2495

Quoted 7 lines
target/i386/ops_sse.h +2 -0
 uint32_t order)
          r2 = s->Q(2);
          r3 = s->Q(3);
          break;
+    default:
+        qemu_build_not_reached();
      }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

Quoted 3 lines

This ultimately expands to assert() and the compiler should see that it terminates the control flow at this point, so shouldn't have a reason to warn.

OK so with qemu_build_not_reached(); I get

/home/augere/UPSTREAM/qemu/include/qemu/osdep.h:184:35: error: call to ‘qemu_build_not_reached_always’ declared with attribute error: code path is reachable
  184 | #define qemu_build_not_reached()  qemu_build_not_reached_always() |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 3 lines

However with g_assert_not_reached(), it does not complain and errors are removed. So I will respin with g_assert_not_reached() if nobody advises me against that.

Thank you!

#9 lore raw

Am 22.12.22 um 12:51 schrieb Philippe Mathieu-Daudé:

Quoted 105 lines · Eric Auger
Quoted 104 lines

Hi All,

Quoted 88 lines · Daniel P. Berrangé
Quoted 79 lines · Eric Auger

Hi Philippe,

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
          |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
          |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
          |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
          |     ~~~~~~~~^~~~

Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 49 lines
Quoted 24 lines
Quoted 24 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
   target/i386/ops_sse.h | 4 ++--

   1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
            r0 = s->Q(0);
            r1 = s->Q(1);
            break;
-    case 3:
+    default:
            r0 = s->Q(2);
            r1 = s->Q(3);

           break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
            r2 = s->Q(0);
Quoted 8 lines
Quoted 7 lines
target/i386/ops_sse.h +1 -1
            r3 = s->Q(1);
            break;
-    case 3:
+    default:
            r2 = s->Q(2);
            r3 = s->Q(3);

           break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
           r0 = s->Q(2);
           r1 = s->Q(3);
           break;
+    default:
+        qemu_build_not_reached();
       }
       switch ((order >> 4) & 3) {

      case 0:

target/i386/ops_sse.h +0 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2495

Quoted 7 lines
target/i386/ops_sse.h +2 -0
 uint32_t order)
           r2 = s->Q(2);
           r3 = s->Q(3);
           break;
+    default:
+        qemu_build_not_reached();
       }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

Quoted 3 lines

This ultimately expands to assert() and the compiler should see that it terminates the control flow at this point, so shouldn't have a reason to warn.

OK so with qemu_build_not_reached(); I get

/home/augere/UPSTREAM/qemu/include/qemu/osdep.h:184:35: error: call to ‘qemu_build_not_reached_always’ declared with attribute error: code path is reachable
   184 | #define qemu_build_not_reached() qemu_build_not_reached_always() | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 5 lines
Quoted 3 lines

However with g_assert_not_reached(), it does not complain and errors are removed. So I will respin with g_assert_not_reached() if nobody advises me against that.

Thank you!

As noted by Paolo a better compiler could know that 0, 1, 2 and 3 are the only possible cases. Such a better compiler might complain that an additional default case is never reached. Therefore the proposed code might cause future compiler warnings.

But we could use this code pattern to make the intention of the code clearer:

case 3:
default: /* default case added to help the compiler to avoid warnings */
    ...

Stefan

#10 lore raw
Quoted 113 lines · Stefan Weil

Am 22.12.22 um 12:51 schrieb Philippe Mathieu-Daudé:

Quoted 104 lines · Eric Auger
Quoted 103 lines

Hi All,

Quoted 87 lines · Daniel P. Berrangé
Quoted 78 lines · Eric Auger

Hi Philippe,

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Eric Auger

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
          |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
          |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
          |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
          |     ~~~~~~~~^~~~

Quoted 1 line

With what compiler? Is that a supported one?

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 49 lines
Quoted 24 lines
Quoted 24 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
   target/i386/ops_sse.h | 4 ++--

   1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
            r0 = s->Q(0);
            r1 = s->Q(1);
            break;
-    case 3:
+    default:
            r0 = s->Q(2);
            r1 = s->Q(3);

           break;

target/i386/ops_sse.h +0 -0
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg
 *s, uint32_t order)
            r2 = s->Q(0);
Quoted 8 lines
Quoted 7 lines
target/i386/ops_sse.h +1 -1
            r3 = s->Q(1);
            break;
-    case 3:
+    default:
            r2 = s->Q(2);
            r3 = s->Q(3);

           break;

Queued, but this compiler sucks. :)

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

-- >8 --

target/i386/ops_sse.h +2 -0
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
 uint32_t order)
           r0 = s->Q(2);
           r1 = s->Q(3);
           break;
+    default:
+        qemu_build_not_reached();
       }
       switch ((order >> 4) & 3) {

      case 0:

target/i386/ops_sse.h +0 -0
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s,
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2495

Quoted 7 lines
target/i386/ops_sse.h +2 -0
 uint32_t order)
           r2 = s->Q(2);
           r3 = s->Q(3);
           break;
+    default:
+        qemu_build_not_reached();
       }

I guess this won't fix the fact r0, r1, r2, r3 are not initialized, will it?

Quoted 3 lines

This ultimately expands to assert() and the compiler should see that it terminates the control flow at this point, so shouldn't have a reason to warn.

OK so with qemu_build_not_reached(); I get

/home/augere/UPSTREAM/qemu/include/qemu/osdep.h:184:35: error: call to ‘qemu_build_not_reached_always’ declared with attribute error: code path is reachable
   184 | #define qemu_build_not_reached() qemu_build_not_reached_always() | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 5 lines
Quoted 3 lines

However with g_assert_not_reached(), it does not complain and errors are removed. So I will respin with g_assert_not_reached() if nobody advises me against that.

Thank you!

Quoted 7 lines

As noted by Paolo a better compiler could know that 0, 1, 2 and 3 are the only possible cases. Such a better compiler might complain that an additional default case is never reached. Therefore the proposed code might cause future compiler warnings.

But we could use this code pattern to make the intention of the code clearer:

case 3:
default: /* default case added to help the compiler to avoid warnings */
    ...

I'm fine with that, as long as we don't obfuscate the code for clever compiler's sake. QEMU code base is already complex enough (the devil 😈 is in the details).

#11 lore raw
In reply to Philippe Mathieu-Daudé

Am 22. Dezember 2022 09:01:34 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 59 lines · Paolo Bonzini
Quoted 15 lines · Eric Auger
Quoted 14 lines

To avoid compilation errors when -Werror=maybe-uninitialized is used, replace 'case 3' by 'default'.

Otherwise we get:

../target/i386/ops_sse.h: In function ‘helper_vpermdq_ymm’:
../target/i386/ops_sse.h:2495:13: error: ‘r3’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2495 |     d->Q(3) = r3;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2494:13: error: ‘r2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2494 |     d->Q(2) = r2;
         |     ~~~~~~~~^~~~

Quoted 8 lines
Quoted 8 lines

../target/i386/ops_sse.h:2493:13: error: ‘r1’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2493 |     d->Q(1) = r1;
         |     ~~~~~~~~^~~~ ../target/i386/ops_sse.h:2492:13: error: ‘r0’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2492 |     d->Q(0) = r0;
         |     ~~~~~~~~^~~~

With what compiler? Is that a supported one?

Quoted 23 lines
Quoted 23 lines
Fixes 790684776861 ("target/i386: reimplement 0x0f 0x3a, add AVX")

---
  target/i386/ops_sse.h | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/ops_sse.h +1 -1
index 3cbc36a59d..c442c8c10c 100644
@@ -2466,7 +2466,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
           r0 = s->Q(0);
           r1 = s->Q(1);
           break;
-    case 3:
+    default:
           r0 = s->Q(2);
           r1 = s->Q(3);
           break;
@@ -2484,7 +2484,7 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
           r2 = s->Q(0);
           r3 = s->Q(1);
Quoted 8 lines

target/i386/ops_sse.h void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order) · line 2492

Quoted 6 lines
target/i386/ops_sse.h +1 -1
           break;
-    case 3:
+    default:
           r2 = s->Q(2);
           r3 = s->Q(3);
           break;

Queued, but this compiler sucks. :)

Quoted 2 lines

Can't we simply add a dumb 'default' case? So when reviewing we don't have to evaluate 'default' means 3 here.

I agree. At least it deserves a comment to preserve the original intention.

Best regards,
Bernhard

Quoted 23 lines

-- >8 --

target/i386/ops_sse.h +4 -1
@@ -2470,6 +2470,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
        r0 = s->Q(2);
        r1 = s->Q(3);
        break;
+    default:
+        qemu_build_not_reached();
    }
    switch ((order >> 4) & 3) {
    case 0:
@@ -2488,6 +2490,8 @@ void helper_vpermdq_ymm(Reg *d, Reg *v, Reg *s, uint32_t order)
        r2 = s->Q(2);
        r3 = s->Q(3);
        break;
+    default:
+        qemu_build_not_reached();
    }
    d->Q(0) = r0;
    d->Q(1) = r1;
---