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

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


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 4 Jul 2023 16:58:33 +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=G9jJ7pFCGUg0kAolaJLhlV6C5YYLvflxrUyGM+T3uJU=; b=GLAAjucG6y7Yl4YbRoP5o5p7eUauxGI0GzFUplb96IqwEjp1eUaHM5S1nnsv6OxGv1MnzW5q9q3T1QTNlb4DFuY+yYOAz5+VXIR46tcyTuBab6eJDnvZuF7LF2vM1HUSZ9l1l+c7p9mf8wwvt/MLwi6LMXiMLitA3orZo3eKS90ano2JvaljWXNt0NjaLhluDgvs5w/zY4yP+u9QN0eFRe2UsCATOzp/G8xnQtRVXEHt/eOOfhxdTtILcQVr0J7KHa0W9fHJwm4Q30Fii+9Gmm5c2JHqVdWK9q5eugq2g3dd8iGrCrBRLNT6p23cj8SKZx0j2InkbGn+ido5KtGWTw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lpW7+gYYXnrZQmFckHZzpUKZzKl01gGtmaFdFelErASWJbLHX1+4L3iU2K/iMCt6v+6p1YC8JumRj64hJsRzf1WcwNnalA9pgK8hvu3UufKm5j5E2GE24TGgskhZ+rSu+AZJ1qfLfMW4RP5ZXGWpdTOaa0jJwgKC+C/tOxdg9f1yZSZ8yXB+XwsewTjI+KeCJPGMwHqYIFnGibBtwrWphvPjSFJ1g5CUxGOfwK6t/gg41nW19Sm2lXgOqf6etJxL4ZYQLAfX2XMFjakNAQuvgiE22587k7AGgfBg3ZchxxL4BTBcEfrTHW+tUTi3NR456Fl+gx5r76mxNdjDJ7WxuQ==
  • 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: Tue, 04 Jul 2023 14:58:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 04.07.2023 16:53, Nicola Vetrini wrote:
> 
> 
> On 04/07/23 16:24, Jan Beulich wrote:
>> On 26.06.2023 17:37, Nicola Vetrini wrote:
>>> Redefine BUILD_BUG_ON_ZERO to avoid using a compiler extension
>>> that gives an acceptable semantics to C99 undefined behavior 58
>>> ("A structure or union is defined as containing no named members
>>> (6.7.2.1)").
>>>
>>> The first definition includes an additional named field of type
>>> char.
>>>
>>> The chosen ill-formed construct for the second definition is a struct
>>> with a named bitfield of width 0 when the condition is true,
>>> which prevents the UB without using the compiler extension while keeping
>>> the semantic of the construct.
>>>
>>> The choice of the bitwise AND operation to bring the result to 0
>>> when cond is false boils down to possibly better portability.
>>>
>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
>>
>> The code change looks okay to me now, but I'd like to double check
>> towards the testing you did with this change: While it is clear that
>> you will have checked that the tree builds with the adjustments, I
>> expect that would have been with a compiler supporting _Static_assert.
>> Did you also check with an older compiler, using the alternative
>> implementation? Plus did you also check both constructs for actually
>> triggering when the supplied condition turns out to be true?
> 
> Besides using the build pipelines in gitlab, I checked just the macro on 
> Compiler Explorer using gcc 4.4.7 and clang 16 
> (https://godbolt.org/z/1d6vznxcW) and the construct is behaving as expected.

Great, thanks for confirming.

Jan



 


Rackspace

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