qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour
@ 2012-10-31  9:30 Peter Maydell
  2012-12-04 16:51 ` Peter Maydell
  2012-12-08 17:53 ` Blue Swirl
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2012-10-31  9:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Blue Swirl, Paolo Bonzini, Anthony Liguori, patches

Add a section to HACKING saying which version of the C spec
we use and describing the bits of implementation defined C
compiler behaviour which C code in QEMU is allowed to rely on.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 HACKING | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/HACKING b/HACKING
index 89a6b3a..6654d33 100644
--- a/HACKING
+++ b/HACKING
@@ -123,3 +123,23 @@ gcc's printf attribute directive in the prototype.
 This makes it so gcc's -Wformat and -Wformat-security options can do
 their jobs and cross-check format strings with the number and types
 of arguments.
+
+6. C standard, implementation defined and undefined behaviors
+
+C code in QEMU should be written to the C99 language specification. A copy
+of the final version of the C99 standard with corrigenda TC1, TC2, and TC3
+included, formatted as a draft, can be downloaded from:
+ http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
+
+The C language specification defines regions of undefined behavior and
+implementation defined behavior (to give compiler authors enough leeway to
+produce better code).  In general, code in QEMU should follow the language
+specification and avoid both undefined and implementation defined
+constructs. ("It works fine on the gcc I tested it with" is not a valid
+argument...) However there are a few areas where we allow ourselves to
+assume certain behaviors because in practice all the platforms we care about
+behave in the same way and writing strictly conformant code would be
+painful. These are:
+ * you may assume that integers are 2s complement representation
+ * you may assume that right shift of a signed integer duplicates
+   the sign bit (ie it is an arithmetic shift, not a logical shift)
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour
  2012-10-31  9:30 [Qemu-devel] [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour Peter Maydell
@ 2012-12-04 16:51 ` Peter Maydell
  2012-12-08 17:53 ` Blue Swirl
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2012-12-04 16:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Blue Swirl, Paolo Bonzini, Anthony Liguori, patches

Ping! now that 1.4 is open. patchwork url
  http://patchwork.ozlabs.org/patch/195783/

-- PMM

On 31 October 2012 09:30, Peter Maydell <peter.maydell@linaro.org> wrote:
> Add a section to HACKING saying which version of the C spec
> we use and describing the bits of implementation defined C
> compiler behaviour which C code in QEMU is allowed to rely on.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  HACKING | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/HACKING b/HACKING
> index 89a6b3a..6654d33 100644
> --- a/HACKING
> +++ b/HACKING
> @@ -123,3 +123,23 @@ gcc's printf attribute directive in the prototype.
>  This makes it so gcc's -Wformat and -Wformat-security options can do
>  their jobs and cross-check format strings with the number and types
>  of arguments.
> +
> +6. C standard, implementation defined and undefined behaviors
> +
> +C code in QEMU should be written to the C99 language specification. A copy
> +of the final version of the C99 standard with corrigenda TC1, TC2, and TC3
> +included, formatted as a draft, can be downloaded from:
> + http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
> +
> +The C language specification defines regions of undefined behavior and
> +implementation defined behavior (to give compiler authors enough leeway to
> +produce better code).  In general, code in QEMU should follow the language
> +specification and avoid both undefined and implementation defined
> +constructs. ("It works fine on the gcc I tested it with" is not a valid
> +argument...) However there are a few areas where we allow ourselves to
> +assume certain behaviors because in practice all the platforms we care about
> +behave in the same way and writing strictly conformant code would be
> +painful. These are:
> + * you may assume that integers are 2s complement representation
> + * you may assume that right shift of a signed integer duplicates
> +   the sign bit (ie it is an arithmetic shift, not a logical shift)
> --
> 1.7.11.4
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour
  2012-10-31  9:30 [Qemu-devel] [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour Peter Maydell
  2012-12-04 16:51 ` Peter Maydell
@ 2012-12-08 17:53 ` Blue Swirl
  1 sibling, 0 replies; 3+ messages in thread
From: Blue Swirl @ 2012-12-08 17:53 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Paolo Bonzini, Anthony Liguori, malc, qemu-devel, patches

Thanks, applied.

On Wed, Oct 31, 2012 at 9:30 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> Add a section to HACKING saying which version of the C spec
> we use and describing the bits of implementation defined C
> compiler behaviour which C code in QEMU is allowed to rely on.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  HACKING | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/HACKING b/HACKING
> index 89a6b3a..6654d33 100644
> --- a/HACKING
> +++ b/HACKING
> @@ -123,3 +123,23 @@ gcc's printf attribute directive in the prototype.
>  This makes it so gcc's -Wformat and -Wformat-security options can do
>  their jobs and cross-check format strings with the number and types
>  of arguments.
> +
> +6. C standard, implementation defined and undefined behaviors
> +
> +C code in QEMU should be written to the C99 language specification. A copy
> +of the final version of the C99 standard with corrigenda TC1, TC2, and TC3
> +included, formatted as a draft, can be downloaded from:
> + http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
> +
> +The C language specification defines regions of undefined behavior and
> +implementation defined behavior (to give compiler authors enough leeway to
> +produce better code).  In general, code in QEMU should follow the language
> +specification and avoid both undefined and implementation defined
> +constructs. ("It works fine on the gcc I tested it with" is not a valid
> +argument...) However there are a few areas where we allow ourselves to
> +assume certain behaviors because in practice all the platforms we care about
> +behave in the same way and writing strictly conformant code would be
> +painful. These are:
> + * you may assume that integers are 2s complement representation
> + * you may assume that right shift of a signed integer duplicates
> +   the sign bit (ie it is an arithmetic shift, not a logical shift)
> --
> 1.7.11.4
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-08 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-31  9:30 [Qemu-devel] [PATCH v2] HACKING: List areas where we may rely on impdef C behaviour Peter Maydell
2012-12-04 16:51 ` Peter Maydell
2012-12-08 17:53 ` Blue Swirl

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).