[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] xen: Use __auto_type
- To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- From: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
- Date: Mon, 05 May 2025 14:57:16 +0200
- Arc-authentication-results: i=1; bugseng.com; arc=none smtp.remote-ip=162.55.131.47
- Arc-message-signature: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; c=relaxed/relaxed; t=1746449836; h=DKIM-Signature:MIME-Version:Date:From:To:Cc:Subject:In-Reply-To: References:Message-ID:X-Sender:Organization:Content-Type: Content-Transfer-Encoding; bh=+6q07O2QYqE5gk+2iKSDXVQnl8JvJZKymTeJI/7hVDk=; b=RzCc8xwKw9NIdpl+Y4gYZlcK2n8cFvDLE5FDvqQdsawDl/sWLfEtj3PtvnATm6A+UZvT +kUCPyFXuvElj/AurjjddEkxWBPEt4VALVj64vOxvXNgcGmYagcOyElDvwKQAIicGAj6z Ti9usDanqpqgl4/3ezCsGoHEFEunKLw15Q5Hhl183QNPGDb0pPbVj/jkV3faxYlOQyWTF CEOdNSk4XTyfZmFgyYBS7JP9tOrAHxZj6/uzchwaGyo9hrXlngLtlwNMosP+8rX6GQ0Lg L72k1aMCUbMmg2VowqIbR6kuTxV/0+mdvNSyAm8yXeISCVCdOobgElys1sr0XWNj1wAv3 cQiVYgIwZTxDtIYn2Dk+DLOhK9IgqkX8d1zmYSEgAyKsSsiV/71dqtJvKnY6VGn0LKOHR BXmB7gQAZI/r6x9OAKYZIoteZSBf33tWHd3KYAtVp/q1VeLnTnmdWazQSui9FI6FQ6tlj QZeXxIkGx9D51BnGiuaHu2++E995WFpzvUAicOG4V0o0vjWhT0P7ffbJpMin2VaqdJDPH iodjuu0oT0nprI6iITjrr+we8cT6kd5klshGMmXTaOzRbs6NIXOfr97qakOW1EiyijsMN rQu38R5dsAjR8IjPWGryGocSy2Z0QJWR7RaLfEhKJPqjP2VP50frMvmRcnS7WzU=
- Arc-seal: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; cv=none; t=1746449836; b=cfDBtjv74drHMsMMvIwOjp9ak2ybpgOLQmEQJqD0b2fyuDOxemnN+mFhSmvZ5vsMPweN xfp0gWSGKUcNp/nkkqwQUNmI+XEIooCyzH+PcEcZ0Jo/d0DIky64X9GFAcQiyr0yza15a vS3IYAldspdMwZfK71c8WSn5I2MY7viLUF9z4PaZtIS2fStLm9bMLuQRihFrlrERJWmhi NfcvQ68BfJcxmdro7XCvFoJW2aRYtzGmZ2zKNNSPIAMMzGrls1bI7Xjmxui12v2lKopki HGiJ9VlUjZYvCGbz7h3vJWP23uKXBE7avu9Q+UEIqV1epTUM8TsHauZeh9f9ETbLK5GFA 73tINZlaF5JBw00V6xsmjqQel62Ww21Yxwq2361yw4TIl9yKOclLP4YS7+KLOk+6FT2F/ YZDiP8peSOi4OyEBEj/pQ+XmkLnN3ljXhurDlVnVCcne6YkaWvN7vKPGcdXJWFdxjDYgx 3QDqfawNJL1hLzuwlk5oHE3y7l827f2s8p4DwXCZ72nH+tuyZGkT7kPU5BfN8WoLAmrLN 0ZIZCiuEaZjJtlMiLHzTMGlVZdqyxcmmV82RFmjcGPLYjtw4y4ovXgNi9w/i6vJM2v03n sEESv4cp2JP9PJEFf3DW0aVFM8bL7BLzFdc48+GC5/NnkFAFhtCCsNP4JKwzleg=
- Authentication-results: bugseng.com; arc=none smtp.remote-ip=162.55.131.47
- Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>, "consulting @ bugseng . com" <consulting@xxxxxxxxxxx>
- Delivery-date: Mon, 05 May 2025 12:57:29 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
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@xxxxxxxxxx>
---
CC: Anthony PERARD <anthony.perard@xxxxxxxxxx>
CC: Michal Orzel <michal.orzel@xxxxxxx>
CC: Jan Beulich <jbeulich@xxxxxxxx>
CC: Julien Grall <julien@xxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Roberto Bagnara <roberto.bagnara@xxxxxxxxxxx>
CC: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
CC: consulting@xxxxxxxxxxx <consulting@xxxxxxxxxxx>
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
|