[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH v3] xen/include: avoid using a compiler extension for BUILD_BUG_ON_ZERO.


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 22 Jun 2023 10:56:59 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tfoinNXLdfvGfuSX4JYQ41+3P9uPb+XyS+vBKZ+ffh4=; b=RdI6c+Q7OXTopeQFZ5EC9CJVbCcfQAfRmbd7lonzqMrw7KjAujsS8xcwAdWlzIhqEAWJrgGw/siEz/tX0eYByz0zu4kljpxF0ECjDrTCVZ8bMjKbcQ8C27FSJLR/Ke1Fy2EvpY+NhEX8jKIkSHVO+0m4lcJoTtv4VtkfgnbRBVYyG7EmKlJmvnY8VD5f+jAmOlx2Nlzaiv3/uKqYEhqqM02PWob6EFT9Nlh+9x6/ib1uSR0VRvITDlfFEKG4t48Ry0JlTGbPd4X+ao8Syi6qy2qpsRCsW78FVeE4SA8sCGVnkAGeP3lmHTQ8/+V7nig6YMhW4GDKOn5wi9gwNGLk9A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NeiV7+awlN7hqUDwDL6k3uzD3b3RvpdBZuJ75/sEimMsEjOM3UDibrZYMQs/d72er0Sx5KS3A6BVLbhy6kLUXOSi5cPuhuqgsf0NJLdKSKvyhjk9+EYIZSJFhtPD+AV51L6FU6k6D4uTYXEKKBJ87BDHsX0/sS+6ItX5Wl3eQb6RCOBWt2A+AoV17qzqJEVFPmBIl8V/ExWQGBojJGP0MNs+ZBhJRokMGOXfjljSVlLhT56tBKrcUr3ydPIde64hO4XHmECWrM5ZivgXlIgLMhC0Z4AqnUHUjd/bm5dwYuoOgtOgtjjQkRuZnwMUS7dQZ0eJHmfTA2bPPROD79zyYQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: sstabellini@xxxxxxxxxx, michal.orzel@xxxxxxx, xenia.ragiadakou@xxxxxxx, ayan.kumar.halder@xxxxxxx, consulting@xxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger.pau@xxxxxxxxxx, bertrand.marquis@xxxxxxx, julien@xxxxxxx, George Dunlap <george.dunlap@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 22 Jun 2023 08:57:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 22.06.2023 10:24, Nicola Vetrini wrote:
> --- a/xen/include/xen/lib.h
> +++ b/xen/include/xen/lib.h
> @@ -51,9 +51,10 @@
>     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 ")"); })
> +    (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 
> 0U)
>  #else
> -#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
> +#define BUILD_BUG_ON_ZERO(cond) \
> +    (sizeof(struct { unsigned u : (cond) ? -1 : 1; }) & 0U)

Given your remark on named bitfields not being allowed to be zero length
(which hopefully holds universally, i.e. isn't subject to compiler
extensions), how about

#define BUILD_BUG_ON_ZERO(cond) (sizeof(struct { int _:!(cond); }) & 0)

? (Implicitly, as said before, I question the value of the U suffixes here.
Even better might be to make sure the expression is explicitly not of
unsigned type, to avoid surprises if someone used ~BUILD_BUG_ON_ZERO()
somewhere.)

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.