Skip to contentSkip to conversation

Fix compiler warnings on Fedora 35 / CLang

PATCH In review Daniel P. Berrangé 3 participants 8 messages Nov 23, 2021 – Nov 24, 2021

lore
Share & tools
lore
#0 lore raw

cover Fix compiler warnings on Fedora 35 / CLang

Current QEMU git master caused compiler warnings on Fedora 35 when using CLang. It is expected to affect any distro with CLang >= 13.0.0

Since QEMU builds with -Werror by default we should fix these warnings before release, as this version of QEMU will increasing trigger the warnings as more distros pull in CLang >= 13.0.0

The spice patch was from John's series at

https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg01056.html

I pulled out this patch on its own as the above series isn't likely suitable for merging as a whole during freeze.

The clipboard patch is an alternative impl to what John posted.

Daniel P. Berrangé (1):
ui: avoid compiler warnings from unused clipboard info variable

John Snow (1):
spice: Update QXLInterface for spice >= 0.15.0

 hw/display/qxl.c        | 14 +++++++++++++-
 include/ui/qemu-spice.h |  6 ++++++
 ui/clipboard.c          |  3 +--
 ui/spice-display.c      | 11 +++++++++++
 4 files changed, 31 insertions(+), 3 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/2 ui: avoid compiler warnings from unused clipboard info variable

With latest clang 13.0.0 we get

../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]

    g_autoptr(QemuClipboardInfo) old = NULL;
                                 ^

The compiler can't tell that we only declared this variable in order to get the side effect of free'ing it when out of scope.

This pattern is a little dubious for a use of g_autoptr, so rewrite the code to avoid it.

---
 ui/clipboard.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
ui/clipboard.c +1 -2
index d7b008d62a..7672058e84 100644
@@ -44,12 +44,11 @@ void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
 
 void qemu_clipboard_update(QemuClipboardInfo *info)
 {
-    g_autoptr(QemuClipboardInfo) old = NULL;
     assert(info->selection < QEMU_CLIPBOARD_SELECTION__COUNT);
 
     notifier_list_notify(&clipboard_notifiers, info);
 
-    old = cbinfo[info->selection];
+    qemu_clipboard_info_unref(cbinfo[info->selection]);
     cbinfo[info->selection] = qemu_clipboard_info_ref(info);
 }
 
Signature · 1 line
2.33.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ui: avoid compiler warnings from unused clipboard info variable

Quoted 9 lines · Daniel P. Berrangé

With latest clang 13.0.0 we get

../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]

     g_autoptr(QemuClipboardInfo) old = NULL;
                                  ^

The compiler can't tell that we only declared this variable in order to get the side effect of free'ing it when out of scope.

Quoted 7 lines

This pattern is a little dubious for a use of g_autoptr, so rewrite the code to avoid it.

---
  ui/clipboard.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

r~

Quoted 20 lines
ui/clipboard.c +1 -2
index d7b008d62a..7672058e84 100644
@@ -44,12 +44,11 @@ void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
 
  void qemu_clipboard_update(QemuClipboardInfo *info)
  {
-    g_autoptr(QemuClipboardInfo) old = NULL;
      assert(info->selection < QEMU_CLIPBOARD_SELECTION__COUNT);
 
      notifier_list_notify(&clipboard_notifiers, info);
 
-    old = cbinfo[info->selection];
+    qemu_clipboard_info_unref(cbinfo[info->selection]);
      cbinfo[info->selection] = qemu_clipboard_info_ref(info);
  }
 
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] ui: avoid compiler warnings from unused clipboard info variable

In reply to Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé

With latest clang 13.0.0 we get

../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]

    g_autoptr(QemuClipboardInfo) old = NULL;
                                 ^

The compiler can't tell that we only declared this variable in order to get the side effect of free'ing it when out of scope.

Quoted 7 lines

This pattern is a little dubious for a use of g_autoptr, so rewrite the code to avoid it.

---
 ui/clipboard.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Tested-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] ui: avoid compiler warnings from unused clipboard info variable

In reply to Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé

With latest clang 13.0.0 we get

../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]

    g_autoptr(QemuClipboardInfo) old = NULL;
                                 ^

The compiler can't tell that we only declared this variable in order to get the side effect of free'ing it when out of scope.

Quoted 7 lines

This pattern is a little dubious for a use of g_autoptr, so rewrite the code to avoid it.

---
 ui/clipboard.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
#5 lore raw

PATCH 2/2 spice: Update QXLInterface for spice >= 0.15.0

In reply to Daniel P. Berrangé

From: John Snow <[email protected]>

spice updated the spelling (and arguments) of "attache_worker" in 0.15.0. Update QEMU to match, preventing -Wdeprecated-declarations compilations from reporting build errors.

