Skip to contentSkip to conversation

Fix more GCC9 -O3 warnings

PATCH Superseded Philippe Mathieu-Daudé 7 participants 27 messages Dec 17, 2019 – Jan 7, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix more GCC9 -O3 warnings

Fix some trivial warnings when building with -O3.

Philippe Mathieu-Daudé (6):
audio/audio: Add missing fall through comment hw/display/tcx: Add missing fall through comments hw/net/imx_fec: Rewrite fall through comments hw/timer/aspeed_timer: Add a fall through comment hw/scsi/megasas: Silent GCC9 duplicated-cond warning
qemu-io-cmds: Silent GCC9 format-overflow warning

 audio/audio.c           | 1 +
 hw/display/tcx.c        | 2 ++
 hw/net/imx_fec.c        | 8 +++++---
 hw/scsi/megasas.c       | 3 ++-
 hw/timer/aspeed_timer.c | 2 +-
 qemu-io-cmds.c          | 1 +
 6 files changed, 12 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/6 audio/audio: Add missing fall through comment

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

audio/audio.c: In function ‘audio_pcm_init_info’:
audio/audio.c:306:14: error: this statement may fall through [-Werror=implicit-fallthrough=]

    306 |         sign = 1;
        |         ~~~~~^~~
  audio/audio.c:307:5: note: here
    307 |     case AUDIO_FORMAT_U8:
        |     ^~~~

cc1: all warnings being treated as errors

Add the missing fall through comment, similarly to e46349414.

Fixes 2b9cce8c8c

---
Cc: Gerd Hoffmann <[email protected]>
Cc: "Kővágó, Zoltán" <[email protected]>

---
 audio/audio.c | 1 +
 1 file changed, 1 insertion(+)
audio/audio.c +1 -0
index 56fae55047..57daf3f620 100644
@@ -304,6 +304,7 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
     switch (as->fmt) {
     case AUDIO_FORMAT_S8:
         sign = 1;
+        /* fall through */
     case AUDIO_FORMAT_U8:
         mul = 1;
         break;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] audio/audio: Add missing fall through comment

Quoted 13 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

audio/audio.c: In function ‘audio_pcm_init_info’:
audio/audio.c:306:14: error: this statement may fall through [-Werror=implicit-fallthrough=]

    306 |         sign = 1;
        |         ~~~~~^~~
  audio/audio.c:307:5: note: here
    307 |     case AUDIO_FORMAT_U8:
        |     ^~~~

cc1: all warnings being treated as errors

Add the missing fall through comment, similarly to e46349414.

...

audio/audio.c void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as) · line 310

