From ca0842ae5ea2fe03398cb774f74b5c8f46272c8a Mon Sep 17 00:00:00 2001 From: swasti16 Date: Fri, 27 Oct 2023 16:17:41 +0530 Subject: [PATCH] Fix #9488: MISRA addon: False positive for rule 10.6 in test for rule 10.1 --- addons/misra.py | 3 +++ addons/test/misra/misra-test.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index 8413ed794ee..b16160bcc11 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2379,6 +2379,9 @@ def misra_10_6(self, data): e = getEssentialType(token.astOperand2) if not e: continue + if e == "char" and vt1.type == "int": + # When arithmetic operations are performed on char values, they are usually promoted to int + continue lhsbits = vt1.bits if vt1.bits else bitsOfEssentialType(vt1.type) if lhsbits > bitsOfEssentialType(e): self.reportError(token, 10, 6) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index e9c61ad32fd..46a8f14a671 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -749,7 +749,7 @@ static void misra_10_6(u8 x, char c1, char c2) { u16 y1 = x+x; // 10.6 u16 y2 = (0x100u - 0x80u); // rhs is not a composite expression because it's a constant expression u16 z = ~u8 x ;//10.6 - s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488 + s32 i = c1 - c2; // 10.3 struct misra_10_6_s s; s.a = x & 1U; // no-warning (#10487) }