Skip to contentSkip to conversation

Fixes for GCC13

PATCH In review Cédric Le Goater 8 participants 15 messages Mar 21, 2023 – Apr 20, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover Fixes for GCC13

Hello,

I activated a GH workflow using fedora rawhide and found out that there were a couple of compile breakage with the new GCC. Here are fixes, the first requiring more attention.

Thanks,

C.

Changes in v2:

- replaced helper routine by pragmas in util/async.c to suppress GCC warning

Cédric Le Goater (3):
async: Suppress GCC13 false positive in aio_bh_poll() target/s390x: Fix float_comp_to_cc() prototype target/ppc: Fix helper_pminsn() prototype

 target/s390x/s390x-internal.h |  3 ++-
 target/ppc/excp_helper.c      |  2 +-
 util/async.c                  | 13 +++++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/3 async: Suppress GCC13 false positive in aio_bh_poll()

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=]

  303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
      |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
  169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
      |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
  161 |     BHListSlice slice;
      |                 ^~~~~

../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
 util/async.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
util/async.c +13 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
 
     /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */
     QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="
+#endif
     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
+#if !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
 
     while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) {
         QEMUBH *bh;
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

Quoted 34 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=]

   303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
       |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
   169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
       |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
   161 |     BHListSlice slice;
       |                 ^~~~~

../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
  util/async.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
util/async.c +0 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
 
      /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */

util/async.c int aio_bh_poll(AioContext *ctx) · line 175

Quoted 10 lines
util/async.c +9 -0
      QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="

That warning parameter looks like a new one in GCC 13 ? ... so you have to check whether it's available before disabling it, otherwise this will fail with older versions of GCC. I just gave it a try with my GCC 8.5 and got this:

../../devel/qemu/util/async.c: In function ‘aio_bh_poll’:
../../devel/qemu/util/async.c:175:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
#pragma GCC diagnostic ignored "-Wdangling-pointer="

                                ^~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Thomas

What about reworking the code like this:

util/async.c +10 -4
index 21016a1ac7..b236bdfbd8 100644
@@ -156,15 +156,14 @@ void aio_bh_call(QEMUBH *bh)
 }
 
 /* Multiple occurrences of aio_bh_poll cannot be called concurrently. */
-int aio_bh_poll(AioContext *ctx)
+static int aio_bh_poll_slice(AioContext *ctx, BHListSlice *slice)
 {
-    BHListSlice slice;
     BHListSlice *s;
     int ret = 0;
 
     /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */
-    QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
-    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
+    QSLIST_MOVE_ATOMIC(&slice->bh_list, &ctx->bh_list);
+    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, slice, next);
 
     while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) {
         QEMUBH *bh;
@@ -191,6 +190,13 @@ int aio_bh_poll(AioContext *ctx)
     return ret;
 }
 
+int aio_bh_poll(AioContext *ctx)
+{
+    BHListSlice slice;
+
+    return aio_bh_poll_slice(ctx, &slice);
+}
+
 void qemu_bh_schedule_idle(QEMUBH *bh)
 {
     aio_bh_enqueue(bh, BH_SCHEDULED | BH_IDLE);

Would that work with GCC 13 and be acceptable?

Thomas

#3 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

Quoted 52 lines · Thomas Huth
Quoted 42 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=] 303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
       |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
   169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
       |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
   161 |     BHListSlice slice;
       |                 ^~~~~
../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>

---
  util/async.c | 13 +++++++++++++

  1 file changed, 13 insertions(+)
util/async.c +3 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
       /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */
       QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local 

variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */

util/async.c

Quoted 3 lines
util/async.c +3 -0
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="

That warning parameter looks like a new one in GCC 13 ? ... so you have to check whether it's available before disabling it, otherwise this will fail with older versions of GCC. I just gave it a try with my GCC 8.5 and got this:

Quoted 5 lines

../../devel/qemu/util/async.c: In function ‘aio_bh_poll’:
../../devel/qemu/util/async.c:175:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
 #pragma GCC diagnostic ignored "-Wdangling-pointer="
                                ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Just curious, does this work? (I don't have a GCC 8.5 handy)

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wdangling-pointer="

#4 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

Quoted 57 lines · Philippe Mathieu-Daudé
Quoted 50 lines · Thomas Huth
Quoted 33 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=] 303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
       |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
   169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
       |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
   161 |     BHListSlice slice;
       |                 ^~~~~
../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>

