qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Subject: Re: [PATCH v3 2/3] docs/devel/style: add a section about bitfield, and disallow them for packed structures
Date: Thu, 28 Nov 2024 15:02:14 -0600	[thread overview]
Message-ID: <65b86333-3d97-4149-a33d-53372fd50004@linaro.org> (raw)
In-Reply-To: <20241128201510.869974-3-pierrick.bouvier@linaro.org>

On 11/28/24 14:15, Pierrick Bouvier wrote:
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   docs/devel/style.rst | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

> 
> diff --git a/docs/devel/style.rst b/docs/devel/style.rst
> index 2f68b500798..2d73e6a8f7a 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>`_, and on big and
> +little endian hosts.
> +
> +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
> +memory usage or usability benefit.
> +
> +We encourage the usage of ``include/hw/registerfields.h`` as a safe replacement
> +for bitfields.
> +
>   Reserved namespaces in C and POSIX
>   ----------------------------------
>   



  reply	other threads:[~2024-11-28 21:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-28 20:15 [PATCH v3 0/3] Enable clang build on Windows Pierrick Bouvier
2024-11-28 20:15 ` [PATCH v3 1/3] win32: remove usage of attribute gcc_struct Pierrick Bouvier
2024-11-28 21:01   ` Richard Henderson
2024-11-28 20:15 ` [PATCH v3 2/3] docs/devel/style: add a section about bitfield, and disallow them for packed structures Pierrick Bouvier
2024-11-28 21:02   ` Richard Henderson [this message]
2024-12-09 20:33   ` Philippe Mathieu-Daudé
2024-12-09 22:15     ` Pierrick Bouvier
2024-12-10  7:52     ` Thomas Huth
2024-12-10 10:10       ` Philippe Mathieu-Daudé
2024-12-10 18:45         ` Pierrick Bouvier
2024-11-28 20:15 ` [PATCH v3 3/3] plugins: enable linking with clang/lld Pierrick Bouvier
2025-01-10  8:03   ` Philippe Mathieu-Daudé
2024-12-09 18:34 ` [PATCH v3 0/3] Enable clang build on Windows Pierrick Bouvier

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=65b86333-3d97-4149-a33d-53372fd50004@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=qemu-devel@nongnu.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).