All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow
@ 2023-10-06 16:45 Thomas Huth
  2023-10-08  7:00 ` Marc-André Lureau
  2023-10-08  8:57 ` Michael S. Tsirkin
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Huth @ 2023-10-06 16:45 UTC (permalink / raw)
  To: Gerd Hoffmann, Michael S. Tsirkin, qemu-devel; +Cc: Markus Armbruster

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

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/hw/virtio/virtio-gpu.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 390c4642b8..8b7e3faf01 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow
  2023-10-06 16:45 [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow Thomas Huth
@ 2023-10-08  7:00 ` Marc-André Lureau
  2023-10-08  8:57 ` Michael S. Tsirkin
  1 sibling, 0 replies; 5+ messages in thread
From: Marc-André Lureau @ 2023-10-08  7:00 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Gerd Hoffmann, Michael S. Tsirkin, qemu-devel, Markus Armbruster

On Fri, Oct 6, 2023 at 8:46 PM Thomas Huth <thuth@redhat.com> wrote:
>
> 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
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  include/hw/virtio/virtio-gpu.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
> index 390c4642b8..8b7e3faf01 100644
> --- a/include/hw/virtio/virtio-gpu.h
> +++ b/include/hw/virtio/virtio-gpu.h
> @@ -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
>
>


-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow
  2023-10-06 16:45 [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow Thomas Huth
  2023-10-08  7:00 ` Marc-André Lureau
@ 2023-10-08  8:57 ` Michael S. Tsirkin
  2023-10-08 11:49   ` Philippe Mathieu-Daudé
  2023-10-09  8:13   ` Thomas Huth
  1 sibling, 2 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2023-10-08  8:57 UTC (permalink / raw)
  To: Thomas Huth; +Cc: Gerd Hoffmann, qemu-devel, Markus Armbruster

On Fri, Oct 06, 2023 at 06:45:08PM +0200, Thomas Huth wrote:
> 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
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  include/hw/virtio/virtio-gpu.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
> index 390c4642b8..8b7e3faf01 100644
> --- a/include/hw/virtio/virtio-gpu.h
> +++ b/include/hw/virtio/virtio-gpu.h
> @@ -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)

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 ?


> -- 
> 2.41.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow
  2023-10-08  8:57 ` Michael S. Tsirkin
@ 2023-10-08 11:49   ` Philippe Mathieu-Daudé
  2023-10-09  8:13   ` Thomas Huth
  1 sibling, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-08 11:49 UTC (permalink / raw)
  To: Michael S. Tsirkin, Thomas Huth
  Cc: Gerd Hoffmann, qemu-devel, Markus Armbruster

On 8/10/23 10:57, Michael S. Tsirkin wrote:
> On Fri, Oct 06, 2023 at 06:45:08PM +0200, Thomas Huth wrote:
>> 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
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   include/hw/virtio/virtio-gpu.h | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
>> index 390c4642b8..8b7e3faf01 100644
>> --- a/include/hw/virtio/virtio-gpu.h
>> +++ b/include/hw/virtio/virtio-gpu.h
>> @@ -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)
> 
> 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);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow
  2023-10-08  8:57 ` Michael S. Tsirkin
  2023-10-08 11:49   ` Philippe Mathieu-Daudé
@ 2023-10-09  8:13   ` Thomas Huth
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Huth @ 2023-10-09  8:13 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Gerd Hoffmann, qemu-devel, Markus Armbruster

On 08/10/2023 10.57, Michael S. Tsirkin wrote:
> On Fri, Oct 06, 2023 at 06:45:08PM +0200, Thomas Huth wrote:
>> 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
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   include/hw/virtio/virtio-gpu.h | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
>> index 390c4642b8..8b7e3faf01 100644
>> --- a/include/hw/virtio/virtio-gpu.h
>> +++ b/include/hw/virtio/virtio-gpu.h
>> @@ -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)
> 
> 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




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-09  8:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 16:45 [PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow Thomas Huth
2023-10-08  7:00 ` Marc-André Lureau
2023-10-08  8:57 ` Michael S. Tsirkin
2023-10-08 11:49   ` Philippe Mathieu-Daudé
2023-10-09  8:13   ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.