qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PATCH v4 2/3] docs/devel/style: add a section about bitfield, and disallow them for packed structures
Date: Fri, 10 Jan 2025 12:34:00 -0800	[thread overview]
Message-ID: <20250110203401.178532-3-pierrick.bouvier@linaro.org> (raw)
In-Reply-To: <20250110203401.178532-1-pierrick.bouvier@linaro.org>

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 docs/devel/style.rst | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/docs/devel/style.rst b/docs/devel/style.rst
index 2f68b500798..d025933808e 100644
--- a/docs/devel/style.rst
+++ b/docs/devel/style.rst
@@ -416,6 +416,26 @@ definitions instead of typedefs in headers and function prototypes; this
 avoids problems with duplicated typedefs and reduces the need to include
 headers from other headers.
 
+Bitfields
+---------
+
+C bitfields can be a cause of non-portability issues, especially under windows
+where `MSVC has a different way to lay them out than GCC
+<https://gcc.gnu.org/onlinedocs/gcc/x86-Type-Attributes.html>`_, or where
+endianness matters.
+
+For this reason, we disallow usage of bitfields in packed structures and in any
+structures which are supposed to exactly match a specific layout in guest
+memory. Some existing code may use it, and we carefully ensured the layout was
+the one expected.
+
+We also suggest avoiding bitfields even in structures where the exact
+layout does not matter, unless you can show that they provide a significant
+usability benefit.
+
+We encourage the usage of ``include/hw/registerfields.h`` as a safe replacement
+for bitfields.
+
 Reserved namespaces in C and POSIX
 ----------------------------------
 
-- 
2.39.5



  parent reply	other threads:[~2025-01-10 20:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-10 20:33 [PATCH v4 0/3] Enable clang build on Windows Pierrick Bouvier
2025-01-10 20:33 ` [PATCH v4 1/3] win32: remove usage of attribute gcc_struct Pierrick Bouvier
2025-01-13 23:38   ` Michael S. Tsirkin
2025-01-10 20:34 ` Pierrick Bouvier [this message]
2025-01-10 20:34 ` [PATCH v4 3/3] plugins: enable linking with clang/lld Pierrick Bouvier
2025-01-10 20:37 ` [PATCH v4 0/3] Enable clang build on Windows Pierrick Bouvier
2025-01-11 15:47   ` Philippe Mathieu-Daudé
2025-01-12 18:03     ` Philippe Mathieu-Daudé
2025-01-13  6:26     ` Thomas Huth
2025-01-13 20:17       ` Pierrick Bouvier
2025-01-13 21:19         ` Alex Bennée
2025-01-13 21:22           ` Pierrick Bouvier
2025-01-11 22:08 ` Stefan Weil via
2025-01-12 17:54   ` Pierrick Bouvier
2025-02-18  4:11   ` Brian Cain
2025-02-18 16:22     ` Pierrick Bouvier
2025-02-18 16:26       ` Daniel P. Berrangé
2025-02-18 20:59       ` Stefan Weil via
2025-02-18 23:17         ` Pierrick Bouvier
2025-02-19  6:39           ` Stefan Weil via
2025-02-19  7:01             ` Pierrick Bouvier
2025-02-19  7:38               ` Stefan Weil via
2025-01-14  8:20 ` Alex Bennée
2025-01-14  8:35   ` Philippe Mathieu-Daudé

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=20250110203401.178532-3-pierrick.bouvier@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sgarzare@redhat.com \
    --cc=thuth@redhat.com \
    /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).