[RFC 3/8] eal: add macro to disable shadow warnings

Stephen Hemminger stephen at networkplumber.org
Thu Aug 28 01:14:06 CEST 2025


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 at 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



More information about the dev mailing list