From: Federico Serafini <federico.serafini@bugseng.com>
To: xen-devel@lists.xenproject.org
Cc: consulting@bugseng.com,
Federico Serafini <federico.serafini@bugseng.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [XEN PATCH v2 1/3] xen: introduce STATIC_ASSERT_UNREACHABLE()
Date: Fri, 26 Jan 2024 11:05:41 +0100 [thread overview]
Message-ID: <42fc6ae8d3eb802429d29c774502ff232340dc84.1706259490.git.federico.serafini@bugseng.com> (raw)
In-Reply-To: <cover.1706259490.git.federico.serafini@bugseng.com>
Introduce macro STATIC_ASSERT_UNREACHABLE() to check that a program
point is considered unreachable by the static analysis performed by the
compiler.
The use of such macro will lead to one of the following outcomes:
- the program point identified by the macro is considered unreachable,
then the compiler removes the macro;
- the program point identified by the macro is not considered
unreachable, then the compiler does not remove the macro, which will
lead to a failure in the build process caused by an assembler error.
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
---
Changes in v2:
- removed constraint about optimization level -O0;
- use capital letters for macro name;
- add missing blanks;
- remove stray semicolon;
- cite the assertion failure in the error message.
---
xen/include/xen/compiler.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index 16d554f2a5..062f54449c 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -64,6 +64,13 @@
# define fallthrough do {} while (0) /* fallthrough */
#endif
+/*
+ * Add the following macro to check that a program point is considered
+ * unreachable by the static analysis performed by the compiler.
+ */
+#define STATIC_ASSERT_UNREACHABLE() \
+ asm ( ".error \"static assertion failed: unreachable\"" )
+
#ifdef __clang__
/* Clang can replace some vars with new automatic ones that go in .data;
* mark all explicit-segment vars 'used' to prevent that. */
--
2.34.1
next prev parent reply other threads:[~2024-01-26 10:08 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-26 10:05 [XEN PATCH v2 0/3] Introduce and use STATIC_ASSERT_UNREACHABLE() Federico Serafini
2024-01-26 10:05 ` Federico Serafini [this message]
2024-02-06 13:22 ` [XEN PATCH v2 1/3] xen: introduce STATIC_ASSERT_UNREACHABLE() Jan Beulich
2024-02-06 13:26 ` Jan Beulich
2024-02-07 1:09 ` Stefano Stabellini
2024-01-26 10:05 ` [XEN PATCH v2 2/3] x86/uaccess: replace __{get,put}_user_bad() with STATIC_ASSERT_UNREACHABLE() Federico Serafini
2024-02-06 13:25 ` Jan Beulich
2024-02-07 1:08 ` Stefano Stabellini
2024-02-07 7:38 ` Jan Beulich
2024-02-07 13:51 ` Federico Serafini
2024-02-07 14:16 ` Jan Beulich
2024-02-07 15:08 ` Federico Serafini
2024-02-07 15:24 ` Jan Beulich
2024-02-07 15:58 ` Federico Serafini
2024-02-07 16:19 ` Jan Beulich
2024-02-08 10:45 ` Federico Serafini
2024-02-08 11:14 ` Jan Beulich
2024-02-09 9:50 ` Federico Serafini
2024-02-12 8:43 ` Jan Beulich
2024-02-14 16:11 ` Federico Serafini
2024-02-15 0:05 ` Stefano Stabellini
2024-02-15 9:26 ` Jan Beulich
2024-02-15 8:10 ` Jan Beulich
2024-02-15 10:07 ` Federico Serafini
2024-02-15 10:32 ` Jan Beulich
2024-02-19 8:35 ` Federico Serafini
2024-02-19 20:43 ` Stefano Stabellini
2024-02-20 7:18 ` Jan Beulich
2024-01-26 10:05 ` [XEN PATCH v2 3/3] automation/eclair: add deviation for MISRA C:2012 Rule 16.3 Federico Serafini
2024-02-07 1:07 ` Stefano Stabellini
2024-01-31 8:19 ` [XEN PATCH v2 0/3] Introduce and use STATIC_ASSERT_UNREACHABLE() Federico Serafini
2024-01-31 9:04 ` Jan Beulich
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=42fc6ae8d3eb802429d29c774502ff232340dc84.1706259490.git.federico.serafini@bugseng.com \
--to=federico.serafini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=consulting@bugseng.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=wl@xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).