From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [RFC 3/8] eal: add macro to disable shadow warnings
Date: Wed, 27 Aug 2025 16:14:06 -0700 [thread overview]
Message-ID: <20250827231528.236172-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20250827231528.236172-1-stephen@networkplumber.org>
When using constructs like:
RTE_MIN(x, RTE_MIN(y, z))
the compiler would generate warnings about overlapping definitions
of the variables in the macro. This is safe so add pragma support
to silence the problem.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/include/rte_common.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 9e7d84f929..34862cc97a 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -210,6 +210,15 @@ typedef uint16_t unaligned_uint16_t;
#define __rte_diagnostic_ignored_wcast_qual
#endif
+/**
+ * Macro to disable compiler warnings about shadow declaration.
+ */
+#if !defined(RTE_TOOLCHAIN_MSVC)
+#define __rte_diagnostic_ignored_shadow _Pragma("GCC diagnostic ignored \"-Wshadow\"")
+#else
+#define __rte_diagnostic_ignored_shadow
+#endif
+
/**
* Mark a function or variable to a weak reference.
*/
@@ -791,12 +800,17 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
/**
* Macro to return the minimum of two numbers
+ * Need to disable warnings about shadowed variables to allow
+ * for nested usage.
*/
#define RTE_MIN(a, b) \
__extension__ ({ \
+ __rte_diagnostic_push \
+ __rte_diagnostic_ignored_shadow \
typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _a : _b; \
+ __rte_diagnostic_pop \
})
/**
@@ -814,9 +828,12 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
*/
#define RTE_MAX(a, b) \
__extension__ ({ \
+ __rte_diagnostic_push \
+ __rte_diagnostic_ignored_shadow \
typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; \
+ __rte_diagnostic_pop \
})
/**
--
2.47.2
next prev parent reply other threads:[~2025-08-27 23:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 23:14 [RFC 0/8] Avoid overlapping declarations Stephen Hemminger
2025-08-27 23:14 ` [RFC 1/8] test/ring: avoid shadow variable usage Stephen Hemminger
2025-08-28 7:42 ` Bruce Richardson
2025-08-27 23:14 ` [RFC 2/8] test/table: replace conflicting variable name Stephen Hemminger
2025-08-27 23:14 ` Stephen Hemminger [this message]
2025-08-28 7:43 ` [RFC 3/8] eal: add macro to disable shadow warnings Bruce Richardson
2025-08-27 23:14 ` [RFC 4/8] eal: avoid shadowed variable aligned_end Stephen Hemminger
2025-08-27 23:14 ` [RFC 5/8] eal: avoid shadowed variables in trace code Stephen Hemminger
2025-08-27 23:14 ` [RFC 6/8] ethdev: avoid shadowed variable warnings Stephen Hemminger
2025-08-27 23:14 ` [RFC 7/8] telemetry: avoid potential name conflict for handler Stephen Hemminger
2025-08-28 7:45 ` Bruce Richardson
2025-08-27 23:14 ` [RFC 8/8] pcapng: avoid shadow declaration warning Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250827231528.236172-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=roretzla@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).