From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5B43345F52; Fri, 27 Dec 2024 02:33:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DB42F402D4; Fri, 27 Dec 2024 02:33:28 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id D04B340294 for ; Fri, 27 Dec 2024 02:33:26 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 1B02D203EC29; Thu, 26 Dec 2024 17:33:26 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1B02D203EC29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1735263206; bh=iRaXaqUlFwHE0ZMA0Y5nYI1uwptXOXSvjCGnXEihBOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axzwlDIyIbdwRHMlkkRpgEB0r6xP/yGC1lZPiUEoG+lzIpCFiYzhOKK0mjjLZecDC zu/Dgg7BKCL6ov8rhZ3TpflzT/kKojYMPZ+J/7n1Wsrse2plXOIKEZmcDDj91DmebM XOHZhllzoIM4v5m4HhkaLuJF9KOvwWZdyXuaPVPc= From: Andre Muezerie To: Tyler Retzlaff Cc: dev@dpdk.org, Andre Muezerie Subject: [PATCH 1/3] lib/eal: add diagnostics macros to make code portable Date: Thu, 26 Dec 2024 17:33:14 -0800 Message-Id: <1735263196-2809-2-git-send-email-andremue@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1735263196-2809-1-git-send-email-andremue@linux.microsoft.com> References: <1735263196-2809-1-git-send-email-andremue@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- lib/eal/include/rte_common.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 4d299f2b36..c5f91730ef 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -137,6 +137,40 @@ typedef uint16_t unaligned_uint16_t; #define RTE_DEPRECATED(x) #endif +/* + * Macro to ignore whenever a pointer is cast so as to remove 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 ignore code that might break the strict aliasing rules that + * the compiler is using for optimization. + */ +#if !defined __INTEL_COMPILER && !defined RTE_TOOLCHAIN_MSVC +#define __rte_diagnostic_ignored_wstrict_aliasing \ + _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") +#else +#define __rte_diagnostic_ignored_wstrict_aliasing +#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 + /** * Mark a function or variable to a weak reference. */ -- 2.47.0.vfs.0.3