[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] misra: deviate MISRA C Rule 10.1 for boolean operands of arithmetic


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Mon, 16 Nov 2026 10:25:26 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mc/pwjjp4loY/3YEWg67ubJK3VxtoO8we+DA/8g0xOA=; b=KTtdDotRkgyTB8Vlbc+Bvzr6zYHwi+zx4YlldmqArKwn29UWQzinAwOvwOG1mkfc0KvFJMWhChXxBcFQd6ongYhKSHQ1LeIi83cbzJw67CSlMY50DtuMIjFhJVlNIGA/KtBjOvi/eWwzK3yX5ULqcgHFXZMcuqPo1ompIxN3Qmj4j7/J9tyYNH+Xzo7BEILUz8PezAHvgUmtQSmgfYg4OQVitkVULVwja/CjTKwa33AShXoU+4P1lHwkzULiOjcqe46Vkdbe5va2yu41DJdGUn5BQAtbUKH1sOrOeSpUo/EKvu9dNm/XYjS5j9bdMfHPSOI+ZQQ8O6deTXA7v36KJA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=E/RwifKXh++9h7LDC9yzncQTxo0+XB4up14mn+Z2zvDGsRvXmjLqB5Kppe/hwiZdrOq5xRxUN2VvJJNDVlU9kdJZ2yoH7cxztad9r0zHBSL3+13LIPl0odXKKqBwwQ4zGdn4Hcpe4YP0Heo3VrSz3rZAI18rVpICXddvQ+0/COGelwBcwCPKlxeaJbWdCeos0aLM3zfC7tIKM+JjjmYR4GYm/w+KWtUO+I9yOPuuifk5P6DMQhOZId4/QVoZljnSP5gRqrKSjTrwFYRh4jz+iuSBCScALwC6IgnliNptRPn7y/+FjM2PCxb4w/fr3TAX1ZvZfZFQExP5STie2Hgoew==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 16 Nov 2026 08:25:43 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 11/10/26 11:58, Jan Beulich wrote:
On 10.11.2026 10:25, 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
operand of binary +, -, *, <<, >>, <, >, <=, >= and of +=, -=, *=,
<<=, >>= is well-defined. Division, remainder, unary plus and minus,

We did discuss division and remainder. What's wrong with unary plus and
minus? Unary minus in particular can be used to create a mask value from
a boolean (all bits set or all bits clear). And why would unary plus and
minus be excluded when bitwise complement (which is less useful with a
boolean operand than unary minus) is not?

Agreed, there's nothing wrong with them. Bitwise complement is already
covered for any operand by the existing deviation, so excluding unary + and - is inconsistent. v3 will include both.


As to relational operators (which it looks like we didn't discuss in v1):
Is it possible to express anything with them which cannot be expressed
with equality operators? If not, I'd suggest keeping them out as well.

No, with 0-or-1 operands each of them can be written with equality and
logical operators. I'll drop them in v3.


--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -335,6 +335,10 @@ 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 binary +, -, *, <<, >>, <, >, <=, >= and of +=, -=, *=, <<=, >>= is safe. See docs/misra/deviations.rst for the full explanation."
+-config=MC3A2.R10.1,etypes+={safe, 
"stmt(operator(add||sub||add_assign||sub_assign||mul||mul_assign||shl||shr||shl_assign||shr_assign||lt||gt||le||ge))",
 "src_type(ebool||boolean)"}

Imo this wants shortening by making use of regex-es (provided such can be
used here).

Unfortunately no. Unlike file() or macro(), which take ^REGEX$
matchers, operator() in ECLAIR only accepts operator identifiers or
predefined operator collections.


Jan

BR, Dmytro.




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.