misra.py: Fix false negative for rule 10.1 (#2449)

This will close Trac 9489.
This commit is contained in:
Georgy Komarov 2019-12-15 20:10:22 +03:00 committed by Daniel Marjamäki
parent 36f369473e
commit f87cd9818c
2 changed files with 24 additions and 2 deletions

View File

@ -1021,11 +1021,16 @@ class MisraChecker:
e2 = getEssentialTypeCategory(token.astOperand2)
if not e1 or not e2:
continue
if token.str in ['<<', '>>']:
if token.str in ('<<', '>>'):
if e1 != 'unsigned':
self.reportError(token, 10, 1)
elif e2 != 'unsigned' and not token.astOperand2.isNumber:
self.reportError(token, 10, 1)
elif token.str in ('~', '&', '|', '^'):
e1_et = getEssentialType(token.astOperand1)
e2_et = getEssentialType(token.astOperand2)
if e1_et == 'char' and e2_et == 'char':
self.reportError(token, 10, 1)
def misra_10_4(self, data):
op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', ':'}

View File

@ -206,16 +206,33 @@ void misra_9_5() {
int x[] = {[0]=23}; // 9.5
}
typedef char misra_10_1_char_t;
#define MISRA_10_1_CHAR char
void misra_10_1(uint8_t u, char c1, char c2) {
int32_t i;
char c;
enum { E1 = 1 };
i = 3 << 1; // 10.1
i = (u & u) << 4; // no-warning
c = c1 & c2; // FIXME: This is not compliant to "10.1". Trac #9489
c = c1 & c2; // 10.1
c = c1 << 1; // 10.1
i = c1 > c2; // no-warning
i = E1 + i; // no-warning
char ch1 = 'a';
char ch2 = 'b';
char ch3;
ch3 = ch1 & ch2; // 10.1
misra_10_1_char_t ct1 = 'a';
misra_10_1_char_t ct2 = 'b';
misra_10_1_char_t ct3;
ct3 = ct1 & ct2; // 10.1
MISRA_10_1_CHAR cd1 = 'a';
MISRA_10_1_CHAR cd2 = 'b';
MISRA_10_1_CHAR cd3;
cd3 = cd1 & cd2; // 10.1
}
void misra_10_4(u32 x, s32 y) {