[v13,1/3] eal: add diagnostics macros to make code portable
Checks
Commit Message
It was a common pattern to have "GCC diagnostic ignored" pragmas
sprinkled over the code and only activate these pragmas for certain
compilers (gcc and clang). Clang supports GCC's pragma for
compatibility with existing source code, so #pragma GCC diagnostic
and #pragma clang diagnostic are synonyms for Clang
(https://clang.llvm.org/docs/UsersManual.html).
Now that effort is being made to make the code compatible with MSVC
these expressions would become more complex. It makes sense to hide
this complexity behind macros. This makes maintenance easier as these
macros are defined in a single place. As a plus the code becomes
more readable as well.
Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
lib/eal/include/rte_common.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
@@ -156,6 +156,35 @@ typedef uint16_t unaligned_uint16_t;
#define RTE_DEPRECATED(x)
#endif
+/*
+ * Macros to cause the compiler to remember the state of the diagnostics as of
+ * each push, and restore to that point at each pop.
+ */
+#if !defined(__INTEL_COMPILER) && !defined(RTE_TOOLCHAIN_MSVC)
+#define __rte_diagnostic_push _Pragma("GCC diagnostic push")
+#define __rte_diagnostic_pop _Pragma("GCC diagnostic pop")
+#else
+#define __rte_diagnostic_push
+#define __rte_diagnostic_pop
+#endif
+
+/*
+ * Macro to disable compiler warnings about removing a type
+ * qualifier from the target type.
+ */
+#if !defined(__INTEL_COMPILER) && !defined(RTE_TOOLCHAIN_MSVC)
+#define __rte_diagnostic_ignored_wcast_qual \
+ _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
+#else
+#define __rte_diagnostic_ignored_wcast_qual
+#endif
+
+/*
+ * Macro to disable compiler warnings about removing a type
+ * qualifier from a pointer.
+ */
+#define RTE_PTR_DROP_QUALIFIERS(X) ((void *)(uintptr_t)(X))
+
/**
* Mark a function or variable to a weak reference.
*/