From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Roberto Bagnara" <roberto.bagnara@bugseng.com>,
"consulting @ bugseng . com" <consulting@bugseng.com>
Subject: Re: [PATCH] xen: Use __auto_type
Date: Mon, 05 May 2025 14:57:16 +0200 [thread overview]
Message-ID: <707b9f833fd4cd0341ad09cbc3265ec9@bugseng.com> (raw)
In-Reply-To: <20250505124646.1569767-1-andrew.cooper3@citrix.com>
On 2025-05-05 14:46, Andrew Cooper wrote:
> In macros it is common to declare local variables using typeof(param)
> in order
> to ensure that side effects are only evaluated once. A consequence of
> this is
> double textural expansion of the parameter, which can get out of hand
> very
> quickly with nested macros.
>
> A GCC extension, __auto_type, is now avaialble in the new toolchain
> baseline
> and avoids the double textural expansion.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Anthony PERARD <anthony.perard@vates.tech>
> CC: Michal Orzel <michal.orzel@amd.com>
> CC: Jan Beulich <jbeulich@suse.com>
> CC: Julien Grall <julien@xen.org>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Roberto Bagnara <roberto.bagnara@bugseng.com>
> CC: Nicola Vetrini <nicola.vetrini@bugseng.com>
> CC: consulting@bugseng.com <consulting@bugseng.com>
>
> The resulting build is identical.
>
> RFC. This requires a MISRA change, as it currently manifests as a R1.1
> violation. Nevertheless, I think we want to start using in places
> where we
> currently use typeof(expression of <initilaiser>).
>
> Eclair run on this patch (expecting a failure):
>
> https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1800631949
>
Hi,
to make the analysis pass you need a couple of hunks in
eclair_analysis/ECLAIR/toolchain.ecl:
-name_selector+={auto_type, "^__auto_type$"}
and add auto_type to the STD.tokenext config below around line 25, then
later
-name_selector+={ext_auto_type, "^ext_auto_type$"}
and add "ext_auto_type" to the -config lines below
around line 125, along with a reference to the gcc docs above the
configurations and in C-language-toolchain.rst
This is an extension, so it's usable without further MISRA impact.
> Min toolchain check:
> https://godbolt.org/z/f9WjooPYj
>
> GCC Manual:
>
> https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Auto-Type.html
> ---
> xen/include/xen/macros.h | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h
> index cd528fbdb127..b5e5ff4b1c2f 100644
> --- a/xen/include/xen/macros.h
> +++ b/xen/include/xen/macros.h
> @@ -71,18 +71,18 @@
> /* Hide a value from the optimiser. */
> #define HIDE(x) \
> ({ \
> - typeof(x) _x = (x); \
> + __auto_type _x = (x); \
> asm volatile ( "" : "+r" (_x) ); \
> _x; \
> })
>
> #define ABS(x) ({ \
> - typeof(x) x_ = (x); \
> + __auto_type x_ = (x); \
> (x_ < 0) ? -x_ : x_; \
> })
>
> #define SWAP(a, b) \
> - do { typeof(a) t_ = (a); (a) = (b); (b) = t_; } while ( 0 )
> + do { __auto_type t_ = (a); (a) = (b); (b) = t_; } while ( 0 )
>
> #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) +
> __must_be_array(x))
>
> @@ -110,15 +110,15 @@
> */
> #define min(x, y) \
> ({ \
> - const typeof(x) _x = (x); \
> - const typeof(y) _y = (y); \
> + const __auto_type _x = (x); \
> + const __auto_type _y = (y); \
> (void)(&_x == &_y); /* typecheck */ \
> _x < _y ? _x : _y; \
> })
> #define max(x, y) \
> ({ \
> - const typeof(x) _x = (x); \
> - const typeof(y) _y = (y); \
> + const __auto_type _x = (x); \
> + const __auto_type _y = (y); \
> (void)(&_x == &_y); /* typecheck */ \
> _x > _y ? _x : _y; \
> })
>
> base-commit: 78ce2be733b1e45e2e190c1765fe31da318d435f
--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
next prev parent reply other threads:[~2025-05-05 12:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 12:46 [PATCH] xen: Use __auto_type Andrew Cooper
2025-05-05 12:57 ` Nicola Vetrini [this message]
2025-05-05 13:00 ` Andrew Cooper
2025-05-05 19:44 ` Stefano Stabellini
2025-05-12 11:59 ` Jan Beulich
2025-05-12 12:09 ` Andrew Cooper
2025-05-12 12:41 ` Frediano Ziglio
2025-05-12 13:00 ` Jan Beulich
2025-05-12 18:25 ` Elliott Mitchell
2025-05-12 19:58 ` Nicola Vetrini
2025-05-12 23:04 ` Demi Marie Obenour
2025-05-12 23:31 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=707b9f833fd4cd0341ad09cbc3265ec9@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=consulting@bugseng.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roberto.bagnara@bugseng.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.