---
  util/async.c | 13 +++++++++++++

  1 file changed, 13 insertions(+)
util/async.c +0 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
       /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */

util/async.c int aio_bh_poll(AioContext *ctx) · line 174

Quoted 10 lines
util/async.c +9 -0
       QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="

That warning parameter looks like a new one in GCC 13 ? ... so you have to check whether it's available before disabling it, otherwise this will fail with older versions of GCC. I just gave it a try with my GCC 8.5 and got this:

Quoted 5 lines

../../devel/qemu/util/async.c: In function ‘aio_bh_poll’:
../../devel/qemu/util/async.c:175:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas] #pragma GCC diagnostic ignored "-Wdangling-pointer="
                                 ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Quoted 5 lines

Just curious, does this work? (I don't have a GCC 8.5 handy)

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wdangling-pointer="

Yep. That works too.

I like Thomas's proposal too. It only lacks a comment on the compile issue. Let's see what others have to say about it.

Thanks,

C.

#5 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

In reply to Thomas Huth
Quoted 94 lines · Thomas Huth
Quoted 33 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=]

   303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
       |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
   169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
       |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
   161 |     BHListSlice slice;
       |                 ^~~~~

../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
  util/async.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
util/async.c +0 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
      /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */

util/async.c int aio_bh_poll(AioContext *ctx) · line 174

Quoted 10 lines
util/async.c +9 -0
      QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="

That warning parameter looks like a new one in GCC 13 ? ... so you have to check whether it's available before disabling it, otherwise this will fail with older versions of GCC. I just gave it a try with my GCC 8.5 and got this:

../../devel/qemu/util/async.c: In function ‘aio_bh_poll’:
../../devel/qemu/util/async.c:175:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
#pragma GCC diagnostic ignored "-Wdangling-pointer="

                                ^~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Thomas

What about reworking the code like this:

util/async.c +10 -4
index 21016a1ac7..b236bdfbd8 100644
@@ -156,15 +156,14 @@ void aio_bh_call(QEMUBH *bh)
 }
 /* Multiple occurrences of aio_bh_poll cannot be called concurrently. */
-int aio_bh_poll(AioContext *ctx)
+static int aio_bh_poll_slice(AioContext *ctx, BHListSlice *slice)
 {
-    BHListSlice slice;
     BHListSlice *s;
     int ret = 0;
     /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */
-    QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
-    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
+    QSLIST_MOVE_ATOMIC(&slice->bh_list, &ctx->bh_list);
+    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, slice, next);
     while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) {
         QEMUBH *bh;
@@ -191,6 +190,13 @@ int aio_bh_poll(AioContext *ctx)
     return ret;
 }
+int aio_bh_poll(AioContext *ctx)
+{
+    BHListSlice slice;
+
+    return aio_bh_poll_slice(ctx, &slice);
+}
+
 void qemu_bh_schedule_idle(QEMUBH *bh)
 {
     aio_bh_enqueue(bh, BH_SCHEDULED | BH_IDLE);
 
Quoted 1 line

Would that work with GCC 13 and be acceptable?

Fine by me. Please add a comment into aio_bh_poll() explaining that this wrapper function exists to silence the gcc dangling-pointer warning. Otherwise someone may be tempted to remove the function.

Stefan

#6 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

Quoted 95 lines · Stefan Hajnoczi
Quoted 94 lines · Thomas Huth
Quoted 33 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=]

    303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
        |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
    169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
        |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
    161 |     BHListSlice slice;
        |                 ^~~~~

../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
   util/async.c | 13 +++++++++++++
   1 file changed, 13 insertions(+)
util/async.c +0 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
       /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */

util/async.c int aio_bh_poll(AioContext *ctx) · line 174

Quoted 10 lines
util/async.c +9 -0
       QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="

That warning parameter looks like a new one in GCC 13 ? ... so you have to check whether it's available before disabling it, otherwise this will fail with older versions of GCC. I just gave it a try with my GCC 8.5 and got this:

../../devel/qemu/util/async.c: In function ‘aio_bh_poll’:
../../devel/qemu/util/async.c:175:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
#pragma GCC diagnostic ignored "-Wdangling-pointer="

                                 ^~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Thomas

What about reworking the code like this:

util/async.c +10 -4
index 21016a1ac7..b236bdfbd8 100644
@@ -156,15 +156,14 @@ void aio_bh_call(QEMUBH *bh)
  }
  /* Multiple occurrences of aio_bh_poll cannot be called concurrently. */
