misra; improved essential type for composite expressions

This commit is contained in:
Daniel Marjamäki 2021-07-21 08:20:15 +02:00
parent 41c94b656a
commit 4428efbd2b
2 changed files with 12 additions and 2 deletions

View File

@ -485,7 +485,7 @@ def getEssentialType(expr):
return 'char'
return '%s %s' % (expr.valueType.sign, expr.valueType.type)
if expr.variable:
if expr.variable or isCast(expr):
if expr.valueType:
if expr.valueType.type == 'bool':
return 'Boolean'
@ -519,6 +519,13 @@ def getEssentialType(expr):
e2 = getEssentialType(expr.astOperand2)
if not e1 or not e2:
return None
if is_constant_integer_expression(expr):
sign1 = e1.split(' ')[0]
sign2 = e1.split(' ')[0]
if sign1 == sign2 and sign1 in ('signed', 'unsigned'):
e = get_essential_type_from_value(expr.getKnownIntValue(), sign1 == 'signed')
if e:
return e
if bitsOfEssentialType(e2) >= bitsOfEssentialType(e1):
return e2
else:

View File

@ -663,7 +663,10 @@ static void misra_10_2(void) {
}
static void misra_10_3(uint32_t u32a, uint32_t u32b) {
uint8_t res = u32a + u32b; // 10.3
uint8_t res;
res = u32a + u32b; // 10.3
res = (uint16_t)(2U + 3U); // 10.3 10.8
res = (uint16_t)2U + (uint16_t)3U;
}
static void misra_10_4(u32 x, s32 y) {