[PATCH v2] docs/misra: document gcc-specific behavior with shifting signed integers

Stefano Stabellini posted 1 patch 8 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20230822010228.2517542-1-sstabellini@kernel.org
docs/misra/C-language-toolchain.rst | 9 +++++++++
1 file changed, 9 insertions(+)
[PATCH v2] docs/misra: document gcc-specific behavior with shifting signed integers
Posted by Stefano Stabellini 8 months, 1 week ago
From: Stefano Stabellini <stefano.stabellini@amd.com>

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
v2:
- split << and >>
- do not use the word "shift" instead of << or >>
---
 docs/misra/C-language-toolchain.rst | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/docs/misra/C-language-toolchain.rst b/docs/misra/C-language-toolchain.rst
index 785aed1eaf..4c4942a113 100644
--- a/docs/misra/C-language-toolchain.rst
+++ b/docs/misra/C-language-toolchain.rst
@@ -200,6 +200,15 @@ The table columns are as follows:
      - ARM64, X86_64
      - See Section "6.29 Designated Initializers" of GCC_MANUAL
 
+   * - Signed << compiler-defined behavior
+     - All architectures
+     - See Section "4.5 Integers" of GCC_MANUAL. As an extension to the
+       C language, GCC does not use the latitude given in C99 and C11
+       only to treat certain aspects of signed << as undefined.
+
+   * - Signed >> acts on negative numbers by sign extension
+     - All architectures
+     - See Section "4.5 Integers" of GCC_MANUAL.
 
 Translation Limits
 __________________
-- 
2.25.1
Re: [PATCH v2] docs/misra: document gcc-specific behavior with shifting signed integers
Posted by Julien Grall 8 months, 1 week ago
Hi Stefano,

On 22/08/2023 02:02, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@amd.com>
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
> ---
> v2:
> - split << and >>
> - do not use the word "shift" instead of << or >>
> ---
>   docs/misra/C-language-toolchain.rst | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/docs/misra/C-language-toolchain.rst b/docs/misra/C-language-toolchain.rst
> index 785aed1eaf..4c4942a113 100644
> --- a/docs/misra/C-language-toolchain.rst
> +++ b/docs/misra/C-language-toolchain.rst
> @@ -200,6 +200,15 @@ The table columns are as follows:
>        - ARM64, X86_64
>        - See Section "6.29 Designated Initializers" of GCC_MANUAL
>   
> +   * - Signed << compiler-defined behavior
> +     - All architectures
> +     - See Section "4.5 Integers" of GCC_MANUAL. As an extension to the
> +       C language, GCC does not use the latitude given in C99 and C11
> +       only to treat certain aspects of signed << as undefined.
> +
> +   * - Signed >> acts on negative numbers by sign extension
> +     - All architectures
> +     - See Section "4.5 Integers" of GCC_MANUAL.

I noticed that all this document is referring to GCC. But we also 
support CLang. Did you confirm that CLang abide with this behavior?

Cheers,

-- 
Julien Grall
Re: [PATCH v2] docs/misra: document gcc-specific behavior with shifting signed integers
Posted by Stefano Stabellini 8 months, 1 week ago
On Tue, 22 Aug 2023, Julien Grall wrote:
> Hi Stefano,
> 
> On 22/08/2023 02:02, Stefano Stabellini wrote:
> > From: Stefano Stabellini <stefano.stabellini@amd.com>
> > 
> > Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
> > ---
> > v2:
> > - split << and >>
> > - do not use the word "shift" instead of << or >>
> > ---
> >   docs/misra/C-language-toolchain.rst | 9 +++++++++
> >   1 file changed, 9 insertions(+)
> > 
> > diff --git a/docs/misra/C-language-toolchain.rst
> > b/docs/misra/C-language-toolchain.rst
> > index 785aed1eaf..4c4942a113 100644
> > --- a/docs/misra/C-language-toolchain.rst
> > +++ b/docs/misra/C-language-toolchain.rst
> > @@ -200,6 +200,15 @@ The table columns are as follows:
> >        - ARM64, X86_64
> >        - See Section "6.29 Designated Initializers" of GCC_MANUAL
> >   +   * - Signed << compiler-defined behavior
> > +     - All architectures
> > +     - See Section "4.5 Integers" of GCC_MANUAL. As an extension to the
> > +       C language, GCC does not use the latitude given in C99 and C11
> > +       only to treat certain aspects of signed << as undefined.
> > +
> > +   * - Signed >> acts on negative numbers by sign extension
> > +     - All architectures
> > +     - See Section "4.5 Integers" of GCC_MANUAL.
> 
> I noticed that all this document is referring to GCC. But we also support
> CLang. Did you confirm that CLang abide with this behavior?

Hi Julien,

No, only GCC. The analysis and documentation so far has been done only
for GCC, as you can see from all the various mentions and pointers to
the GCC manual scattered through C-language-toolchain.rst. Actually I
think it would be very useful for our users to do the same also for
CLang, given that some safety compilers are based on CLang. And it would
be very useful to know if there are any difference. If collectively we
start to find corresponding references to the CLang manual we could add
them one by one to C-language-toolchain.rst as we find them.
Re: [PATCH v2] docs/misra: document gcc-specific behavior with shifting signed integers
Posted by Jan Beulich 8 months, 1 week ago
On 22.08.2023 03:02, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@amd.com>
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>