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

Re: [XEN PATCH] xen/include/xen/lib.h: avoid undefined behavior.


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 15 Jun 2023 14:23:11 +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=2QUprFQF0h8870RPvKwiYQmm8QryBFOrTZhglpSVI+s=; b=CFkkJgYpWYImAfQAf4E3xAdt7zw+kJ30U/3CesoFHKQM3J9v0c8QsNG+5r1/R7rhiCpMs3Aj1dNSXcGV3FGvGR7+nDlBduKHLjBHoKgVcrhXwWkkZpuMNRy7Xo7Ydi6khbdcTB/oMCtBXIRuz5PtJ63e6fOG8ix13jMozPrurkVCF1UvEUFCdzD4qWnlIV0DlH5Ep4w9J66sRoEQYYuDriX9hay/7PtF3R4CPi/0+MUtvpZsT0Vpd4+0RRegOTUSwgTPsQWtKoFnQlXbOzI61M4VvSlUmddPdSzs0eC4VhmpRzkZeqV4ebspU7b8MMv/V2BSVNF6vDMni2icpz2vtg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z6ErRZpFH7HK8KM1178UeXbBTWp59C1hLQT1h9QdNRVSXToaomgExFKifz5z5toRgjRG7iHgAvFMTUkRnEUG8cpIwp3dJ5Ack4dJLbkR4DEWNft/YbO92yv6i4BHKGUitVm1PODLiiJNhVqnqTAfs64Ju7Oao6tzTRGL7pUkS4zpvkbbUl+S65RrXCqRvsxZahKem3VaFq+Ncd4FUBLciN0Cug1jWz7u1d+VXFOTgXTEm65pXsvNVKl/Y0wYby1fx3+Z8ex4zaC9OEYr3/xLcVqcwqx/sk2roxnQckh6JNuJZ5Tcs3avz8I65lLXEewTJuuNCmXhn2rd6PBLPdhsqA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: consulting@xxxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 15 Jun 2023 12:23:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 15.06.2023 12:30, Nicola Vetrini wrote:
> --- 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)

In addition to what Andrew has said, I'd further like to ask that you
try to first understand why certain things are the way they are, by
looking at history. We did use an array here up to commit c8e857a0aff3,
and if you go there you'll find an explanation why it wants to be
something else.

Jan



 


Rackspace

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