misra; implement rule 10.7
This commit is contained in:
parent
fb8d6daf79
commit
d2843b70ca
|
@ -2177,6 +2177,32 @@ class MisraChecker:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def misra_10_7(self, cfg):
|
||||||
|
for token in cfg.tokenlist:
|
||||||
|
if token.astOperand1 is None or token.astOperand2 is None:
|
||||||
|
continue
|
||||||
|
if not token.isArithmeticalOp:
|
||||||
|
continue
|
||||||
|
parent = token.astParent
|
||||||
|
if parent is None:
|
||||||
|
continue
|
||||||
|
if not parent.isArithmeticalOp:
|
||||||
|
if not parent.isAssignmentOp:
|
||||||
|
continue
|
||||||
|
if parent.str == '=':
|
||||||
|
continue
|
||||||
|
token_type = getEssentialType(token)
|
||||||
|
if token_type is None:
|
||||||
|
continue
|
||||||
|
sibling = parent.astOperand1 if (token == parent.astOperand2) else parent.astOperand2
|
||||||
|
sibling_type = getEssentialType(sibling)
|
||||||
|
if sibling_type is None:
|
||||||
|
continue
|
||||||
|
b1 = bitsOfEssentialType(token_type)
|
||||||
|
b2 = bitsOfEssentialType(sibling_type)
|
||||||
|
if b1 > 0 and b1 < b2:
|
||||||
|
self.reportError(token, 10, 7)
|
||||||
|
|
||||||
def misra_10_8(self, data):
|
def misra_10_8(self, data):
|
||||||
for token in data.tokenlist:
|
for token in data.tokenlist:
|
||||||
if not isCast(token):
|
if not isCast(token):
|
||||||
|
@ -3801,6 +3827,7 @@ class MisraChecker:
|
||||||
self.executeCheck(1004, self.misra_10_4, cfg)
|
self.executeCheck(1004, self.misra_10_4, cfg)
|
||||||
self.executeCheck(1005, self.misra_10_5, cfg)
|
self.executeCheck(1005, self.misra_10_5, cfg)
|
||||||
self.executeCheck(1006, self.misra_10_6, cfg)
|
self.executeCheck(1006, self.misra_10_6, cfg)
|
||||||
|
self.executeCheck(1007, self.misra_10_7, cfg)
|
||||||
self.executeCheck(1008, self.misra_10_8, cfg)
|
self.executeCheck(1008, self.misra_10_8, cfg)
|
||||||
self.executeCheck(1101, self.misra_11_1, cfg)
|
self.executeCheck(1101, self.misra_11_1, cfg)
|
||||||
self.executeCheck(1102, self.misra_11_2, cfg)
|
self.executeCheck(1102, self.misra_11_2, cfg)
|
||||||
|
|
|
@ -704,6 +704,15 @@ static void misra_10_6_1(uint32_t *a, uint16_t b, uint16_t c)
|
||||||
*a = b + c ; // 10.6
|
*a = b + c ; // 10.6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void misra_10_7(uint16_t u16a, uint16_t u16b) {
|
||||||
|
uint32_t u32a = 100u;
|
||||||
|
res = u32a * u16a + u16b; // 12.1 no-warning
|
||||||
|
res = (u32a * u16a) + u16b; // no-warning
|
||||||
|
res = u32a * ( ( uint32_t ) u16a + u16b ); // no-warning
|
||||||
|
res = u32a * (u16a + u16b); // 10.7
|
||||||
|
u32a *= u16a + u16b; // 10.7
|
||||||
|
}
|
||||||
|
|
||||||
static void misra_10_8(u8 x, s32 a, s32 b) {
|
static void misra_10_8(u8 x, s32 a, s32 b) {
|
||||||
y = (u16)x;
|
y = (u16)x;
|
||||||
y = (u16)(x+x); // 10.8
|
y = (u16)(x+x); // 10.8
|
||||||
|
|
Loading…
Reference in New Issue