From patchwork Thu Jun 15 10:30:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13281033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B793FEB64D9 for ; Thu, 15 Jun 2023 10:30:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549524.858102 (Exim 4.92) (envelope-from ) id 1q9kFI-0001rv-Lg; Thu, 15 Jun 2023 10:30:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549524.858102; Thu, 15 Jun 2023 10:30:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9kFI-0001ro-Iv; Thu, 15 Jun 2023 10:30:28 +0000 Received: by outflank-mailman (input) for mailman id 549524; Thu, 15 Jun 2023 10:30:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9kFH-0001ri-K1 for xen-devel@lists.xenproject.org; Thu, 15 Jun 2023 10:30:27 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a3c5a7bf-0b67-11ee-b232-6b7b168915f2; Thu, 15 Jun 2023 12:30:25 +0200 (CEST) Received: from nico.bugseng.com (unknown [151.57.87.217]) by support.bugseng.com (Postfix) with ESMTPSA id 32E2B4EE0738; Thu, 15 Jun 2023 12:30:23 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a3c5a7bf-0b67-11ee-b232-6b7b168915f2 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Nicola Vetrini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [XEN PATCH] xen/include/xen/lib.h: avoid undefined behavior. Date: Thu, 15 Jun 2023 12:30:15 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Redefine BUILD_BUG_ON_ZERO to fully comply with C99 avoiding undefined behavior 58 ("A structure or union is defined as containing no named members (6.7.2.1)." This also avoids a dependency on the compiler and its version. Signed-off-by: Nicola Vetrini --- xen/include/xen/lib.h | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 67fc7c1d7e..a266159b9f 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -40,22 +40,8 @@ unlikely(ret_warn_on_); \ }) -/* All clang versions supported by Xen have _Static_assert. */ -#if defined(__clang__) || \ - (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) -/* Force a compilation error if condition is true */ -#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) - -/* Force a compilation error if condition is true, but also produce a - result (of value 0 and type size_t), so the expression can be used - e.g. in a structure initializer (or where-ever else comma expressions - aren't permitted). */ -#define BUILD_BUG_ON_ZERO(cond) \ - sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); }) -#else -#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); }) +#define BUILD_BUG_ON_ZERO(cond) (sizeof(char[(cond)? -1 : 1]) - 1U) #define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond)) -#endif #ifndef NDEBUG #define ASSERT(p) \