From nobody Fri May 10 06:23:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686825057708570.7508130999352; Thu, 15 Jun 2023 03:30:57 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version 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 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1686825059659100001 Content-Type: text/plain; charset="utf-8" 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_); \ }) =20 -/* All clang versions supported by Xen have _Static_assert. */ -#if defined(__clang__) || \ - (__GNUC__ > 4 || (__GNUC__ =3D=3D 4 && __GNUC_MINOR__ >=3D 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 =20 #ifndef NDEBUG #define ASSERT(p) \ --=20 2.34.1