Quoted 12 lines
audio/audio.c +1 -0
index 56fae55047..57daf3f620 100644
@@ -304,6 +304,7 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
     switch (as->fmt) {
     case AUDIO_FORMAT_S8:
         sign = 1;
+        /* fall through */
     case AUDIO_FORMAT_U8:
         mul = 1;
         break;

r~

#3 lore raw

Re: [PATCH 1/6] audio/audio: Add missing fall through comment

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

Gcc is not confused whatsoever.

Quoted 39 lines

audio/audio.c: In function ‘audio_pcm_init_info’:
audio/audio.c:306:14: error: this statement may fall through
[-Werror=implicit-fallthrough=]

    306 |         sign = 1;
        |         ~~~~~^~~
  audio/audio.c:307:5: note: here
    307 |     case AUDIO_FORMAT_U8:
        |     ^~~~

cc1: all warnings being treated as errors

Add the missing fall through comment, similarly to e46349414.

Fixes 2b9cce8c8c

---
Cc: Gerd Hoffmann <[email protected]>
Cc: "Kővágó, Zoltán" <[email protected]>

---
 audio/audio.c | 1 +
 1 file changed, 1 insertion(+)
audio/audio.c +1 -0
index 56fae55047..57daf3f620 100644
@@ -304,6 +304,7 @@ void audio_pcm_init_info (struct audio_pcm_info *info,
 struct audsettings *as)
     switch (as->fmt) {
     case AUDIO_FORMAT_S8:
         sign = 1;
+        /* fall through */
     case AUDIO_FORMAT_U8:
         mul = 1;
         break;

--
2.21.0

#4 lore raw

Re: [PATCH 1/6] audio/audio: Add missing fall through comment

Quoted 9 lines · Aleksandar Markovic

On Tuesday, December 17, 2019, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

Gcc is not confused whatsoever.

It is right! I'll update the description :)

Quoted 41 lines
       audio/audio.c: In function ‘audio_pcm_init_info’:
       audio/audio.c:306:14: error: this statement may fall through
    [-Werror=implicit-fallthrough=]
         306 |         sign = 1;
             |         ~~~~~^~~
       audio/audio.c:307:5: note: here
         307 |     case AUDIO_FORMAT_U8:
             |     ^~~~
       cc1: all warnings being treated as errors

    Add the missing fall through comment, similarly to e46349414.

    Fixes: 2b9cce8c8c
    Signed-off-by: Philippe Mathieu-Daudé <[email protected]
    <mailto:[email protected]>>
    ---
    Cc: Gerd Hoffmann <[email protected] <mailto:[email protected]>>
    Cc: "Kővágó, Zoltán" <[email protected]
    <mailto:[email protected]>>
    ---
      audio/audio.c | 1 +
      1 file changed, 1 insertion(+)

    diff --git a/audio/audio.c b/audio/audio.c
    index 56fae55047..57daf3f620 100644
    --- a/audio/audio.c
    +++ b/audio/audio.c
    @@ -304,6 +304,7 @@ void audio_pcm_init_info (struct audio_pcm_info
    *info, struct audsettings *as)
          switch (as->fmt) {
          case AUDIO_FORMAT_S8:
              sign = 1;
    +        /* fall through */
          case AUDIO_FORMAT_U8:
              mul = 1;
              break;
    -- 
    2.21.0
#5 lore raw

PATCH 2/6 hw/display/tcx: Add missing fall through comments

In reply to Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/display/tcx.c: In function ‘tcx_dac_writel’:
hw/display/tcx.c:453:26: error: this statement may fall through [-Werror=implicit-fallthrough=]

    453 |             s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
        |             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/display/tcx.c:454:9: note: here
    454 |         default:
        |         ^~~~~~~
  hw/display/tcx.c: In function ‘tcx_dac_readl’:
  hw/display/tcx.c:412:22: error: this statement may fall through [-Werror=implicit-fallthrough=]
    412 |         s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
        |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/display/tcx.c:413:5: note: here
    413 |     default:
        |     ^~~~~~~

cc1: all warnings being treated as errors

Add the missing fall through comments.

---
Cc: Olivier Danet <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>

---
 hw/display/tcx.c | 2 ++
 1 file changed, 2 insertions(+)
hw/display/tcx.c +2 -0
index 14e829d3fa..abbeb30284 100644
@@ -410,6 +410,7 @@ static uint64_t tcx_dac_readl(void *opaque, hwaddr addr,
     case 2:
         val = s->b[s->dac_index] << 24;
         s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
+        /* fall through */
     default:
         s->dac_state = 0;
         break;
@@ -451,6 +452,7 @@ static void tcx_dac_writel(void *opaque, hwaddr addr, uint64_t val,
             s->b[index] = val >> 24;
             update_palette_entries(s, index, index + 1);
             s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
+            /* fall through */
         default:
             s->dac_state = 0;
             break;
Signature · 1 line
2.21.0
Reviewed-by on v1 2/6
#6 lore raw

Re: [PATCH 2/6] hw/display/tcx: Add missing fall through comments

Quoted 21 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/display/tcx.c: In function ‘tcx_dac_writel’:
hw/display/tcx.c:453:26: error: this statement may fall through [-Werror=implicit-fallthrough=]

    453 |             s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
        |             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/display/tcx.c:454:9: note: here
    454 |         default:
        |         ^~~~~~~
  hw/display/tcx.c: In function ‘tcx_dac_readl’:
  hw/display/tcx.c:412:22: error: this statement may fall through [-Werror=implicit-fallthrough=]
    412 |         s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement */
        |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/display/tcx.c:413:5: note: here
    413 |     default:
        |     ^~~~~~~

cc1: all warnings being treated as errors

Add the missing fall through comments.

Quoted 8 lines

---
Cc: Olivier Danet <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>

---
 hw/display/tcx.c | 2 ++
 1 file changed, 2 insertions(+)

r~

#7 lore raw

Re: [PATCH 2/6] hw/display/tcx: Add missing fall through comments

In reply to Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/display/tcx.c: In function ‘tcx_dac_writel’:
hw/display/tcx.c:453:26: error: this statement may fall through
[-Werror=implicit-fallthrough=]

    453 |             s->dac_index = (s->dac_index + 1) & 0xff; /* Index
autoincrement */
        |             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/display/tcx.c:454:9: note: here
    454 |         default:
        |         ^~~~~~~
  hw/display/tcx.c: In function ‘tcx_dac_readl’:
  hw/display/tcx.c:412:22: error: this statement may fall through
[-Werror=implicit-fallthrough=]
    412 |         s->dac_index = (s->dac_index + 1) & 0xff; /* Index
autoincrement */
        |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/display/tcx.c:413:5: note: here
    413 |     default:
        |     ^~~~~~~

cc1: all warnings being treated as errors

Add the missing fall through comments.

Quoted 10 lines

---
Cc: Olivier Danet <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>

---
 hw/display/tcx.c | 2 ++
 1 file changed, 2 insertions(+)

The content of the patch is fine, but the commit message is, I think,
inacurate: gcc is not confused at all, it does what it was told to.

The title is fine.

Quoted 29 lines
hw/display/tcx.c +1 -0
index 14e829d3fa..abbeb30284 100644
@@ -410,6 +410,7 @@ static uint64_t tcx_dac_readl(void *opaque, hwaddr
 addr,
     case 2:
         val = s->b[s->dac_index] << 24;
         s->dac_index = (s->dac_index + 1) & 0xff; /* Index autoincrement
 */
+        /* fall through */
     default:
         s->dac_state = 0;
         break;
hw/display/tcx.c +0 -0
@@ -451,6 +452,7 @@ static void tcx_dac_writel(void *opaque, hwaddr addr,
 uint64_t val,
             s->b[index] = val >> 24;
             update_palette_entries(s, index, index + 1);
             s->dac_index = (s->dac_index + 1) & 0xff; /* Index

autoincrement */
+ /* fall through */

         default:
             s->dac_state = 0;
             break;

--
2.21.0

#8 lore raw

Re: [PATCH 2/6] hw/display/tcx: Add missing fall through comments

Quoted 41 lines · Aleksandar Markovic

On Tuesday, December 17, 2019, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

  hw/display/tcx.c: In function ‘tcx_dac_writel’:
  hw/display/tcx.c:453:26: error: this statement may fall through
[-Werror=implicit-fallthrough=]
    453 |             s->dac_index = (s->dac_index + 1) & 0xff; /*
Index autoincrement */
        |             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ hw/display/tcx.c:454:9: note: here
    454 |         default:
        |         ^~~~~~~
  hw/display/tcx.c: In function ‘tcx_dac_readl’:
  hw/display/tcx.c:412:22: error: this statement may fall through
[-Werror=implicit-fallthrough=]
    412 |         s->dac_index = (s->dac_index + 1) & 0xff; /*
Index autoincrement */
        |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ hw/display/tcx.c:413:5: note: here
    413 |     default:
        |     ^~~~~~~
  cc1: all warnings being treated as errors

Add the missing fall through comments.

Fixes 55d7bfe22

<mailto:[email protected]>>
---
Cc: Olivier Danet <[email protected] <mailto:[email protected]>>
Cc: Mark Cave-Ayland <[email protected] <mailto:[email protected]>>
---
 hw/display/tcx.c | 2 ++
 1 file changed, 2 insertions(+)

Quoted 1 line

The content of the patch is fine, but the commit message is, I think, inacurate: gcc is not confused at all, it does what it was told to.

You are correct, I'll update the comment.

Quoted 30 lines

The title is fine.

    diff --git a/hw/display/tcx.c b/hw/display/tcx.c
    index 14e829d3fa..abbeb30284 100644
    --- a/hw/display/tcx.c
    +++ b/hw/display/tcx.c
    @@ -410,6 +410,7 @@ static uint64_t tcx_dac_readl(void *opaque,
    hwaddr addr,
          case 2:
              val = s->b[s->dac_index] << 24;
              s->dac_index = (s->dac_index + 1) & 0xff; /* Index
    autoincrement */
    +        /* fall through */
          default:
              s->dac_state = 0;
              break;
    @@ -451,6 +452,7 @@ static void tcx_dac_writel(void *opaque, hwaddr
    addr, uint64_t val,
                  s->b[index] = val >> 24;
                  update_palette_entries(s, index, index + 1);
                  s->dac_index = (s->dac_index + 1) & 0xff; /* Index
    autoincrement */
    +            /* fall through */
              default:
                  s->dac_state = 0;
                  break;
    -- 
    2.21.0
#9 lore raw

PATCH 3/6 hw/net/imx_fec: Rewrite fall through comments

In reply to Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/net/imx_fec.c: In function ‘imx_eth_write’:
hw/net/imx_fec.c:906:12: error: this statement may fall through [-Werror=implicit-fallthrough=]

    906 |         if (unlikely(single_tx_ring)) {
        |            ^
  hw/net/imx_fec.c:912:5: note: here
    912 |     case ENET_TDAR:     /* FALLTHROUGH */
        |     ^~~~

cc1: all warnings being treated as errors

Rewrite the comments in the correct place, using 'fall through' which is recognized by GCC and static analyzers.

---
Cc: Peter Chubb <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: [email protected]

---
 hw/net/imx_fec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +5 -3
index bd99236864..30cc07753d 100644
@@ -901,15 +901,17 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,
             s->regs[index] = 0;
         }
         break;
-    case ENET_TDAR1:    /* FALLTHROUGH */
-    case ENET_TDAR2:    /* FALLTHROUGH */
+        /* fall through */
+    case ENET_TDAR1:
+    case ENET_TDAR2:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDAR2 or TDAR1\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
-    case ENET_TDAR:     /* FALLTHROUGH */
+        /* fall through */
+    case ENET_TDAR:
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             s->regs[index] = ENET_TDAR_TDAR;
             imx_eth_do_tx(s, index);
Signature · 1 line
2.21.0
#10 lore raw

Re: [PATCH 3/6] hw/net/imx_fec: Rewrite fall through comments

Quoted 30 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/net/imx_fec.c: In function ‘imx_eth_write’:
hw/net/imx_fec.c:906:12: error: this statement may fall through [-Werror=implicit-fallthrough=]

    906 |         if (unlikely(single_tx_ring)) {
        |            ^
  hw/net/imx_fec.c:912:5: note: here
    912 |     case ENET_TDAR:     /* FALLTHROUGH */
        |     ^~~~

cc1: all warnings being treated as errors

Rewrite the comments in the correct place, using 'fall through' which is recognized by GCC and static analyzers.

---
Cc: Peter Chubb <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: [email protected]

---
 hw/net/imx_fec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +0 -0
index bd99236864..30cc07753d 100644

hw/net/imx_fec.c static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, · line 904

Quoted 6 lines
hw/net/imx_fec.c +1 -2
@@ -901,15 +901,17 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,
             s->regs[index] = 0;
         }
         break;
-    case ENET_TDAR1:    /* FALLTHROUGH */
-    case ENET_TDAR2:    /* FALLTHROUGH */
+        /* fall through */

Wrong location. And I think you don't need any comment here at all, GCC should stay silent without it?

hw/net/imx_fec.c static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, · line 913

Quoted 10 lines
hw/net/imx_fec.c +3 -1
+    case ENET_TDAR1:
+    case ENET_TDAR2:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDAR2 or TDAR1\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
-    case ENET_TDAR:     /* FALLTHROUGH */
+        /* fall through */

I'd suggest to simply remove it, too.

hw/net/imx_fec.c static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, · line 917

Quoted 5 lines
hw/net/imx_fec.c +1 -0
+    case ENET_TDAR:
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             s->regs[index] = ENET_TDAR_TDAR;
             imx_eth_do_tx(s, index);

Thomas

#11 lore raw

Re: [PATCH 3/6] hw/net/imx_fec: Rewrite fall through comments

Quoted 52 lines · Thomas Huth
Quoted 30 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/net/imx_fec.c: In function ‘imx_eth_write’:
hw/net/imx_fec.c:906:12: error: this statement may fall through [-Werror=implicit-fallthrough=]

    906 |         if (unlikely(single_tx_ring)) {
        |            ^
  hw/net/imx_fec.c:912:5: note: here
    912 |     case ENET_TDAR:     /* FALLTHROUGH */
        |     ^~~~

cc1: all warnings being treated as errors

Rewrite the comments in the correct place, using 'fall through' which is recognized by GCC and static analyzers.

---
Cc: Peter Chubb <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: [email protected]

---
 hw/net/imx_fec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +0 -0
index bd99236864..30cc07753d 100644

hw/net/imx_fec.c static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, · line 904

Quoted 6 lines
hw/net/imx_fec.c +1 -2
@@ -901,15 +901,17 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,
             s->regs[index] = 0;
         }
         break;
-    case ENET_TDAR1:    /* FALLTHROUGH */
-    case ENET_TDAR2:    /* FALLTHROUGH */
+        /* fall through */

Wrong location. And I think you don't need any comment here at all, GCC should stay silent without it?

hw/net/imx_fec.c static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, · line 913

Quoted 10 lines
hw/net/imx_fec.c +3 -1
+    case ENET_TDAR1:
+    case ENET_TDAR2:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDAR2 or TDAR1\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
-    case ENET_TDAR:     /* FALLTHROUGH */
+        /* fall through */
Quoted 1 line

I'd suggest to simply remove it, too.

/me needsmorecoffee

... of course this hunk was fine. Good that you kept it in v2.

Thomas

Quoted 8 lines

hw/net/imx_fec.c static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, · line 917

Quoted 5 lines
hw/net/imx_fec.c +1 -0
+    case ENET_TDAR:
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             s->regs[index] = ENET_TDAR_TDAR;
             imx_eth_do_tx(s, index);

Thomas

Reviewed-by on v1 3/6
#12 lore raw

Re: [PATCH 3/6] hw/net/imx_fec: Rewrite fall through comments

In reply to Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/net/imx_fec.c: In function ‘imx_eth_write’:
hw/net/imx_fec.c:906:12: error: this statement may fall through [-Werror=implicit-fallthrough=]

    906 |         if (unlikely(single_tx_ring)) {
        |            ^
  hw/net/imx_fec.c:912:5: note: here
    912 |     case ENET_TDAR:     /* FALLTHROUGH */
        |     ^~~~

cc1: all warnings being treated as errors

Rewrite the comments in the correct place, using 'fall through' which is recognized by GCC and static analyzers.

Quoted 8 lines

---
Cc: Peter Chubb <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: [email protected]

---
 hw/net/imx_fec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

r~

Reviewed-by on v1 3/6
#13 lore raw

Re: [PATCH 3/6] hw/net/imx_fec: Rewrite fall through comments

In reply to Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé

GCC9 is confused by this comment when building with CFLAG -Wimplicit-fallthrough=2:

hw/net/imx_fec.c: In function ‘imx_eth_write’:
hw/net/imx_fec.c:906:12: error: this statement may fall through
[-Werror=implicit-fallthrough=]

    906 |         if (unlikely(single_tx_ring)) {
        |            ^
  hw/net/imx_fec.c:912:5: note: here
    912 |     case ENET_TDAR:     /* FALLTHROUGH */
        |     ^~~~

cc1: all warnings being treated as errors

Rewrite the comments in the correct place, using 'fall through' which is recognized by GCC and static analyzers.

Quoted 10 lines

---
Cc: Peter Chubb <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: [email protected]

---
 hw/net/imx_fec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Here we can truly say that gcc is confused (as opposed to another patch from this series).

The new positions of comments/annotations are good.

Quoted 31 lines
hw/net/imx_fec.c +5 -3
index bd99236864..30cc07753d 100644
@@ -901,15 +901,17 @@ static void imx_eth_write(void *opaque, hwaddr
 offset, uint64_t value,
             s->regs[index] = 0;
         }
         break;
-    case ENET_TDAR1:    /* FALLTHROUGH */
-    case ENET_TDAR2:    /* FALLTHROUGH */
+        /* fall through */
+    case ENET_TDAR1:
+    case ENET_TDAR2:
         if (unlikely(single_tx_ring)) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "[%s]%s: trying to access TDAR2 or TDAR1\n",
                           TYPE_IMX_FEC, __func__);
             return;
         }
-    case ENET_TDAR:     /* FALLTHROUGH */
+        /* fall through */
+    case ENET_TDAR:
         if (s->regs[ENET_ECR] & ENET_ECR_ETHEREN) {
             s->regs[index] = ENET_TDAR_TDAR;
             imx_eth_do_tx(s, index);

--
2.21.0

#14 lore raw

PATCH 4/6 hw/timer/aspeed_timer: Add a fall through comment

In reply to Philippe Mathieu-Daudé

Reported by GCC9 when building with CFLAG -Wimplicit-fallthrough=2:

hw/timer/aspeed_timer.c: In function ‘aspeed_timer_set_value’:
hw/timer/aspeed_timer.c:283:24: error: this statement may fall through [-Werror=implicit-fallthrough=]

    283 |         if (old_reload || !t->reload) {
        |             ~~~~~~~~~~~^~~~~~~~~~~~~
  hw/timer/aspeed_timer.c:287:5: note: here
    287 |     case TIMER_REG_STATUS:
        |     ^~~~

cc1: all warnings being treated as errors

Add the missing fall through comment.

Fixes 1403f364472

---
Cc: "Cédric Le Goater" <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Andrew Jeffery <[email protected]>
Cc: Joel Stanley <[email protected]>
Cc: [email protected]

---
 hw/timer/aspeed_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/aspeed_timer.c +1 -1
index a8c38cc118..c91f18415c 100644
@@ -283,7 +283,7 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
         if (old_reload || !t->reload) {
             break;
         }
-
+        /* fall through to re-enable */
     case TIMER_REG_STATUS:
         if (timer_enabled(t)) {
             uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
Signature · 1 line
2.21.0
Reviewed-by on v1 4/6
#15 lore raw

Re: [PATCH 4/6] hw/timer/aspeed_timer: Add a fall through comment

Quoted 9 lines · Philippe Mathieu-Daudé

Reported by GCC9 when building with CFLAG -Wimplicit-fallthrough=2:

hw/timer/aspeed_timer.c: In function ‘aspeed_timer_set_value’:
hw/timer/aspeed_timer.c:283:24: error: this statement may fall through [-Werror=implicit-fallthrough=]

    283 |         if (old_reload || !t->reload) {
        |             ~~~~~~~~~~~^~~~~~~~~~~~~
  hw/timer/aspeed_timer.c:287:5: note: here
    287 |     case TIMER_REG_STATUS:
        |     ^~~~
Quoted 6 lines

cc1: all warnings being treated as errors

Add the missing fall through comment.

Fixes 1403f364472
Quoted 24 lines

---
Cc: "Cédric Le Goater" <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Andrew Jeffery <[email protected]>
Cc: Joel Stanley <[email protected]>
Cc: [email protected]

---
 hw/timer/aspeed_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/aspeed_timer.c +1 -1
index a8c38cc118..c91f18415c 100644
@@ -283,7 +283,7 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
         if (old_reload || !t->reload) {
             break;
         }
-
+        /* fall through to re-enable */
     case TIMER_REG_STATUS:
         if (timer_enabled(t)) {
             uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
Reviewed-by on v1 4/6
#16 lore raw

Re: [PATCH 4/6] hw/timer/aspeed_timer: Add a fall through comment

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Reported by GCC9 when building with CFLAG -Wimplicit-fallthrough=2:

hw/timer/aspeed_timer.c: In function ‘aspeed_timer_set_value’:
hw/timer/aspeed_timer.c:283:24: error: this statement may fall through [-Werror=implicit-fallthrough=]

    283 |         if (old_reload || !t->reload) {
        |             ~~~~~~~~~~~^~~~~~~~~~~~~
  hw/timer/aspeed_timer.c:287:5: note: here
    287 |     case TIMER_REG_STATUS:
        |     ^~~~
Quoted 7 lines

cc1: all warnings being treated as errors

Add the missing fall through comment.

Fixes 1403f364472

---

Quoted 26 lines
Cc "Cédric Le Goater" <[email protected]>
Cc Peter Maydell <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Joel Stanley <[email protected]>
---
 hw/timer/aspeed_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/aspeed_timer.c +1 -2
index a8c38cc118..c91f18415c 100644
@@ -283,7 +283,7 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
         if (old_reload || !t->reload) {
             break;
         }
-
+        /* fall through to re-enable */
     case TIMER_REG_STATUS:
         if (timer_enabled(t)) {
             uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
--

2.21.0

#17 lore raw

PATCH 5/6 hw/scsi/megasas: Silent GCC9 duplicated-cond warning

In reply to Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

hw/scsi/megasas.c: In function ‘megasas_scsi_realize’:
hw/scsi/megasas.c:2387:26: error: duplicated ‘if’ condition [-Werror=duplicated-cond]
2387 | } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
hw/scsi/megasas.c:2385:19: note: previously used here
2385 | if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
cc1: all warnings being treated as errors

When this device was introduced in commit e8f943c3bcc, the author cared about modularity, using a definition for the firmware limit. If we modify the limit, the code is valid. Add a check if the definition got modified to a bigger limit.

---
Cc: Hannes Reinecke <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Fam Zheng <[email protected]>
Cc: [email protected]

---
 hw/scsi/megasas.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/megasas.c +2 -1
index de9bd20887..ece1601b66 100644
@@ -2382,7 +2382,8 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
     if (!s->hba_serial) {
         s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
     }
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
+    if (MEGASAS_MAX_SGE > 128
+        && s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
     } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;
Signature · 1 line
2.21.0
#18 lore raw

Re: [PATCH 5/6] hw/scsi/megasas: Silent GCC9 duplicated-cond warning

Quoted 30 lines · Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

hw/scsi/megasas.c: In function ‘megasas_scsi_realize’:
hw/scsi/megasas.c:2387:26: error: duplicated ‘if’ condition [-Werror=duplicated-cond]
2387 | } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
hw/scsi/megasas.c:2385:19: note: previously used here
2385 | if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
cc1: all warnings being treated as errors

When this device was introduced in commit e8f943c3bcc, the author cared about modularity, using a definition for the firmware limit. If we modify the limit, the code is valid. Add a check if the definition got modified to a bigger limit.

---
Cc: Hannes Reinecke <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Fam Zheng <[email protected]>
Cc: [email protected]

---
 hw/scsi/megasas.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/megasas.c +0 -0
index de9bd20887..ece1601b66 100644

hw/scsi/megasas.c static void megasas_scsi_realize(PCIDevice *dev, Error **errp) · line 2389

Quoted 9 lines
hw/scsi/megasas.c +2 -1
@@ -2382,7 +2382,8 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
     if (!s->hba_serial) {
         s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
     }
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
+    if (MEGASAS_MAX_SGE > 128
+        && s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
     } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;

I'm not keen on this. It looks to me like the raw 128 case should be removed -- surely that's the point of the symbolic constant. But I'll defer if a maintainer disagrees.

r~

#19 lore raw

Re: [PATCH 5/6] hw/scsi/megasas: Silent GCC9 duplicated-cond warning

Quoted 36 lines · Richard Henderson
Quoted 35 lines · Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

hw/scsi/megasas.c: In function ‘megasas_scsi_realize’:
hw/scsi/megasas.c:2387:26: error: duplicated ‘if’ condition [-Werror=duplicated-cond]

    2387 |     } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
   hw/scsi/megasas.c:2385:19: note: previously used here
    2385 |     if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {

cc1: all warnings being treated as errors

When this device was introduced in commit e8f943c3bcc, the author cared about modularity, using a definition for the firmware limit. If we modify the limit, the code is valid. Add a check if the definition got modified to a bigger limit.

---
Cc: Hannes Reinecke <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Fam Zheng <[email protected]>
Cc: [email protected]

---
  hw/scsi/megasas.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/megasas.c +2 -1
index de9bd20887..ece1601b66 100644
@@ -2382,7 +2382,8 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
      if (!s->hba_serial) {
          s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
      }
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
+    if (MEGASAS_MAX_SGE > 128
+        && s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
Quoted 8 lines

hw/scsi/megasas.c static void megasas_scsi_realize(PCIDevice *dev, Error **errp) · line 2389

Quoted 4 lines
hw/scsi/megasas.c +0 -0
          s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
      } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
          s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;

I'm not keen on this. It looks to me like the raw 128 case should be removed -- surely that's the point of the symbolic constant. But I'll defer if a maintainer disagrees.

Is that approach acceptable?

-- >8 --
@@ -54,6 +54,9 @@
#define MEGASAS_FLAG_USE_QUEUE64 1
#define MEGASAS_MASK_USE_QUEUE64 (1 << MEGASAS_FLAG_USE_QUEUE64)

+QEMU_BUILD_BUG_MSG(MEGASAS_MAX_SGE > 128,
+ "Firmware limit too big for this device model");
+

 static const char *mfi_frame_desc[] = {
     "MFI init", "LD Read", "LD Write", "LD SCSI", "PD SCSI",
     "MFI Doorbell", "MFI Abort", "MFI SMP", "MFI Stop"};
@@ -2382,9 +2385,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
     if (!s->hba_serial) {
         s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
     }
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
-        s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
-    } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
+    if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;
     } else {
         s->fw_sge = 64 - MFI_PASS_FRAME_SIZE;

---

#20 lore raw

Re: [PATCH 5/6] hw/scsi/megasas: Silent GCC9 duplicated-cond warning

Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 11 lines
Quoted 7 lines

-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) { +    if (MEGASAS_MAX_SGE > 128
+        && s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) { s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE; } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) { s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;

I'm not keen on this.  It looks to me like the raw 128 case should be removed -- surely that's the point of the symbolic constant.  But I'll defer if a maintainer disagrees.

Is that approach acceptable?

-- >8 --

hw/scsi/megasas.c +4 -3
@@ -54,6 +54,9 @@
  #define MEGASAS_FLAG_USE_QUEUE64   1
  #define MEGASAS_MASK_USE_QUEUE64   (1 << MEGASAS_FLAG_USE_QUEUE64)
 
+QEMU_BUILD_BUG_MSG(MEGASAS_MAX_SGE > 128,
+                   "Firmware limit too big for this device model");
+
  static const char *mfi_frame_desc[] = {
      "MFI init", "LD Read", "LD Write", "LD SCSI", "PD SCSI",
      "MFI Doorbell", "MFI Abort", "MFI SMP", "MFI Stop"};
@@ -2382,9 +2385,7 @@ static void megasas_scsi_realize(PCIDevice *dev, Error
 **errp)
      if (!s->hba_serial) {
          s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
      }
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
-        s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
-    } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
+    if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
          s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;
      } else {
Quoted 1 line

         s->fw_sge = 64 - MFI_PASS_FRAME_SIZE;

Eh. I suppose. But what's the point of leaving the hard-coded 128? There's certainly something I'm missing here...

r~

#21 lore raw

Re: [PATCH 5/6] hw/scsi/megasas: Silent GCC9 duplicated-cond warning

In reply to Richard Henderson
Quoted 13 lines · Richard Henderson

hw/scsi/megasas.c static void megasas_scsi_realize(PCIDevice *dev, Error **errp)

Quoted 12 lines
     if (!s->hba_serial) {
         s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
     }
hw/scsi/megasas.c +2 -1
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
+    if (MEGASAS_MAX_SGE > 128
+        && s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
     } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;
     } else {
         s->fw_sge = 64 - MFI_PASS_FRAME_SIZE;
     }
Quoted 3 lines

I'm not keen on this. It looks to me like the raw 128 case should be removed -- surely that's the point of the symbolic constant. But I'll defer if a maintainer disagrees.

I don't really understand this chain of ifs. Hannes, does it make sense to just remove the "if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE)" case, or does Phil's variation (quoted in the patch fragment above) makes sense?

Or perhaps this rewrite:

        max_sge = s->fw_sge + MFI_PASS_FRAME_SIZE;
        if (max_sge < MEGASAS_MAX_SGE) {
            if (max_sge < 64) {
                error(...);
            } else {
                max_sge = max_sge < 128 ? 64 : 128;
            }
        }
	s->fw_sge = max_sge - MFI_PASS_FRAME_SIZE;

Paolo

#22 lore raw

Re: [PATCH 5/6] hw/scsi/megasas: Silent GCC9 duplicated-cond warning

Quoted 24 lines · Paolo Bonzini
Quoted 13 lines · Richard Henderson

hw/scsi/megasas.c static void megasas_scsi_realize(PCIDevice *dev, Error **errp)

Quoted 12 lines
     if (!s->hba_serial) {
         s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
     }
hw/scsi/megasas.c +2 -1
-    if (s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
+    if (MEGASAS_MAX_SGE > 128
+        && s->fw_sge >= MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = MEGASAS_MAX_SGE - MFI_PASS_FRAME_SIZE;
     } else if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE) {
         s->fw_sge = 128 - MFI_PASS_FRAME_SIZE;
     } else {
         s->fw_sge = 64 - MFI_PASS_FRAME_SIZE;
     }
Quoted 3 lines

I'm not keen on this. It looks to me like the raw 128 case should be removed -- surely that's the point of the symbolic constant. But I'll defer if a maintainer disagrees.

I don't really understand this chain of ifs. Hannes, does it make sense to just remove the "if (s->fw_sge >= 128 - MFI_PASS_FRAME_SIZE)" case, or does Phil's variation (quoted in the patch fragment above) makes sense?

Or perhaps this rewrite:

Quoted 10 lines
        max_sge = s->fw_sge + MFI_PASS_FRAME_SIZE;
        if (max_sge < MEGASAS_MAX_SGE) {
            if (max_sge < 64) {
                error(...);
            } else {
                max_sge = max_sge < 128 ? 64 : 128;
            }
        }
	s->fw_sge = max_sge - MFI_PASS_FRAME_SIZE;

Yeah, do it.
The original code assumed that one could change MFI_PASS_FRAME_SIZE, but it turned out not to be possible as it's being hardcoded in the drivers themselves (even though the interface provides mechanisms to query it). So we can remove the duplicate lines.
But then I prefer to stick with the define, and avoid having to check the magic '128' value directly; rather use the define throughout the code.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      Teamlead Storage & Networking
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
#23 lore raw

PATCH 6/6 qemu-io-cmds: Silent GCC9 format-overflow warning

In reply to Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

In function ‘help_oneline’,
inlined from ‘help_all’ at qemu-io-cmds.c:2414:9,
inlined from ‘help_f’ at qemu-io-cmds.c:2424:9:
qemu-io-cmds.c:2389:9: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

   2389 |         printf("%s ", ct->name);
        |         ^~~~~~~~~~~~~~~~~~~~~~~

Audit shows this can't happen. Give a hint to GCC adding an assert() call.

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: [email protected]

---
 qemu-io-cmds.c | 1 +
 1 file changed, 1 insertion(+)
qemu-io-cmds.c +1 -0
index 1b7e700020..9e956a5dd4 100644
@@ -2411,6 +2411,7 @@ static void help_all(void)
     const cmdinfo_t *ct;
 
     for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
+        assert(ct->name);
         help_oneline(ct->name, ct);
     }
     printf("\nUse 'help commandname' for extended help.\n");
Signature · 1 line
2.21.0
#24 lore raw

Re: [PATCH 6/6] qemu-io-cmds: Silent GCC9 format-overflow warning

Quoted 11 lines · Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

In function ‘help_oneline’,
inlined from ‘help_all’ at qemu-io-cmds.c:2414:9,
inlined from ‘help_f’ at qemu-io-cmds.c:2424:9:
qemu-io-cmds.c:2389:9: error: ‘%s’ directive argument is null [-Werror=format-overflow=]

   2389 |         printf("%s ", ct->name);
        |         ^~~~~~~~~~~~~~~~~~~~~~~

Audit shows this can't happen. Give a hint to GCC adding an assert() call.

This deserves more investigation. From my glance it appears you are right -- and moreover impossible for gcc to have come to this conclusion. Which begs the question of how that is.

Did you file a gcc bug report?

r~

Quoted 23 lines

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: [email protected]

---
 qemu-io-cmds.c | 1 +
 1 file changed, 1 insertion(+)
qemu-io-cmds.c +1 -0
index 1b7e700020..9e956a5dd4 100644
@@ -2411,6 +2411,7 @@ static void help_all(void)
     const cmdinfo_t *ct;
 
     for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
+        assert(ct->name);
         help_oneline(ct->name, ct);
     }
     printf("\nUse 'help commandname' for extended help.\n");
#25 lore raw

Re: [PATCH 6/6] qemu-io-cmds: Silent GCC9 format-overflow warning

Quoted 10 lines · Richard Henderson
Quoted 9 lines · Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

In function ‘help_oneline’,
inlined from ‘help_all’ at qemu-io-cmds.c:2414:9, inlined from ‘help_f’ at qemu-io-cmds.c:2424:9:

   qemu-io-cmds.c:2389:9: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    2389 |         printf("%s ", ct->name);
         |         ^~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 2 lines

Audit shows this can't happen. Give a hint to GCC adding an assert() call.

This deserves more investigation. From my glance it appears you are right -- and moreover impossible for gcc to have come to this conclusion. Which begs the question of how that is.

New entries are added to cmdtab[] in qemuio_add_command() which is public (also called in qemu-io.c). So you can insert a cmdinfo_t with a name being NULL. This is why I thought GCC was correct first, and I tried:

-- >8 --

qemu-io-cmds.c +1 -0
@@ -42,6 +42,7 @@ void qemuio_add_command(const cmdinfo_t *ci)
      * Catch it now rather than letting it manifest as a crash if a
      * particular set of command line options are used.
      */
+    assert(ci->name);
     assert(ci->perm == 0 ||
            (ci->flags & (CMD_FLAG_GLOBAL | CMD_NOFILE_OK)) == 0);
     cmdtab = g_renew(cmdinfo_t, cmdtab, ++ncmds);

---

But this didn't fix the warning... So I moved the assert() in the other location.

Quoted 2 lines

Did you file a gcc bug report?

No because I'm not sure this is a bug, but if you confirm I'll file one :)

Quoted 24 lines
Quoted 23 lines

---
Cc: Kevin Wolf <[email protected]>
Cc: Max Reitz <[email protected]>
Cc: [email protected]

---
  qemu-io-cmds.c | 1 +
  1 file changed, 1 insertion(+)
qemu-io-cmds.c +1 -0
index 1b7e700020..9e956a5dd4 100644
@@ -2411,6 +2411,7 @@ static void help_all(void)
      const cmdinfo_t *ct;
 
      for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
+        assert(ct->name);
          help_oneline(ct->name, ct);
      }
      printf("\nUse 'help commandname' for extended help.\n");
#26 lore raw

Re: [PATCH 6/6] qemu-io-cmds: Silent GCC9 format-overflow warning

Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Richard Henderson
Quoted 10 lines · Philippe Mathieu-Daudé

GCC9 is confused when building with CFLAG -O3:

   In function ‘help_oneline’,
       inlined from ‘help_all’ at qemu-io-cmds.c:2414:9, inlined from ‘help_f’ at qemu-io-cmds.c:2424:9:
   qemu-io-cmds.c:2389:9: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
    2389 |         printf("%s ", ct->name);
         |         ^~~~~~~~~~~~~~~~~~~~~~~

Quoted 6 lines
Quoted 2 lines

Audit shows this can't happen. Give a hint to GCC adding an assert() call.

This deserves more investigation.  From my glance it appears you are right -- and moreover impossible for gcc to have come to this conclusion.  Which begs the question of how that is.

New entries are added to cmdtab[] in qemuio_add_command() which is public (also called in qemu-io.c). So you can insert a cmdinfo_t with a name being NULL. This is why I thought GCC was correct first, and I tried:

-- >8 --

qemu-io-cmds.c +1 -0
@@ -42,6 +42,7 @@ void qemuio_add_command(const cmdinfo_t *ci)
       * Catch it now rather than letting it manifest as a crash if a
       * particular set of command line options are used.
       */
+    assert(ci->name);

     assert(ci->perm == 0 ||
            (ci->flags & (CMD_FLAG_GLOBAL | CMD_NOFILE_OK)) == 0); cmdtab = g_renew(cmdinfo_t, cmdtab, ++ncmds);
---

Quoted 6 lines

But this didn't fix the warning... So I moved the assert() in the other location.

Quoted 2 lines

Did you file a gcc bug report?

No because I'm not sure this is a bug, but if you confirm I'll file one :)

The error message is not saying the value *might* be null, but that it *is* null. That is, the compiler thinks that it has proven the value can be no other value than null.

Can I assume that you've tested this particular code path, rather than merely removed the Werror?

If the compiler really is "proving" that the value must be null, then the assert should be transformed to assert(false), and qemu will abort at runtime.
In this case, the reason why the Werror went away is that the printf is
removed as unreachable beforehand.

But of course the value assigned in qemuio_add_command is truly variable, and since -O3 does not imply -flto the compiler cannot have proven to see all callers. So it follows that the compiler should not have proven that the value is null.

So there *must* be a compiler bug. The only question is whether it is isolated to the printf warning or if it goes further into value propagation and wrong code generation.

r~