Commit d4b52cf2 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

include: suppress Wdangling-pointer warnings in queue_extras.h



Newer versions of gcc (13) are reporting bogus warnings when doing a
TAILQ_SWAP() with a tailq declared on stack.  For example:

In file included from /src/spdk-2/include/spdk/queue.h:22,
                 from /src/spdk-2/include/spdk/dma.h:14,
                 from /src/spdk-2/include/spdk/accel.h:15,
                 from /src/spdk-2/include/spdk/accel_module.h:12,
                 from accel.c:9:
accel.c: In function ‘spdk_accel_sequence_reverse’:
/src/spdk-2/include/spdk/queue_extras.h:344:27: error: storing the address of local variable ‘tasks’ in ‘*seq.tasks.tqh_last’ [-Werror=dangling-pointer=]
  344 |         (head2)->tqh_last = swap_last;                                  \
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
accel.c:1926:9: note: in expansion of macro ‘TAILQ_SWAP’
 1926 |         TAILQ_SWAP(&tasks, &seq->tasks, spdk_accel_task, seq_link);
      |         ^~~~~~~~~~
accel.c:1922:37: note: ‘tasks’ declared here
 1922 |         struct accel_sequence_tasks tasks = TAILQ_HEAD_INITIALIZER(tasks);
      |                                     ^~~~~

The address of a local variable is indeed stored in tqh_last, but a few
lines later it is overwritten (tqh_first is NULL in this case, because
it's initialized by TAILQ_HEAD_INITIALIZER):

if ((swap_first = (head2)->tqh_first) != NULL)			\
	swap_first->field.tqe_prev = &(head2)->tqh_first;	\
else								\
	(head2)->tqh_last = &(head2)->tqh_first;		\

So, suppress those warnings if using gcc-13 and up.

Fixes #3030.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I0c6d68bcfef29b345f968832ba62114e5a639ffa
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18439


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKamil Godzwon <kamilx.godzwon@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent a214d48d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -106,6 +106,18 @@
 *
 */

/* gcc-13 reports bogus Wdangling-pointer warnings on some of the macros below (see issue #3030) */
#if defined(__GNUC__) && (__GNUC__ >= 13)
#define SPDK_QE_SUPPRESS_WARNINGS() do {				\
	_Pragma("GCC diagnostic push")					\
	_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\"")	\
} while (0)
#define SPDK_QE_UNSUPPRESS_WARNINGS() _Pragma("GCC diagnostic pop")
#else
#define SPDK_QE_SUPPRESS_WARNINGS()
#define SPDK_QE_UNSUPPRESS_WARNINGS()
#endif

/*
 * Singly-linked Tail queue declarations.
 */
@@ -323,6 +335,7 @@ struct { \
	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))

#define TAILQ_SWAP(head1, head2, type, field) do {			\
	SPDK_QE_SUPPRESS_WARNINGS();					\
	struct type *swap_first = (head1)->tqh_first;			\
	struct type **swap_last = (head1)->tqh_last;			\
	(head1)->tqh_first = (head2)->tqh_first;			\
@@ -337,6 +350,7 @@ struct { \
		swap_first->field.tqe_prev = &(head2)->tqh_first;	\
	else								\
		(head2)->tqh_last = &(head2)->tqh_first;		\
	SPDK_QE_UNSUPPRESS_WARNINGS();					\
} while (0)

#endif