Skip to contentSkip to conversation

Help wanted for enabling -Wshadow=local

PATCH In review Markus Armbruster 3 participants 7 messages Oct 6, 2023 – Oct 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Help wanted for enabling -Wshadow=local

Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".

Enabling -Wshadow would prevent bugs like this one. But we have to clean up all the offenders first.

Quite a few people responded to my calls for help. Thank you so much!

I'm collecting patches in my git repo at
https://repo.or.cz/qemu/armbru.git in branch shadow-next. All but the last two are in a pending pull request.

My test build is down to seven files with warnings. "[PATCH v2 0/3]
hexagon: GETPC() and shadowing fixes" takes care of four, but it needs a rebase.

Remaining three:

In file included from ../hw/display/virtio-gpu-virgl.c:19:
../hw/display/virtio-gpu-virgl.c: In function ‘virgl_cmd_submit_3d’:
/work/armbru/qemu/include/hw/virtio/virtio-gpu.h:228:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
228 | size_t s; \
| ^
../hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro ‘VIRTIO_GPU_FILL_CMD’
215 | VIRTIO_GPU_FILL_CMD(cs);
| ^~~~~~~~~~~~~~~~~~~
../hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration is here
213 | size_t s;
| ^

In file included from ../contrib/vhost-user-gpu/virgl.h:18,
from ../contrib/vhost-user-gpu/virgl.c:17:
../contrib/vhost-user-gpu/virgl.c: In function ‘virgl_cmd_submit_3d’:
../contrib/vhost-user-gpu/vugpu.h:167:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
167 | size_t s; \
| ^
../contrib/vhost-user-gpu/virgl.c:203:5: note: in expansion of macro ‘VUGPU_FILL_CMD’
203 | VUGPU_FILL_CMD(cs);
| ^~~~~~~~~~~~~~
../contrib/vhost-user-gpu/virgl.c:201:12: note: shadowed declaration is here
201 | size_t s;
| ^

../contrib/vhost-user-gpu/vhost-user-gpu.c: In function ‘vg_resource_flush’:
../contrib/vhost-user-gpu/vhost-user-gpu.c:837:29: warning: declaration of ‘i’ shadows a previous local [-Wshadow=local]
837 | pixman_image_t *i =
| ^
../contrib/vhost-user-gpu/vhost-user-gpu.c:757:9: note: shadowed declaration is here
757 | int i;
| ^

Gerd, Marc-André, or anybody else?

More warnings may lurk in code my test build doesn't compile. Need a full CI build with -Wshadow=local to find them. Anybody care to kick one off?

#1 lore raw
Quoted 53 lines · Markus Armbruster

Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".

Enabling -Wshadow would prevent bugs like this one. But we have to clean up all the offenders first.

Quite a few people responded to my calls for help. Thank you so much!

I'm collecting patches in my git repo at
https://repo.or.cz/qemu/armbru.git in branch shadow-next. All but the last two are in a pending pull request.

My test build is down to seven files with warnings. "[PATCH v2 0/3]
hexagon: GETPC() and shadowing fixes" takes care of four, but it needs a rebase.

Remaining three:

In file included from ../hw/display/virtio-gpu-virgl.c:19:
../hw/display/virtio-gpu-virgl.c: In function ‘virgl_cmd_submit_3d’:
/work/armbru/qemu/include/hw/virtio/virtio-gpu.h:228:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
228 | size_t s; \
| ^
../hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro ‘VIRTIO_GPU_FILL_CMD’
215 | VIRTIO_GPU_FILL_CMD(cs);
| ^~~~~~~~~~~~~~~~~~~
../hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration is here
213 | size_t s;
| ^

In file included from ../contrib/vhost-user-gpu/virgl.h:18,
from ../contrib/vhost-user-gpu/virgl.c:17:
../contrib/vhost-user-gpu/virgl.c: In function ‘virgl_cmd_submit_3d’:
../contrib/vhost-user-gpu/vugpu.h:167:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
167 | size_t s; \
| ^
../contrib/vhost-user-gpu/virgl.c:203:5: note: in expansion of macro ‘VUGPU_FILL_CMD’
203 | VUGPU_FILL_CMD(cs);
| ^~~~~~~~~~~~~~
../contrib/vhost-user-gpu/virgl.c:201:12: note: shadowed declaration is here
201 | size_t s;
| ^