-int aio_bh_poll(AioContext *ctx)
+static int aio_bh_poll_slice(AioContext *ctx, BHListSlice *slice)
  {
-    BHListSlice slice;
      BHListSlice *s;
      int ret = 0;
      /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */
-    QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
-    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
+    QSLIST_MOVE_ATOMIC(&slice->bh_list, &ctx->bh_list);
+    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, slice, next);
      while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) {
          QEMUBH *bh;
@@ -191,6 +190,13 @@ int aio_bh_poll(AioContext *ctx)
      return ret;
  }
+int aio_bh_poll(AioContext *ctx)
+{
+    BHListSlice slice;
+
+    return aio_bh_poll_slice(ctx, &slice);
+}
+
  void qemu_bh_schedule_idle(QEMUBH *bh)
  {
      aio_bh_enqueue(bh, BH_SCHEDULED | BH_IDLE);
 
Quoted 5 lines
Quoted 1 line

Would that work with GCC 13 and be acceptable?

Fine by me. Please add a comment into aio_bh_poll() explaining that this wrapper function exists to silence the gcc dangling-pointer warning. Otherwise someone may be tempted to remove the function.

IMO by using #pragmas it is clearer this is a kludge. Also we can revert this commit adding the pragmas/comment once the compiler are fixed.

#7 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

Hi

Quoted 112 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Thomas Huth
Quoted 6 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local

variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’
[-Werror=dangling-pointer=]

Quoted 1 line
Quoted 1 line
Quoted 1 line
    303 |     (head)->sqh_last = &(elm)->field.sqe_next;
            \
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
        |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

../util/async.c:169:5: note: in expansion of macro

‘QSIMPLEQ_INSERT_TAIL’

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
    169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
        |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
    161 |     BHListSlice slice;
        |                 ^~~~~

../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
   util/async.c | 13 +++++++++++++
   1 file changed, 13 insertions(+)
Quoted 6 lines
Quoted 6 lines

util/async.c int aio_bh_poll(AioContext *ctx) · line 164

Quoted 6 lines
util/async.c +0 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
       /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in

aio_bh_enqueue(). */

Quoted 4 lines
Quoted 4 lines

util/async.c int aio_bh_poll(AioContext *ctx) · line 168

Quoted 4 lines
util/async.c +3 -0
       QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local

variable

Quoted 1 line
Quoted 1 line

util/async.c int aio_bh_poll(AioContext *ctx) · line 169

Quoted 1 line
util/async.c +1 -0
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but

the

Quoted 11 lines
Quoted 11 lines

util/async.c int aio_bh_poll(AioContext *ctx) · line 174

Quoted 5 lines
util/async.c +5 -0
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="

That warning parameter looks like a new one in GCC 13 ? ... so you have to check whether it's available before disabling it, otherwise this will fail with older versions of GCC. I just gave it a try with my GCC 8.5 and got this:

Quoted 2 lines
Quoted 2 lines

../../devel/qemu/util/async.c: In function ‘aio_bh_poll’:
../../devel/qemu/util/async.c:175:32: error: unknown option after

‘#pragma GCC diagnostic’ kind [-Werror=pragmas]

Quoted 8 lines
Quoted 8 lines

#pragma GCC diagnostic ignored "-Wdangling-pointer="

                                 ^~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Thomas

What about reworking the code like this:

Quoted 7 lines

util/async.c void aio_bh_call(QEMUBH *bh) · line 157

Quoted 7 lines
util/async.c +0 -0
index 21016a1ac7..b236bdfbd8 100644
@@ -156,15 +156,14 @@ void aio_bh_call(QEMUBH *bh)
  }
  /* Multiple occurrences of aio_bh_poll cannot be called concurrently.

*/

Quoted 7 lines

util/async.c void aio_bh_call(QEMUBH *bh)

Quoted 7 lines
util/async.c +1 -2
-int aio_bh_poll(AioContext *ctx)
+static int aio_bh_poll_slice(AioContext *ctx, BHListSlice *slice)
  {
-    BHListSlice slice;
      BHListSlice *s;
      int ret = 0;
      /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in

aio_bh_enqueue(). */

Quoted 20 lines
Quoted 20 lines
util/async.c +9 -2
-    QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
-    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
+    QSLIST_MOVE_ATOMIC(&slice->bh_list, &ctx->bh_list);
+    QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, slice, next);
      while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) {
          QEMUBH *bh;
@@ -191,6 +190,13 @@ int aio_bh_poll(AioContext *ctx)
      return ret;
  }
