Skip to contentSkip to conversation

hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow

PATCH In review Thomas Huth 4 participants 5 messages Oct 6, 2023 – Oct 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow

Avoid using trivial variable names in macros, otherwise we get the following compiler warning when compiling with -Wshadow=local:

In file included from ../../qemu/hw/display/virtio-gpu-virgl.c:19:
../../home/thuth/devel/qemu/hw/display/virtio-gpu-virgl.c:
In function ‘virgl_cmd_submit_3d’:
../../qemu/include/hw/virtio/virtio-gpu.h:228:16: error: declaration of ‘s’
shadows a previous local [-Werror=shadow=compatible-local]
228 | size_t s;
| ^
../../qemu/hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro
‘VIRTIO_GPU_FILL_CMD’

  215 |     VIRTIO_GPU_FILL_CMD(cs);
      |     ^~~~~~~~~~~~~~~~~~~

../../qemu/hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration
is here
213 | size_t s;
| ^
cc1: all warnings being treated as errors

---
 include/hw/virtio/virtio-gpu.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +4 -4
index 390c4642b8..8b7e3faf01 100644
@@ -225,13 +225,13 @@ struct VhostUserGPU {
 };
 
 #define VIRTIO_GPU_FILL_CMD(out) do {                                   \
-        size_t s;                                                       \
-        s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,          \
+        size_t s_;                                                      \
+        s_ = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,         \
                        &out, sizeof(out));                              \
-        if (s != sizeof(out)) {                                         \
+        if (s_ != sizeof(out)) {                                        \
             qemu_log_mask(LOG_GUEST_ERROR,                              \
                           "%s: command size incorrect %zu vs %zu\n",    \
-                          __func__, s, sizeof(out));                    \
+                          __func__, s_, sizeof(out));                   \
             return;                                                     \
         }                                                               \
     } while (0)
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Thomas Huth

Avoid using trivial variable names in macros, otherwise we get the following compiler warning when compiling with -Wshadow=local:

In file included from ../../qemu/hw/display/virtio-gpu-virgl.c:19:
../../home/thuth/devel/qemu/hw/display/virtio-gpu-virgl.c:
In function ‘virgl_cmd_submit_3d’:
../../qemu/include/hw/virtio/virtio-gpu.h:228:16: error: declaration of ‘s’
shadows a previous local [-Werror=shadow=compatible-local]
228 | size_t s;
| ^
../../qemu/hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro
‘VIRTIO_GPU_FILL_CMD’

  215 |     VIRTIO_GPU_FILL_CMD(cs);
      |     ^~~~~~~~~~~~~~~~~~~
Quoted 7 lines

../../qemu/hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration
is here
213 | size_t s;
| ^
cc1: all warnings being treated as errors

Quoted 30 lines
---
 include/hw/virtio/virtio-gpu.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +4 -5
index 390c4642b8..8b7e3faf01 100644
@@ -225,13 +225,13 @@ struct VhostUserGPU {
 };
 
 #define VIRTIO_GPU_FILL_CMD(out) do {                                   \
-        size_t s;                                                       \
-        s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,          \
+        size_t s_;                                                      \
+        s_ = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,         \
                        &out, sizeof(out));                              \
-        if (s != sizeof(out)) {                                         \
+        if (s_ != sizeof(out)) {                                        \
             qemu_log_mask(LOG_GUEST_ERROR,                              \
                           "%s: command size incorrect %zu vs %zu\n",    \
-                          __func__, s, sizeof(out));                    \
+                          __func__, s_, sizeof(out));                   \
             return;                                                     \
         }                                                               \
     } while (0)
--

2.41.0

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to Thomas Huth
Quoted 37 lines · Thomas Huth

Avoid using trivial variable names in macros, otherwise we get the following compiler warning when compiling with -Wshadow=local:

In file included from ../../qemu/hw/display/virtio-gpu-virgl.c:19:
../../home/thuth/devel/qemu/hw/display/virtio-gpu-virgl.c:
In function ‘virgl_cmd_submit_3d’:
../../qemu/include/hw/virtio/virtio-gpu.h:228:16: error: declaration of ‘s’
shadows a previous local [-Werror=shadow=compatible-local]
228 | size_t s;
| ^
../../qemu/hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro
‘VIRTIO_GPU_FILL_CMD’

  215 |     VIRTIO_GPU_FILL_CMD(cs);
      |     ^~~~~~~~~~~~~~~~~~~

../../qemu/hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration
is here
213 | size_t s;
| ^
cc1: all warnings being treated as errors

---
 include/hw/virtio/virtio-gpu.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +2 -2
index 390c4642b8..8b7e3faf01 100644
@@ -225,13 +225,13 @@ struct VhostUserGPU {
 };
 
 #define VIRTIO_GPU_FILL_CMD(out) do {                                   \
-        size_t s;                                                       \
-        s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,          \
+        size_t s_;                                                      \
+        s_ = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,         \

include/hw/virtio/virtio-gpu.h struct VhostUserGPU { · line 237

Quoted 10 lines
include/hw/virtio/virtio-gpu.h +2 -2
                        &out, sizeof(out));                              \