../contrib/vhost-user-gpu/vhost-user-gpu.c: In function ‘vg_resource_flush’:
../contrib/vhost-user-gpu/vhost-user-gpu.c:837:29: warning: declaration of ‘i’ shadows a previous local [-Wshadow=local]
837 | pixman_image_t *i =
| ^
../contrib/vhost-user-gpu/vhost-user-gpu.c:757:9: note: shadowed declaration is here
757 | int i;
| ^

Quoted 5 lines

Gerd, Marc-André, or anybody else?

More warnings may lurk in code my test build doesn't compile. Need a full CI build with -Wshadow=local to find them. Anybody care to kick one off?

I ran a build here (with -Werror enabled, so that it's easier to see where it breaks):

https://gitlab.com/thuth/qemu/-/pipelines/1028023489

... but I didn't see any additional spots in the logs beside the ones that you already listed.

Thomas

#2 lore raw
Quoted 60 lines · Thomas Huth
Quoted 53 lines · Markus Armbruster

Local variables shadowing other local variables or parameters make the code needlessly hard to understand.  Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".

Enabling -Wshadow would prevent bugs like this one.  But we have to clean up all the offenders first.

Quite a few people responded to my calls for help.  Thank you so much!

I'm collecting patches in my git repo at
https://repo.or.cz/qemu/armbru.git in branch shadow-next.  All but the last two are in a pending pull request.

My test build is down to seven files with warnings.  "[PATCH v2 0/3]
hexagon: GETPC() and shadowing fixes" takes care of four, but it needs a rebase.

Remaining three:

     In file included from ../hw/display/virtio-gpu-virgl.c:19:
     ../hw/display/virtio-gpu-virgl.c: In function ‘virgl_cmd_submit_3d’:
     /work/armbru/qemu/include/hw/virtio/virtio-gpu.h:228:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local] 228 |         size_t s;                                                       \
           |                ^
     ../hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro ‘VIRTIO_GPU_FILL_CMD’
       215 |     VIRTIO_GPU_FILL_CMD(cs);
           |     ^~~~~~~~~~~~~~~~~~~
     ../hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration is here
       213 |     size_t s;
           |            ^

     In file included from ../contrib/vhost-user-gpu/virgl.h:18,
                      from ../contrib/vhost-user-gpu/virgl.c:17:
     ../contrib/vhost-user-gpu/virgl.c: In function ‘virgl_cmd_submit_3d’:
     ../contrib/vhost-user-gpu/vugpu.h:167:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local] 167 |         size_t s;                                               \
           |                ^
     ../contrib/vhost-user-gpu/virgl.c:203:5: note: in expansion of macro ‘VUGPU_FILL_CMD’
       203 |     VUGPU_FILL_CMD(cs);
           |     ^~~~~~~~~~~~~~
     ../contrib/vhost-user-gpu/virgl.c:201:12: note: shadowed declaration is here
       201 |     size_t s;
           |            ^

     ../contrib/vhost-user-gpu/vhost-user-gpu.c: In function ‘vg_resource_flush’:
     ../contrib/vhost-user-gpu/vhost-user-gpu.c:837:29: warning: declaration of ‘i’ shadows a previous local [-Wshadow=local] 837 |             pixman_image_t *i =
           |                             ^
     ../contrib/vhost-user-gpu/vhost-user-gpu.c:757:9: note: shadowed declaration is here
       757 |     int i;
           |         ^

Quoted 5 lines

Gerd, Marc-André, or anybody else?

More warnings may lurk in code my test build doesn't compile.  Need a full CI build with -Wshadow=local to find them.  Anybody care to kick one off?

Quoted 5 lines