+int aio_bh_poll(AioContext *ctx)
+{
+    BHListSlice slice;
+
+    return aio_bh_poll_slice(ctx, &slice);
+}
+
  void qemu_bh_schedule_idle(QEMUBH *bh)
  {
      aio_bh_enqueue(bh, BH_SCHEDULED | BH_IDLE);
 
Quoted 5 lines
Quoted 1 line

Would that work with GCC 13 and be acceptable?

Fine by me. Please add a comment into aio_bh_poll() explaining that this wrapper function exists to silence the gcc dangling-pointer warning. Otherwise someone may be tempted to remove the function.

Quoted 5 lines

IMO by using #pragmas it is clearer this is a kludge. Also we can revert this commit adding the pragmas/comment once the compiler are fixed.

up

fwiw,bBoth solutions look fine to me, as long as there is a comment explaining it.

Signature · 1 line
Marc-André Lureau
#8 lore raw

Re: [PATCH for-8.0 v2 1/3] async: Suppress GCC13 false positive in aio_bh_poll()

In reply to Cédric Le Goater

Hi everyone,

Fedora 38 rolled out recently. I did a distro upgrade, and Fedora 38 is now using GCC 13 ... and now I can't build QEMU without this patch.

I'll use it as is for now. It would be nice to fix this upstream though :D

Thanks,

Daniel

Quoted 52 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=]

   303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
       |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
   169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
       |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
   161 |     BHListSlice slice;
       |                 ^~~~~

../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list in following loop of the same routine. Add a pragma to silent GCC.

Cc Stefan Hajnoczi <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Daniel P. Berrangé <[email protected]>
---
  util/async.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
util/async.c +13 -0
index 21016a1ac7..de9b431236 100644
@@ -164,7 +164,20 @@ int aio_bh_poll(AioContext *ctx)
 
      /* Synchronizes with QSLIST_INSERT_HEAD_ATOMIC in aio_bh_enqueue().  */
      QSLIST_MOVE_ATOMIC(&slice.bh_list, &ctx->bh_list);
+
+    /*
+     * GCC13 [-Werror=dangling-pointer=] complains that the local variable
+     * 'slice' is being stored in the global 'ctx->bh_slice_list' but the
+     * list is emptied before this function returns.
+     */
+#if !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdangling-pointer="
+#endif
      QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
