This commit is contained in:
Daniel Marjamäki 2022-02-11 21:04:46 +01:00
parent d4cd249c21
commit 515649217f
2 changed files with 27 additions and 6 deletions

View File

@ -422,6 +422,28 @@ def get_type_conversion_to_from(token):
return None
def is_composite_expr(expr, composite_operator=False):
"""MISRA C 2012, section 8.10.3"""
if expr is None:
return False
if not composite_operator:
if (expr.str in ('+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~')):
return is_composite_expr(expr.astOperand1,True) or is_composite_expr(expr.astOperand2, True)
if expr.str == '?' and simpleMatch(expr.astOperand2, ':'):
colon = expr.astOperand2
return is_composite_expr(colon.astOperand1,True) or is_composite_expr(colon.astOperand2, True)
return False
# non constant expression?
if expr.isNumber:
return False
if expr.astOperand1 or expr.astOperand2:
return is_composite_expr(expr.astOperand1,True) or is_composite_expr(expr.astOperand2, True)
return True
def getEssentialTypeCategory(expr):
if not expr:
return None
@ -2277,8 +2299,7 @@ class MisraChecker:
for token in data.tokenlist:
if token.str != '=' or not token.astOperand1 or not token.astOperand2:
continue
if (token.astOperand2.str not in ('+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~') and
not isCast(token.astOperand2)):
if not is_composite_expr(token.astOperand2):
continue
vt1 = token.astOperand1.valueType
vt2 = token.astOperand2.valueType

View File

@ -623,7 +623,7 @@ static void misra_10_1(uint32_t u, char c1, char c2, uint8_t u8) {
int32_t i;
char c;
enum { E1 = 1 };
i = 3 << 1; // 10.1 10.6
i = 3 << 1; // 10.1
i = (u & u) << 4; // no-warning
c = c1 & c2; // 10.1
c = c1 << 1; // 10.1
@ -736,10 +736,10 @@ static void misra_10_5(uint16_t x) {
struct misra_10_6_s {
unsigned int a:4;
};
static void misra_10_6(u8 x, u32 a, u32 b, char c1, char c2) {
u16 y = x+x; // 10.6
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
u32 c = ( u16) ( u32 a + u32 b ); //10.6
s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488
struct misra_10_6_s s;
s.a = x & 1U; // no-warning (#10487)