I ran a build here (with -Werror enabled, so that it's easier to see where it breaks):

 https://gitlab.com/thuth/qemu/-/pipelines/1028023489

... but I didn't see any additional spots in the logs beside the ones that you already listed.

After adding two more patches to fix the above warnings, things look pretty good:

https://gitlab.com/thuth/qemu/-/pipelines/1028413030

There are just some warnings left in the BSD code, as Warner already mentioned in his reply to v2 of your mail:

https://gitlab.com/thuth/qemu/-/jobs/5241420713

Thomas

#3 lore raw
Quoted 93 lines · Thomas Huth
Quoted 15 lines · Thomas Huth
Quoted 14 lines · Markus Armbruster

Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".

Enabling -Wshadow would prevent bugs like this one. But we have to clean up all the offenders first.

Quite a few people responded to my calls for help. Thank you so much!

I'm collecting patches in my git repo at
https://repo.or.cz/qemu/armbru.git in branch shadow-next. All but the last two are in a pending pull request.

Quoted 8 lines
Quoted 8 lines

My test build is down to seven files with warnings. "[PATCH v2 0/3]
hexagon: GETPC() and shadowing fixes" takes care of four, but it needs a rebase.

Remaining three:

In file included from ../hw/display/virtio-gpu-virgl.c:19:
../hw/display/virtio-gpu-virgl.c: In function

‘virgl_cmd_submit_3d’:

Quoted 6 lines
Quoted 6 lines
     /work/armbru/qemu/include/hw/virtio/virtio-gpu.h:228:16: warning:
declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
       228 |         size_t
s;                                                       \
           |                ^
     ../hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of

macro

Quoted 4 lines
Quoted 4 lines

‘VIRTIO_GPU_FILL_CMD’

       215 |     VIRTIO_GPU_FILL_CMD(cs);
           |     ^~~~~~~~~~~~~~~~~~~
     ../hw/display/virtio-gpu-virgl.c:213:12: note: shadowed

declaration

Quoted 7 lines
Quoted 7 lines

is here
213 | size_t s;
| ^

In file included from ../contrib/vhost-user-gpu/virgl.h:18,
from ../contrib/vhost-user-gpu/virgl.c:17:
../contrib/vhost-user-gpu/virgl.c: In function

‘virgl_cmd_submit_3d’:

Quoted 1 line
Quoted 1 line
     ../contrib/vhost-user-gpu/vugpu.h:167:16: warning: declaration of

‘s’

Quoted 5 lines
Quoted 5 lines

shadows a previous local [-Wshadow=compatible-local]
167 | size_t

s;                                               \
           |                ^
     ../contrib/vhost-user-gpu/virgl.c:203:5: note: in expansion of

macro

Quoted 4 lines
Quoted 4 lines

‘VUGPU_FILL_CMD’

       203 |     VUGPU_FILL_CMD(cs);
           |     ^~~~~~~~~~~~~~
     ../contrib/vhost-user-gpu/virgl.c:201:12: note: shadowed

declaration

Quoted 15 lines
Quoted 15 lines

is here
201 | size_t s;
| ^

../contrib/vhost-user-gpu/vhost-user-gpu.c: In function
‘vg_resource_flush’:

     ../contrib/vhost-user-gpu/vhost-user-gpu.c:837:29: warning:

declaration of ‘i’ shadows a previous local [-Wshadow=local]
837 | pixman_image_t *i =
| ^
../contrib/vhost-user-gpu/vhost-user-gpu.c:757:9: note: shadowed
declaration is here

       757 |     int i;
           |         ^
Quoted 7 lines
Quoted 5 lines

Gerd, Marc-André, or anybody else?

More warnings may lurk in code my test build doesn't compile. Need a full CI build with -Wshadow=local to find them. Anybody care to kick one off?

I ran a build here (with -Werror enabled, so that it's easier to see

where

Quoted 5 lines

it breaks):

https://gitlab.com/thuth/qemu/-/pipelines/1028023489

... but I didn't see any additional spots in the logs beside the ones

that

Quoted 1 line

you already listed.

After adding two more patches to fix the above warnings, things look pretty
good:

Quoted 6 lines

https://gitlab.com/thuth/qemu/-/pipelines/1028413030

There are just some warnings left in the BSD code, as Warner already mentioned in his reply to v2 of your mail:

https://gitlab.com/thuth/qemu/-/jobs/5241420713

I think I have fixes for these. I need to merge what just landed into bsd-user fork, rebase, test, the apply them to qemu master branch, retest and send them off...

My illness has hung on longer than I thought so I'm still behind...

Warner

Quoted 3 lines

Thomas

#4 lore raw
Quoted 17 lines · Warner Losh
Quoted 15 lines · Thomas Huth
Quoted 14 lines · Thomas Huth
Quoted 13 lines · Markus Armbruster

Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".

Enabling -Wshadow would prevent bugs like this one. But we have to clean up all the offenders first.

Quite a few people responded to my calls for help. Thank you so much!

I'm collecting patches in my git repo at
https://repo.or.cz/qemu/armbru.git in branch shadow-next. All but the last two are in a pending pull request.

[...]

Quoted 21 lines
Quoted 21 lines
Quoted 11 lines
Quoted 3 lines

More warnings may lurk in code my test build doesn't compile. Need a full CI build with -Wshadow=local to find them. Anybody care to kick one off?

I ran a build here (with -Werror enabled, so that it's easier to see where it breaks):

https://gitlab.com/thuth/qemu/-/pipelines/1028023489

... but I didn't see any additional spots in the logs beside the ones that you already listed.

After adding two more patches to fix the above warnings, things look pretty
good:

https://gitlab.com/thuth/qemu/-/pipelines/1028413030

There are just some warnings left in the BSD code, as Warner already mentioned in his reply to v2 of your mail:

Quoted 8 lines
Quoted 1 line

https://gitlab.com/thuth/qemu/-/jobs/5241420713

I think I have fixes for these. I need to merge what just landed into bsd-user fork, rebase, test, the apply them to qemu master branch, retest and send them off...

My illness has hung on longer than I thought so I'm still behind...

Get well, and looking forward to your patches!

#5 lore raw
In reply to Warner Losh
Quoted 104 lines · Warner Losh

On Fri, Oct 6, 2023, 11:55 AM Thomas Huth <[email protected] <mailto:[email protected]>> wrote:

On 06/10/2023 18.18, Thomas Huth wrote:
> On 06/10/2023 16.45, Markus Armbruster wrote:
>> Local variables shadowing other local variables or parameters make the >> code needlessly hard to understand.  Bugs love to hide in such code. >> Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail >> on polling error".
>>
>> Enabling -Wshadow would prevent bugs like this one.  But we have to >> clean up all the offenders first.
>>
>> Quite a few people responded to my calls for help.  Thank you so much! >>
>> I'm collecting patches in my git repo at
>> https://repo.or.cz/qemu/armbru.git
<https://repo.or.cz/qemu/armbru.git> in branch shadow-next.  All but the
>> last two are in a pending pull request.
>>
>> My test build is down to seven files with warnings.  "[PATCH v2 0/3] >> hexagon: GETPC() and shadowing fixes" takes care of four, but it needs a >> rebase.
>>
>> Remaining three:
>>
>>      In file included from ../hw/display/virtio-gpu-virgl.c:19:
>>      ../hw/display/virtio-gpu-virgl.c: In function
‘virgl_cmd_submit_3d’:
>>      /work/armbru/qemu/include/hw/virtio/virtio-gpu.h:228:16: warning:
>> declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local] >>        228 |         size_t
>> s;                                                       \
>>            |                ^
>>      ../hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of
macro
>> ‘VIRTIO_GPU_FILL_CMD’
>>        215 |     VIRTIO_GPU_FILL_CMD(cs);
>>            |     ^~~~~~~~~~~~~~~~~~~
>>      ../hw/display/virtio-gpu-virgl.c:213:12: note: shadowed
declaration
>> is here
>>        213 |     size_t s;
>>            |            ^
>>
>>      In file included from ../contrib/vhost-user-gpu/virgl.h:18, >>                       from ../contrib/vhost-user-gpu/virgl.c:17:
>>      ../contrib/vhost-user-gpu/virgl.c: In function
‘virgl_cmd_submit_3d’:
>>      ../contrib/vhost-user-gpu/vugpu.h:167:16: warning: declaration
of ‘s’
>> shadows a previous local [-Wshadow=compatible-local]
>>        167 |         size_t
>> s;                                               \
>>            |                ^
>>      ../contrib/vhost-user-gpu/virgl.c:203:5: note: in expansion of
macro
>> ‘VUGPU_FILL_CMD’
>>        203 |     VUGPU_FILL_CMD(cs);
>>            |     ^~~~~~~~~~~~~~
>>      ../contrib/vhost-user-gpu/virgl.c:201:12: note: shadowed
declaration
>> is here
>>        201 |     size_t s;
>>            |            ^
>>
>>      ../contrib/vhost-user-gpu/vhost-user-gpu.c: In function >> ‘vg_resource_flush’:
>>      ../contrib/vhost-user-gpu/vhost-user-gpu.c:837:29: warning:
>> declaration of ‘i’ shadows a previous local [-Wshadow=local] >>        837 |             pixman_image_t *i =
>>            |                             ^
>>      ../contrib/vhost-user-gpu/vhost-user-gpu.c:757:9: note: shadowed >> declaration is here
>>        757 |     int i;
>>            |         ^
>>
>> Gerd, Marc-André, or anybody else?
>>
>> More warnings may lurk in code my test build doesn't compile.  Need a >> full CI build with -Wshadow=local to find them.  Anybody care to kick >> one off?
>
> I ran a build here (with -Werror enabled, so that it's easier to see
where
> it breaks):
>
> https://gitlab.com/thuth/qemu/-/pipelines/1028023489
<https://gitlab.com/thuth/qemu/-/pipelines/1028023489>
>
> ... but I didn't see any additional spots in the logs beside the ones
that
> you already listed.

After adding two more patches to fix the above warnings, things look pretty good:

https://gitlab.com/thuth/qemu/-/pipelines/1028413030
<https://gitlab.com/thuth/qemu/-/pipelines/1028413030>

There are just some warnings left in the BSD code, as Warner already mentioned in his reply to v2 of your mail:

Quoted 7 lines

https://gitlab.com/thuth/qemu/-/jobs/5241420713
<https://gitlab.com/thuth/qemu/-/jobs/5241420713>

I think I have fixes for these. I need to merge what just landed into bsd-user fork, rebase, test, the apply them to qemu master branch, retest and send them off...

My illness has hung on longer than I thought so I'm still behind...

Get well soon again! ... and no worries about the -Wshadow=local patches in the BSD code, there is no hurry - The BSDs are using Clang by default, so that option won't get enabled by default there anyway yet - I had to switch to GCC in the CI pipeline to trigger those, and I guess only very few people will use GCC to compile QEMU on FreeBSD.

Thomas

#6 lore raw
In reply to Markus Armbruster
Quoted 53 lines · Markus Armbruster

Local variables shadowing other local variables or parameters make the code needlessly hard to understand. Bugs love to hide in such code.
Evidence: "[PATCH v3 1/7] migration/rdma: Fix save_page method to fail on polling error".

Enabling -Wshadow would prevent bugs like this one. But we have to clean up all the offenders first.

Quite a few people responded to my calls for help. Thank you so much!

I'm collecting patches in my git repo at
https://repo.or.cz/qemu/armbru.git in branch shadow-next. All but the last two are in a pending pull request.

My test build is down to seven files with warnings. "[PATCH v2 0/3]
hexagon: GETPC() and shadowing fixes" takes care of four, but it needs a rebase.

Remaining three:

In file included from ../hw/display/virtio-gpu-virgl.c:19:
../hw/display/virtio-gpu-virgl.c: In function ‘virgl_cmd_submit_3d’:
/work/armbru/qemu/include/hw/virtio/virtio-gpu.h:228:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
228 | size_t s; \
| ^
../hw/display/virtio-gpu-virgl.c:215:5: note: in expansion of macro ‘VIRTIO_GPU_FILL_CMD’
215 | VIRTIO_GPU_FILL_CMD(cs);
| ^~~~~~~~~~~~~~~~~~~
../hw/display/virtio-gpu-virgl.c:213:12: note: shadowed declaration is here
213 | size_t s;
| ^

In file included from ../contrib/vhost-user-gpu/virgl.h:18,
from ../contrib/vhost-user-gpu/virgl.c:17:
../contrib/vhost-user-gpu/virgl.c: In function ‘virgl_cmd_submit_3d’:
../contrib/vhost-user-gpu/vugpu.h:167:16: warning: declaration of ‘s’ shadows a previous local [-Wshadow=compatible-local]
167 | size_t s; \
| ^
../contrib/vhost-user-gpu/virgl.c:203:5: note: in expansion of macro ‘VUGPU_FILL_CMD’
203 | VUGPU_FILL_CMD(cs);
| ^~~~~~~~~~~~~~
../contrib/vhost-user-gpu/virgl.c:201:12: note: shadowed declaration is here
201 | size_t s;
| ^

../contrib/vhost-user-gpu/vhost-user-gpu.c: In function ‘vg_resource_flush’:
../contrib/vhost-user-gpu/vhost-user-gpu.c:837:29: warning: declaration of ‘i’ shadows a previous local [-Wshadow=local]
837 | pixman_image_t *i =
| ^
../contrib/vhost-user-gpu/vhost-user-gpu.c:757:9: note: shadowed declaration is here
757 | int i;
| ^

Quoted 1 line

Gerd, Marc-André, or anybody else?

Thomas posted patches:

[PATCH] hw/virtio/virtio-gpu: Fix compiler warning when compiling with -Wshadow [PATCH] contrib/vhost-user-gpu: Fix compiler warning when compiling with -Wshadow

Quoted 3 lines

More warnings may lurk in code my test build doesn't compile. Need a full CI build with -Wshadow=local to find them. Anybody care to kick one off?

Thomas did; see his reply downthread.

Thank you, Thomas!