+#if !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
 
      while ((s = QSIMPLEQ_FIRST(&ctx->bh_slice_list))) {
          QEMUBH *bh;
#9 lore raw

PATCH v2 2/3 target/s390x: Fix float_comp_to_cc() prototype

In reply to Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../target/s390x/tcg/fpu_helper.c:123:5: error: conflicting types for ‘float_comp_to_cc’ due to enum/integer mismatch; have ‘int(CPUS390XState *, FloatRelation)’ {aka ‘int(struct CPUArchState *, FloatRelation)’} [-Werror=enum-int-mismatch]

123 | int float_comp_to_cc(CPUS390XState *env, FloatRelation float_compare)

      |     ^~~~~~~~~~~~~~~~
In file included from ../target/s390x/tcg/fpu_helper.c:23:
../target/s390x/s390x-internal.h:302:5: note: previous declaration of ‘float_comp_to_cc’ with type ‘int(CPUS390XState *, int)’ {aka ‘int(struct CPUArchState *, int)’}
  302 | int float_comp_to_cc(CPUS390XState *env, int float_compare);
      |     ^~~~~~~~~~~~~~~~
Cc Thomas Huth <[email protected]>
Cc Richard Henderson <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Ilya Leoshkevich <[email protected]>
Fixes 71bfd65c5f ("softfloat: Name compare relation enum")
---
 target/s390x/s390x-internal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/s390x/s390x-internal.h +2 -1
index 5d4361d35b..825252d728 100644
@@ -11,6 +11,7 @@
 #define S390X_INTERNAL_H
 
 #include "cpu.h"
+#include "fpu/softfloat.h"
 
 #ifndef CONFIG_USER_ONLY
 typedef struct LowCore {
@@ -299,7 +300,7 @@ uint32_t set_cc_nz_f128(float128 v);
 uint8_t s390_softfloat_exc_to_ieee(unsigned int exc);
 int s390_swap_bfp_rounding_mode(CPUS390XState *env, int m3);
 void s390_restore_bfp_rounding_mode(CPUS390XState *env, int old_mode);
-int float_comp_to_cc(CPUS390XState *env, int float_compare);
+int float_comp_to_cc(CPUS390XState *env, FloatRelation float_compare);
 
 #define DCMASK_ZERO             0x0c00
 #define DCMASK_NORMAL           0x0300
Signature · 1 line
2.39.2
Reviewed-by on v2 2/3
#10 lore raw

Re: [PATCH for-8.0 v2 2/3] target/s390x: Fix float_comp_to_cc() prototype

Quoted 13 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../target/s390x/tcg/fpu_helper.c:123:5: error: conflicting types for ‘float_comp_to_cc’ due to enum/integer mismatch; have ‘int(CPUS390XState *, FloatRelation)’ {aka ‘int(struct CPUArchState *, FloatRelation)’} [-Werror=enum-int-mismatch]

123 | int float_comp_to_cc(CPUS390XState *env, FloatRelation float_compare)

       |     ^~~~~~~~~~~~~~~~
In file included from ../target/s390x/tcg/fpu_helper.c:23:
../target/s390x/s390x-internal.h:302:5: note: previous declaration of ‘float_comp_to_cc’ with type ‘int(CPUS390XState *, int)’ {aka ‘int(struct CPUArchState *, int)’}
   302 | int float_comp_to_cc(CPUS390XState *env, int float_compare);
       |     ^~~~~~~~~~~~~~~~
Quoted 7 lines
Cc Thomas Huth <[email protected]>
Cc Richard Henderson <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Ilya Leoshkevich <[email protected]>
Fixes 71bfd65c5f ("softfloat: Name compare relation enum")

r~

Reviewed-by on v2 2/3
#11 lore raw

Re: [PATCH for-8.0 v2 2/3] target/s390x: Fix float_comp_to_cc() prototype

In reply to Cédric Le Goater
Quoted 37 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error :

../target/s390x/tcg/fpu_helper.c:123:5: error: conflicting types for ‘float_comp_to_cc’ due to enum/integer mismatch; have ‘int(CPUS390XState *, FloatRelation)’ {aka ‘int(struct CPUArchState *, FloatRelation)’} [-Werror=enum-int-mismatch]

123 | int float_comp_to_cc(CPUS390XState *env, FloatRelation float_compare)

       |     ^~~~~~~~~~~~~~~~
In file included from ../target/s390x/tcg/fpu_helper.c:23:
../target/s390x/s390x-internal.h:302:5: note: previous declaration of ‘float_comp_to_cc’ with type ‘int(CPUS390XState *, int)’ {aka ‘int(struct CPUArchState *, int)’}
   302 | int float_comp_to_cc(CPUS390XState *env, int float_compare);
       |     ^~~~~~~~~~~~~~~~
Cc Thomas Huth <[email protected]>
Cc Richard Henderson <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Ilya Leoshkevich <[email protected]>
Fixes 71bfd65c5f ("softfloat: Name compare relation enum")
---
  target/s390x/s390x-internal.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/s390x/s390x-internal.h +1 -0
index 5d4361d35b..825252d728 100644
@@ -11,6 +11,7 @@
  #define S390X_INTERNAL_H
 
  #include "cpu.h"
+#include "fpu/softfloat.h"
 
  #ifndef CONFIG_USER_ONLY
  typedef struct LowCore {

target/s390x/s390x-internal.h uint32_t set_cc_nz_f128(float128 v); · line 306

Quoted 8 lines
target/s390x/s390x-internal.h +1 -1
@@ -299,7 +300,7 @@ uint32_t set_cc_nz_f128(float128 v);
  uint8_t s390_softfloat_exc_to_ieee(unsigned int exc);
  int s390_swap_bfp_rounding_mode(CPUS390XState *env, int m3);
  void s390_restore_bfp_rounding_mode(CPUS390XState *env, int old_mode);
-int float_comp_to_cc(CPUS390XState *env, int float_compare);
+int float_comp_to_cc(CPUS390XState *env, FloatRelation float_compare);
 
  #define DCMASK_ZERO             0x0c00
  #define DCMASK_NORMAL           0x0300

Better to respond to v2:

#12 lore raw

PATCH v2 3/3 target/ppc: Fix helper_pminsn() prototype

In reply to Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error:

../target/ppc/excp_helper.c:2625:6: error: conflicting types for ‘helper_pminsn’ due to enum/integer mismatch; have ‘void(CPUPPCState *, powerpc_pm_insn_t)’ {aka ‘void(struct CPUArchState *, powerpc_pm_insn_t)’} [-Werror=enum-int-mismatch]
2625 | void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn)

      |      ^~~~~~~~~~~~~
In file included from /home/legoater/work/qemu/qemu.git/include/qemu/osdep.h:49,
                 from ../target/ppc/excp_helper.c:19:

/home/legoater/work/qemu/qemu.git/include/exec/helper-head.h:23:27: note: previous declaration of ‘helper_pminsn’ with type ‘void(CPUArchState *, uint32_t)’ {aka ‘void(CPUArchState *, unsigned int)’}
23 | #define HELPER(name) glue(helper_, name)
| ^~~~~~~

Cc Daniel Henrique Barboza <[email protected]>
Fixes 7778a575c7 ("ppc: Add P7/P8 Power Management instructions")
---
 target/ppc/excp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +1 -1
index 287659c74d..199328f4b6 100644
@@ -2622,7 +2622,7 @@ void helper_scv(CPUPPCState *env, uint32_t lev)
     }
 }
 
