.../eclair_analysis/ECLAIR/deviations.ecl | 9 +++++++++ docs/misra/deviations.rst | 20 +++++++++++++++++++ docs/misra/rules.rst | 4 ++++ 3 files changed, 33 insertions(+)
MISRA C Rule 10.1 states: "Operands shall not be of an inappropriate
essential type".
The result of relational, equality and logical negation operators has
type int and value 0 or 1 (C99 6.5.8p6, 6.5.9p3, 6.5.3.3p5). An object
or function result of type bool has value 0 or 1 too, and it is
promoted to int (C99 6.3.1.2, 6.3.1.1p2). Using that value as an
operand of unary +, -, binary +, -, *, <<, >> and of +=, -=, *=,
<<=, >>= is well-defined. Division, remainder, the relational
operators, increment and decrement stay covered by the rule.
Update the ECLAIR configuration to tag the accepted uses as safe.
Update deviations.rst and rules.rst accordingly.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3080459013
Changes in v3:
- include unary + and -
- drop relational operators
- split the ECLAIR config into one clause per operator group for
readability
---
.../eclair_analysis/ECLAIR/deviations.ecl | 9 +++++++++
docs/misra/deviations.rst | 20 +++++++++++++++++++
docs/misra/rules.rst | 4 ++++
3 files changed, 33 insertions(+)
diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index d49af53055..e22a05a21b 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -341,6 +341,15 @@ still non-negative."
-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"}
-doc_end
+-doc_begin="A 0-or-1 Boolean operand of unary +, -, binary +, -, *, <<, >> and of +=, -=, *=, <<=, >>= is safe. See docs/misra/deviations.rst for the full explanation."
+-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(plus||minus))", "src_type(ebool||boolean)"}
+-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(add||add_assign))", "src_type(ebool||boolean)"}
+-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(sub||sub_assign))", "src_type(ebool||boolean)"}
+-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(mul||mul_assign))", "src_type(ebool||boolean)"}
+-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(shl||shl_assign))", "src_type(ebool||boolean)"}
+-config=MC3A2.R10.1,etypes+={safe, "stmt(operator(shr||shr_assign))", "src_type(ebool||boolean)"}
+-doc_end
+
-doc_begin="The macro ISOLATE_LSB encapsulates a well-known pattern to obtain
a mask where only the lowest bit set in the argument is set, if any, for unsigned
integers arguments on two's complement architectures
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index 7b983db264..6458a79a67 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -355,6 +355,26 @@ Deviations related to MISRA C:2012 Rules:
well-known to all Xen developers to be a comparison with 0.
- Tagged as `safe` for ECLAIR.
+ * - R10.1
+ - The result of relational, equality and logical negation operators has
+ type int and value 0 or 1 (C99 6.5.8p6, 6.5.9p3, 6.5.3.3p5). An object
+ or function result of type bool has value 0 or 1 too, and it is
+ promoted to int (C99 6.3.1.2, 6.3.1.1p2). Such a value is a
+ well-defined operand of the following operators. Unary + leaves it
+ unchanged. Unary - yields 0 or -1, all bits clear or, in two's
+ complement, all bits set. Binary + and - (and += and -=) count
+ something if the condition holds. \* (and \*=) yields the other operand
+ if the condition holds and 0 otherwise. << and >> (and <<= and >>=)
+ extend that selection to a shift: a Boolean left operand contributes 0
+ or 1, and a Boolean right operand is a shift count of 0 or 1. / and %
+ (and /= and %=) are excluded. A Boolean divisor is 0 when the condition
+ is false, and division or remainder by zero is undefined behavior
+ (C99 6.5.5p5). The relational operators are excluded as well: with
+ 0-or-1 operands, whatever they express can be written with the equality
+ and logical operators, which already accept an essentially Boolean
+ operand. Increment and decrement stay under the rule.
+ - Tagged as `safe` for ECLAIR.
+
* - R10.1
- Xen only supports architectures where signed integers are representend
using two's complement and all the Xen developers are aware of this. For
diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
index 7e191a0d4a..c075fe2391 100644
--- a/docs/misra/rules.rst
+++ b/docs/misra/rules.rst
@@ -387,6 +387,10 @@ maintainers if you want to suggest a change.
compilers' extensions)
- Implicit conversions to boolean for conditionals (?: if while
for) and logical operators (! || &&)
+ - Operands of essentially Boolean type (results of relational,
+ equality and logical negation operators, objects and function
+ results of type bool) used only with unary +, -, binary +, -,
+ \*, <<, >>, +=, -=, \*=, <<= and >>=
- The essential type model allows the constants defined by anonymous
enums (e.g., enum { A, B, C }) to be used as operands to arithmetic
operators, as they have a signed essential type.
--
2.43.0
On 17.11.2026 20:35, Dmytro Prokopchuk1 wrote: > MISRA C Rule 10.1 states: "Operands shall not be of an inappropriate > essential type". > > The result of relational, equality and logical negation operators has > type int and value 0 or 1 (C99 6.5.8p6, 6.5.9p3, 6.5.3.3p5). An object > or function result of type bool has value 0 or 1 too, and it is > promoted to int (C99 6.3.1.2, 6.3.1.1p2). Using that value as an Like in deviations.rst, s/that value/such a value/ ? > operand of unary +, -, binary +, -, *, <<, >> and of +=, -=, *=, > <<=, >>= is well-defined. Division, remainder, the relational > operators, increment and decrement stay covered by the rule. > > Update the ECLAIR configuration to tag the accepted uses as safe. > Update deviations.rst and rules.rst accordingly. > > Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com> Preferably with the adjustment (happy to carry out while committing): Reviewed-by: Jan Beulich <jbeulich@suse.com> Jan
On 11/18/26 10:49, Jan Beulich wrote: > On 17.11.2026 20:35, Dmytro Prokopchuk1 wrote: >> MISRA C Rule 10.1 states: "Operands shall not be of an inappropriate >> essential type". >> >> The result of relational, equality and logical negation operators has >> type int and value 0 or 1 (C99 6.5.8p6, 6.5.9p3, 6.5.3.3p5). An object >> or function result of type bool has value 0 or 1 too, and it is >> promoted to int (C99 6.3.1.2, 6.3.1.1p2). Using that value as an > > Like in deviations.rst, s/that value/such a value/ ? > >> operand of unary +, -, binary +, -, *, <<, >> and of +=, -=, *=, >> <<=, >>= is well-defined. Division, remainder, the relational >> operators, increment and decrement stay covered by the rule. >> >> Update the ECLAIR configuration to tag the accepted uses as safe. >> Update deviations.rst and rules.rst accordingly. >> >> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com> > > Preferably with the adjustment (happy to carry out while committing): Of course, I agree :) > Reviewed-by: Jan Beulich <jbeulich@suse.com> > > Jan BR, Dmytro.
© 2016 - 2026 Red Hat, Inc.