Skip to contentSkip to conversation

hw/virtio/vhost-shadow-virtqueue: Silence GCC error "maybe-uninitialized"

PATCH Superseded Bernhard Beschow 2 participants 3 messages Sep 6, 2022 – Sep 9, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/virtio/vhost-shadow-virtqueue: Silence GCC error "maybe-uninitialized"

GCC issues a false positive warning, resulting in build failure with -Werror:

In file included from /usr/include/glib-2.0/glib.h:114,

                   from /home/zcone-pisint/Projects/qemu/src/include/glib-compat.h:32,
                   from /home/zcone-pisint/Projects/qemu/src/include/qemu/osdep.h:144,
                   from ../src/hw/virtio/vhost-shadow-virtqueue.c:10:
  In function ‘g_autoptr_cleanup_generic_gfree’,
      inlined from ‘vhost_handle_guest_kick’ at ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42:
  /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: ‘elem’ may be used uninitialized [-Werror=maybe-uninitialized]
     28 |   g_free (*pp);
        |   ^~~~~~~~~~~~
  ../src/hw/virtio/vhost-shadow-virtqueue.c: In function ‘vhost_handle_guest_kick’:
  ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42: note: ‘elem’ was declared here
    292 |             g_autofree VirtQueueElement *elem;
        |                                          ^~~~

cc1: all warnings being treated as errors

There is actually no problem since "elem" is initialized in both branches. Silence the warning by initializig it with "NULL".

Fixes 9c2ab2f1ec333be8614cc12272d4b91960704dbe ("vhost: stop transfer elem ownership in vhost_handle_guest_kick")
---
 hw/virtio/vhost-shadow-virtqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-shadow-virtqueue.c +1 -1
index e8e5bbc368..596d4434d2 100644
@@ -289,7 +289,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)
         virtio_queue_set_notification(svq->vq, false);
 
         while (true) {
-            g_autofree VirtQueueElement *elem;
+            g_autofree VirtQueueElement *elem = NULL;
             int r;
 
             if (svq->next_guest_avail_elem) {
Signature · 1 line
2.37.3
Reviewed-by Philippe Mathieu-Daudé on v1 1/1
#1 lore raw
Quoted 16 lines · Bernhard Beschow

GCC issues a false positive warning, resulting in build failure with -Werror:

In file included from /usr/include/glib-2.0/glib.h:114,

                   from /home/zcone-pisint/Projects/qemu/src/include/glib-compat.h:32,
                   from /home/zcone-pisint/Projects/qemu/src/include/qemu/osdep.h:144,
                   from ../src/hw/virtio/vhost-shadow-virtqueue.c:10:
  In function ‘g_autoptr_cleanup_generic_gfree’,
      inlined from ‘vhost_handle_guest_kick’ at ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42:
  /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: ‘elem’ may be used uninitialized [-Werror=maybe-uninitialized]
     28 |   g_free (*pp);
        |   ^~~~~~~~~~~~
  ../src/hw/virtio/vhost-shadow-virtqueue.c: In function ‘vhost_handle_guest_kick’:
  ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42: note: ‘elem’ was declared here
    292 |             g_autofree VirtQueueElement *elem;
        |                                          ^~~~
Quoted 4 lines

cc1: all warnings being treated as errors

There is actually no problem since "elem" is initialized in both branches. Silence the warning by initializig it with "NULL".

Could you amend the first line of gcc --version?

Quoted 23 lines
Fixes 9c2ab2f1ec333be8614cc12272d4b91960704dbe ("vhost: stop transfer elem ownership in vhost_handle_guest_kick")
---
 hw/virtio/vhost-shadow-virtqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-shadow-virtqueue.c +1 -2
index e8e5bbc368..596d4434d2 100644
@@ -289,7 +289,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)
         virtio_queue_set_notification(svq->vq, false);
 
         while (true) {
-            g_autofree VirtQueueElement *elem;
+            g_autofree VirtQueueElement *elem = NULL;
             int r;
 
             if (svq->next_guest_avail_elem) {
--

2.37.3

#2 lore raw

Am 6. September 2022 17:52:24 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 19 lines · Bernhard Beschow
Quoted 18 lines

GCC issues a false positive warning, resulting in build failure with -Werror:

In file included from /usr/include/glib-2.0/glib.h:114,

                   from /home/zcone-pisint/Projects/qemu/src/include/glib-compat.h:32,
                   from /home/zcone-pisint/Projects/qemu/src/include/qemu/osdep.h:144,
                   from ../src/hw/virtio/vhost-shadow-virtqueue.c:10:
  In function ‘g_autoptr_cleanup_generic_gfree’,
      inlined from ‘vhost_handle_guest_kick’ at ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42:
  /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: ‘elem’ may be used uninitialized [-Werror=maybe-uninitialized]
     28 |   g_free (*pp);
        |   ^~~~~~~~~~~~
  ../src/hw/virtio/vhost-shadow-virtqueue.c: In function ‘vhost_handle_guest_kick’:
  ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42: note: ‘elem’ was declared here
    292 |             g_autofree VirtQueueElement *elem;
        |                                          ^~~~

cc1: all warnings being treated as errors

Quoted 4 lines
Quoted 2 lines

There is actually no problem since "elem" is initialized in both branches. Silence the warning by initializig it with "NULL".

Could you amend the first line of gcc --version?

Hi Phil,

Yes, will do in v2.

Sorry for getting off-topic, but have you recognized my vt82c686 series? Your opinion would matter there and I'm not sure if my mail bounced. In my case Gmail likes to put your mail in the spam box :/

Regards,
Bernhard

Quoted 26 lines
Quoted 23 lines
Fixes 9c2ab2f1ec333be8614cc12272d4b91960704dbe ("vhost: stop transfer elem ownership in vhost_handle_guest_kick")
---
 hw/virtio/vhost-shadow-virtqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-shadow-virtqueue.c +1 -2
index e8e5bbc368..596d4434d2 100644
@@ -289,7 +289,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)
         virtio_queue_set_notification(svq->vq, false);
 
         while (true) {
-            g_autofree VirtQueueElement *elem;
+            g_autofree VirtQueueElement *elem = NULL;
             int r;
 
             if (svq->next_guest_avail_elem) {
--

2.37.3