See also:
https://gitlab.freedesktop.org/spice/spice/-/commit/974692bda1e77af92b71ed43b022439448492cb9

---
 hw/display/qxl.c        | 14 +++++++++++++-
 include/ui/qemu-spice.h |  6 ++++++
 ui/spice-display.c      | 11 +++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)
hw/display/qxl.c +13 -1
index 29c80b4289..1da6703e44 100644
@@ -517,13 +517,20 @@ static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
 
 /* spice display interface callbacks */
 
-static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
+static void interface_attached_worker(QXLInstance *sin)
 {
     PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl);
 
     trace_qxl_interface_attach_worker(qxl->id);
 }
 
+#if !(SPICE_HAS_ATTACHED_WORKER)
+static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
+{
+    interface_attached_worker(sin);
+}
+#endif
+
 static void interface_set_compression_level(QXLInstance *sin, int level)
 {
     PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl);
@@ -1131,7 +1138,12 @@ static const QXLInterface qxl_interface = {
     .base.major_version      = SPICE_INTERFACE_QXL_MAJOR,
     .base.minor_version      = SPICE_INTERFACE_QXL_MINOR,
 
+#if SPICE_HAS_ATTACHED_WORKER
+    .attached_worker         = interface_attached_worker,
+#else
     .attache_worker          = interface_attach_worker,
+#endif
+
     .set_compression_level   = interface_set_compression_level,
 #if SPICE_NEEDS_SET_MM_TIME
     .set_mm_time             = interface_set_mm_time,
include/ui/qemu-spice.h +6 -0
index 71ecd6cfd1..21fe195e18 100644
@@ -40,6 +40,12 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
 #define SPICE_NEEDS_SET_MM_TIME 0
 #endif
 
+#if defined(SPICE_SERVER_VERSION) && (SPICE_SERVER_VERSION >= 0x000f00)
+#define SPICE_HAS_ATTACHED_WORKER 1
+#else
+#define SPICE_HAS_ATTACHED_WORKER 0
+#endif
+
 #else  /* CONFIG_SPICE */
 
 #include "qemu/error-report.h"
ui/spice-display.c +11 -0
index f59c69882d..1a60cebb7d 100644
@@ -500,10 +500,17 @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
 
 /* spice display interface callbacks */
 
+#if SPICE_HAS_ATTACHED_WORKER
+static void interface_attached_worker(QXLInstance *sin)
+{
+    /* nothing to do */
+}
+#else
 static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
 {
     /* nothing to do */
 }
+#endif
 
 static void interface_set_compression_level(QXLInstance *sin, int level)
 {
@@ -702,7 +709,11 @@ static const QXLInterface dpy_interface = {
     .base.major_version      = SPICE_INTERFACE_QXL_MAJOR,
     .base.minor_version      = SPICE_INTERFACE_QXL_MINOR,
 
+#if SPICE_HAS_ATTACHED_WORKER
+    .attached_worker         = interface_attached_worker,
+#else
     .attache_worker          = interface_attach_worker,
+#endif
     .set_compression_level   = interface_set_compression_level,
 #if SPICE_NEEDS_SET_MM_TIME
     .set_mm_time             = interface_set_mm_time,
Signature · 1 line
2.33.1
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] spice: Update QXLInterface for spice >= 0.15.0

Quoted 9 lines · Daniel P. Berrangé

From: John Snow <[email protected]>

spice updated the spelling (and arguments) of "attache_worker" in 0.15.0. Update QEMU to match, preventing -Wdeprecated-declarations compilations from reporting build errors.

See also:
https://gitlab.freedesktop.org/spice/spice/-/commit/974692bda1e77af92b71ed43b022439448492cb9

Quoted 6 lines
---
  hw/display/qxl.c        | 14 +++++++++++++-
  include/ui/qemu-spice.h |  6 ++++++
  ui/spice-display.c      | 11 +++++++++++
  3 files changed, 30 insertions(+), 1 deletion(-)

r~

Tested-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] spice: Update QXLInterface for spice >= 0.15.0

In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé

From: John Snow <[email protected]>

spice updated the spelling (and arguments) of "attache_worker" in 0.15.0. Update QEMU to match, preventing -Wdeprecated-declarations compilations from reporting build errors.

See also:
https://gitlab.freedesktop.org/spice/spice/-/commit/974692bda1e77af92b71ed43b022439448492cb9

?Signed-off-by: Daniel P. Berrangé <[email protected]>?

Quoted 5 lines
---
 hw/display/qxl.c        | 14 +++++++++++++-
 include/ui/qemu-spice.h |  6 ++++++
 ui/spice-display.c      | 11 +++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)