-        if (s != sizeof(out)) {                                         \
+        if (s_ != sizeof(out)) {                                        \
             qemu_log_mask(LOG_GUEST_ERROR,                              \
                           "%s: command size incorrect %zu vs %zu\n",    \
-                          __func__, s, sizeof(out));                    \
+                          __func__, s_, sizeof(out));                   \
             return;                                                     \
         }                                                               \
     } while (0)

This is not really enough I think. Someone might use another macro as parameter to this macro and we'll get a mess. We want something that's specific to this macro. How about VIRTIO_GPU_FILL_CMD_s ?

Quoted 2 lines
Signature · 1 line
2.41.0
#3 lore raw
Quoted 45 lines · Michael S. Tsirkin
Quoted 44 lines · Thomas Huth

Avoid using trivial variable names in macros, otherwise we get the following compiler warning when compiling with -Wshadow=local:

In file included from ../../qemu/hw/display/virtio-gpu-virgl.c:19:
../../home/thuth/devel/qemu/hw/display/virtio-gpu-virgl.c:
In function ‘virgl_cmd_submit_3d’:
../../qemu/include/hw/virtio/virtio-gpu.h:228:16: error: declaration of ‘s’
shadows a previous local [-Werror=shadow=compatible-local]
228 | size_t s;
| ^
../../qemu/hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro
‘VIRTIO_GPU_FILL_CMD’

   215 |     VIRTIO_GPU_FILL_CMD(cs);
       |     ^~~~~~~~~~~~~~~~~~~

../../qemu/hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration
is here
213 | size_t s;
| ^
cc1: all warnings being treated as errors

---
  include/hw/virtio/virtio-gpu.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +4 -4
index 390c4642b8..8b7e3faf01 100644
@@ -225,13 +225,13 @@ struct VhostUserGPU {
  };
 
  #define VIRTIO_GPU_FILL_CMD(out) do {                                   \
-        size_t s;                                                       \
-        s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,          \
+        size_t s_;                                                      \
+        s_ = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,         \
                         &out, sizeof(out));                              \
-        if (s != sizeof(out)) {                                         \
+        if (s_ != sizeof(out)) {                                        \
              qemu_log_mask(LOG_GUEST_ERROR,                              \
                            "%s: command size incorrect %zu vs %zu\n",    \
-                          __func__, s, sizeof(out));                    \
+                          __func__, s_, sizeof(out));                   \
Quoted 8 lines

include/hw/virtio/virtio-gpu.h struct VhostUserGPU { · line 237

Quoted 3 lines
include/hw/virtio/virtio-gpu.h +0 -0
              return;                                                     \
          }                                                               \
      } while (0)

This is not really enough I think. Someone might use another macro as parameter to this macro and we'll get a mess. We want something that's specific to this macro. How about VIRTIO_GPU_FILL_CMD_s ?

Or unmacroize as:

virtio_gpu_fill_cmd(struct virtio_gpu_ctrl_command *cmd,

                      const void *data, size_t size);
#4 lore raw
In reply to Michael S. Tsirkin
Quoted 45 lines · Michael S. Tsirkin
Quoted 44 lines · Thomas Huth

Avoid using trivial variable names in macros, otherwise we get the following compiler warning when compiling with -Wshadow=local:

In file included from ../../qemu/hw/display/virtio-gpu-virgl.c:19:
../../home/thuth/devel/qemu/hw/display/virtio-gpu-virgl.c:
In function ‘virgl_cmd_submit_3d’:
../../qemu/include/hw/virtio/virtio-gpu.h:228:16: error: declaration of ‘s’
shadows a previous local [-Werror=shadow=compatible-local]
228 | size_t s;
| ^
../../qemu/hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro
‘VIRTIO_GPU_FILL_CMD’

   215 |     VIRTIO_GPU_FILL_CMD(cs);
       |     ^~~~~~~~~~~~~~~~~~~

../../qemu/hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration
is here
213 | size_t s;
| ^
cc1: all warnings being treated as errors

---
  include/hw/virtio/virtio-gpu.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/virtio/virtio-gpu.h +4 -4
index 390c4642b8..8b7e3faf01 100644
@@ -225,13 +225,13 @@ struct VhostUserGPU {
  };
 
  #define VIRTIO_GPU_FILL_CMD(out) do {                                   \
-        size_t s;                                                       \
-        s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,          \
+        size_t s_;                                                      \
+        s_ = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0,         \
                         &out, sizeof(out));                              \
-        if (s != sizeof(out)) {                                         \
+        if (s_ != sizeof(out)) {                                        \
              qemu_log_mask(LOG_GUEST_ERROR,                              \
                            "%s: command size incorrect %zu vs %zu\n",    \
-                          __func__, s, sizeof(out));                    \
+                          __func__, s_, sizeof(out));                   \
Quoted 8 lines

include/hw/virtio/virtio-gpu.h struct VhostUserGPU { · line 237

Quoted 3 lines
include/hw/virtio/virtio-gpu.h +0 -0
              return;                                                     \
          }                                                               \
      } while (0)

This is not really enough I think. Someone might use another macro as parameter to this macro and we'll get a mess. We want something that's specific to this macro. How about VIRTIO_GPU_FILL_CMD_s ?

Sure, can do (also for the other patch).

Thomas