docs/misra: add rules 10.1 10.2 10.3 10.4
PATCH 1/1 docs/misra: add rules 10.1 10.2 10.3 10.4
From: Stefano Stabellini <[email protected]>
10.1 with several caveats, described in the notes.
10.3 and 10.4 as "aspirational" guidelines, as clarified in the notes.
--- docs/misra/rules.rst | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
docs/misra/rules.rst +52 -0
@@ -318,6 +318,58 @@ maintainers if you want to suggest a change. - An element of an object shall not be initialized more than once - + * - `Rule 10.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_01.c>`_ + - Required + - Operands shall not be of an inappropriate essential type + - The following are allowed: + - Value-preserving conversions of integer constants + - Bitwise and, or, xor, one's complement, bitwise and assignment, + bitwise or assignment, bitwise xor assignment (bitwise and, or, xor + are safe on non-negative integers; also Xen assumes two's complement + representation) + - Left shift, right shift, left shift assignment, right shift + assignment (see C-language-toolchain.rst for assumptions on + compilers' extensions) + - Implicit conversions to boolean for logical operators' arguments + + * - `Rule 10.2 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_02.c>`_ + - Required + - Expressions of essentially character type shall not be used + inappropriately in addition and subtraction operations + - + + * - `Rule 10.3 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_03.c>`_ + - Required + - The value of an expression shall not be assigned to an object + with a narrower essential type or of a dierent essential type + category + - Please beware that this rule has many violations in the Xen + codebase today, and its adoption is aspirational. However, when + submitting new patches please try to decrease the number of + violations when possible. + + gcc has a helpful warning that can help you spot and remove + violations of this kind: conversion. For instance, you can use + it as follows: + + cd xen; CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" make + + * - `Rule 10.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_04.c>`_ + - Required + - Both operands of an operator in which the usual arithmetic + conversions are performed shall have the same essential type + category + - Please beware that this rule has many violations in the Xen + codebase today, and its adoption is aspirational. However, when + submitting new patches please try to decrease the number of + violations when possible. + + gcc has a helpful warning that can help you spot and remove + violations of this kind: arith-conversion. For instance, you + can use it as follows: + + cd xen; CFLAGS="-Warith-conversion -Wno-error=arith-conversion" make + * - `Rule 12.5 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_12_05.c>`_ - Mandatory - The sizeof operator shall not have an operand which is a function
Signature · 1 line
2.25.1
Quoted 8 lines · Stefano Stabellini
docs/misra/rules.rst +2
-0@@ -318,6 +318,58 @@ maintainers if you want to suggest a change. - An element of an object shall not be initialized more than once - + * - `Rule 10.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_01.c>`_ + - Required
docs/misra/rules.rst maintainers if you want to suggest a change. · line 332
Quoted 10 lines
docs/misra/rules.rst +10
-0+ - Operands shall not be of an inappropriate essential type + - The following are allowed: + - Value-preserving conversions of integer constants + - Bitwise and, or, xor, one's complement, bitwise and assignment, + bitwise or assignment, bitwise xor assignment (bitwise and, or, xor + are safe on non-negative integers; also Xen assumes two's complement + representation) + - Left shift, right shift, left shift assignment, right shift + assignment (see C-language-toolchain.rst for assumptions on + compilers' extensions)
Is "assumptions" the right term here? We don't just assume these are there, we actually checked their doc and behavior. Maybe simply "uses of" instead?
docs/misra/rules.rst maintainers if you want to suggest a change. · line 333
Quoted 1 line
docs/misra/rules.rst +1
-0+ - Implicit conversions to boolean for logical operators' arguments
What is "logical operators" here? Perhaps this wants to be "conditionals" instead, to cover all of ?:, if(), while(), for() (did I forget any?), of which only the first is an operator?
docs/misra/rules.rst maintainers if you want to suggest a change. · line 344
Quoted 4 lines
docs/misra/rules.rst +4
-0+ * - `Rule 10.3 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_03.c>`_ + - Required + - The value of an expression shall not be assigned to an object + with a narrower essential type or of a dierent essential type
Nit: ff missing?
docs/misra/rules.rst maintainers if you want to suggest a change. · line 355
Quoted 11 lines
docs/misra/rules.rst +11
-0+ category + - Please beware that this rule has many violations in the Xen + codebase today, and its adoption is aspirational. However, when + submitting new patches please try to decrease the number of + violations when possible. + + gcc has a helpful warning that can help you spot and remove + violations of this kind: conversion. For instance, you can use + it as follows: + + cd xen; CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" make
Maybe slightly shorter as
CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" make -C xen
?
Jan
Quoted 50 lines · Jan Beulich
Quoted 8 lines · Stefano Stabellini
docs/misra/rules.rst +2
-0@@ -318,6 +318,58 @@ maintainers if you want to suggest a change. - An element of an object shall not be initialized more than once - + * - `Rule 10.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_01.c>`_ + - Requireddocs/misra/rules.rst maintainers if you want to suggest a change. · line 332
Quoted 10 lines
docs/misra/rules.rst +10
-0+ - Operands shall not be of an inappropriate essential type + - The following are allowed: + - Value-preserving conversions of integer constants + - Bitwise and, or, xor, one's complement, bitwise and assignment, + bitwise or assignment, bitwise xor assignment (bitwise and, or, xor + are safe on non-negative integers; also Xen assumes two's complement + representation) + - Left shift, right shift, left shift assignment, right shift + assignment (see C-language-toolchain.rst for assumptions on + compilers' extensions)Is "assumptions" the right term here? We don't just assume these are there, we actually checked their doc and behavior. Maybe simply "uses of" instead?
docs/misra/rules.rst maintainers if you want to suggest a change. · line 333
Quoted 1 line
docs/misra/rules.rst +1
-0+ - Implicit conversions to boolean for logical operators' argumentsWhat is "logical operators" here? Perhaps this wants to be "conditionals" instead, to cover all of ?:,
if(),while(),for()(did I forget any?), of which only the first is an operator?docs/misra/rules.rst maintainers if you want to suggest a change. · line 344
Quoted 4 lines
docs/misra/rules.rst +4
-0+ * - `Rule 10.3 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_03.c>`_ + - Required + - The value of an expression shall not be assigned to an object + with a narrower essential type or of a dierent essential typeNit: ff missing?
docs/misra/rules.rst maintainers if you want to suggest a change. · line 355
Quoted 11 lines
docs/misra/rules.rst +11
-0+ category + - Please beware that this rule has many violations in the Xen + codebase today, and its adoption is aspirational. However, when + submitting new patches please try to decrease the number of + violations when possible. + + gcc has a helpful warning that can help you spot and remove + violations of this kind: conversion. For instance, you can use + it as follows: + + cd xen; CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" makeMaybe slightly shorter as
Quoted 3 lines
CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" make -C xen
?
+1. It also means that the command can be called multiple time without having to type 'cd -' between.
Cheers,
Signature · 1 line
Julien Grall
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Stefano Stabellini
docs/misra/rules.rst +0
-0@@ -318,6 +318,58 @@ maintainers if you want to suggest a change. - An element of an object shall not be initialized more than once -
Quoted 15 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 332
Quoted 12 lines
docs/misra/rules.rst +12
-0+ * - `Rule 10.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_01.c>`_ + - Required + - Operands shall not be of an inappropriate essential type + - The following are allowed: + - Value-preserving conversions of integer constants + - Bitwise and, or, xor, one's complement, bitwise and assignment, + bitwise or assignment, bitwise xor assignment (bitwise and, or, xor + are safe on non-negative integers; also Xen assumes two's complement + representation) + - Left shift, right shift, left shift assignment, right shift + assignment (see C-language-toolchain.rst for assumptions on + compilers' extensions)Is "assumptions" the right term here? We don't just assume these are there, we actually checked their doc and behavior. Maybe simply "uses of" instead?
yes, I'll use "uses of"
Quoted 5 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 333
Quoted 1 line
docs/misra/rules.rst +1
-0+ - Implicit conversions to boolean for logical operators' argumentsWhat is "logical operators" here? Perhaps this wants to be "conditionals" instead, to cover all of ?:,
if(),while(),for()(did I forget any?), of which only the first is an operator?
There are also ! || && which are the logical operators
I'll write it as follows:
Implicit conversions to boolean for conditionals (?: if while for) and logical operators (! || &&)
Quoted 6 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 344
Quoted 4 lines
docs/misra/rules.rst +4
-0+ * - `Rule 10.3 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_10_03.c>`_ + - Required + - The value of an expression shall not be assigned to an object + with a narrower essential type or of a dierent essential typeNit: ff missing?
yep, thanks
Quoted 14 lines
docs/misra/rules.rst maintainers if you want to suggest a change. · line 355
Quoted 11 lines
docs/misra/rules.rst +11
-0+ category + - Please beware that this rule has many violations in the Xen + codebase today, and its adoption is aspirational. However, when + submitting new patches please try to decrease the number of + violations when possible. + + gcc has a helpful warning that can help you spot and remove + violations of this kind: conversion. For instance, you can use + it as follows: + + cd xen; CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" makeMaybe slightly shorter as
Quoted 3 lines
CFLAGS="-Wconversion -Wno-error=sign-conversion -Wno-error=conversion" make -C xen
?
I'll make the change here and also in the other instance of the same