diff --git a/addons/misra.py b/addons/misra.py index 46fdf3e9f..4d9bd6fb9 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1023,7 +1023,7 @@ class MisraSettings(object): class MisraChecker: - def __init__(self, settings, stdversion="c90"): + def __init__(self, settings, stdversion="c89"): """ :param settings: misra.py script settings. """ @@ -1293,21 +1293,24 @@ class MisraChecker: def misra_6_1(self, data): # Bitfield type must be bool or explicity signed/unsigned int - for token in data.tokenlist: - if token.valueType == None: + for token in data.tokenlist: + if not token.valueType: continue - if token.valueType.bits == 0: continue - - if token.valueType.type == 'bool': + if not token.variable: + continue + if not token.scope: + continue + if token.scope.type not in 'Struct': continue - if token.valueType.type != 'int': - self.reportError(token, 6, 1) - - if token.variable == None or token.variable.typeStartToken == None or token.variable.typeEndToken == None: - continue + if data.standards.c == 'c89': + if token.valueType.type != 'int': + self.reportError(token, 6, 1) + elif data.standards.c == 'c99': + if token.valueType.type == 'bool': + continue isExplicitlySignedOrUnsigned = False typeToken = token.variable.typeStartToken @@ -1318,7 +1321,7 @@ class MisraChecker: if typeToken.Id == token.variable.typeEndToken.Id: break - + typeToken = typeToken.next if not isExplicitlySignedOrUnsigned: @@ -1327,10 +1330,13 @@ class MisraChecker: def misra_6_2(self, data): # Bitfields of size 1 can not be signed - for token in data.tokenlist: - if token.valueType == None: + for token in data.tokenlist: + if not token.valueType: + continue + if not token.scope: + continue + if token.scope.type not in 'Struct': continue - if token.valueType.bits == 1 and token.valueType.sign == 'signed': self.reportError(token, 6, 2) diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 003c54da5..7da34cc02 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -206,18 +206,21 @@ void misra_5_5_func1() typedef unsigned int UINT_TYPEDEF; struct struct_with_bitfields { - unsigned int a:2; // Compliant + unsigned int a:2; // Compliant signed int b:2; // Compliant UINT_TYPEDEF c:2; // Compliant - int d:2; // 6.1 - plain int not compliant - - bool e:2; // Compliant + int d:2; // 6.1 - plain int not compliant signed long f:2; // 6.1 - signed long not compliant - unsigned int g:1; // Compliant signed int h:1; // 6.2 - signed int with size 1 is not compliant }; +void misra6_1_fn() { + // "Use" occurrence should not generate warnings + struct_with_bitfields s; + s.h = 61; +} + void misra_7_1() { int x = 066; // 7.1 }