-void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn)
+void helper_pminsn(CPUPPCState *env, uint32_t insn)
 {
     CPUState *cs;
 
Signature · 1 line
2.39.2
Reviewed-by on v2 3/3
#13 lore raw

Re: [PATCH for-8.0 v2 3/3] target/ppc: Fix helper_pminsn() prototype

Quoted 13 lines · Cédric Le Goater

From: Cédric Le Goater<[email protected]>

GCC13 reports an error:

../target/ppc/excp_helper.c:2625:6: error: conflicting types for ‘helper_pminsn’ due to enum/integer mismatch; have ‘void(CPUPPCState *, powerpc_pm_insn_t)’ {aka ‘void(struct CPUArchState *, powerpc_pm_insn_t)’} [-Werror=enum-int-mismatch]
2625 | void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn)

       |      ^~~~~~~~~~~~~
In file included from /home/legoater/work/qemu/qemu.git/include/qemu/osdep.h:49,
                  from ../target/ppc/excp_helper.c:19:

/home/legoater/work/qemu/qemu.git/include/exec/helper-head.h:23:27: note: previous declaration of ‘helper_pminsn’ with type ‘void(CPUArchState *, uint32_t)’ {aka ‘void(CPUArchState *, unsigned int)’}
23 | #define HELPER(name) glue(helper_, name)
| ^~~~~~~

Quoted 7 lines
Cc Daniel Henrique Barboza<[email protected]>
Fixes 7778a575c7 ("ppc: Add P7/P8 Power Management instructions")
---
  target/ppc/excp_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

Reviewed-by on v2 3/3
#14 lore raw

Re: [PATCH for-8.0 v2 3/3] target/ppc: Fix helper_pminsn() prototype

In reply to Cédric Le Goater
Quoted 26 lines · Cédric Le Goater

From: Cédric Le Goater <[email protected]>

GCC13 reports an error:

../target/ppc/excp_helper.c:2625:6: error: conflicting types for ‘helper_pminsn’ due to enum/integer mismatch; have ‘void(CPUPPCState *, powerpc_pm_insn_t)’ {aka ‘void(struct CPUArchState *, powerpc_pm_insn_t)’} [-Werror=enum-int-mismatch]
2625 | void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn)

       |      ^~~~~~~~~~~~~
In file included from /home/legoater/work/qemu/qemu.git/include/qemu/osdep.h:49,
                  from ../target/ppc/excp_helper.c:19:

/home/legoater/work/qemu/qemu.git/include/exec/helper-head.h:23:27: note: previous declaration of ‘helper_pminsn’ with type ‘void(CPUArchState *, uint32_t)’ {aka ‘void(CPUArchState *, unsigned int)’}
23 | #define HELPER(name) glue(helper_, name)
| ^~~~~~~

Cc Daniel Henrique Barboza <[email protected]>
Fixes 7778a575c7 ("ppc: Add P7/P8 Power Management instructions")
---
  target/ppc/excp_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +0 -0
index 287659c74d..199328f4b6 100644

target/ppc/excp_helper.c void helper_scv(CPUPPCState *env, uint32_t lev) · line 2628

Quoted 8 lines
target/ppc/excp_helper.c +1 -1
@@ -2622,7 +2622,7 @@ void helper_scv(CPUPPCState *env, uint32_t lev)
      }
  }
 
-void helper_pminsn(CPUPPCState *env, powerpc_pm_insn_t insn)
+void helper_pminsn(CPUPPCState *env, uint32_t insn)
  {
      CPUState *cs;