misra: avoid fp for essentially boolean conditions when bitfield member is used
This commit is contained in:
parent
59cc479855
commit
2a9ee563c2
|
@ -46,6 +46,7 @@ class ValueType:
|
|||
|
||||
type = None
|
||||
sign = None
|
||||
bits = 0
|
||||
constness = 0
|
||||
pointer = 0
|
||||
typeScopeId = None
|
||||
|
@ -55,6 +56,9 @@ class ValueType:
|
|||
def __init__(self, element):
|
||||
self.type = element.get('valueType-type')
|
||||
self.sign = element.get('valueType-sign')
|
||||
bits = element.get('valueType-bits')
|
||||
if bits:
|
||||
self.bits = int(bits)
|
||||
self.typeScopeId = element.get('valueType-typeScope')
|
||||
self.originalTypeName = element.get('valueType-originalTypeName')
|
||||
constness = element.get('valueType-constness')
|
||||
|
|
|
@ -216,7 +216,7 @@ def hasSideEffectsRecursive(expr):
|
|||
def isBoolExpression(expr):
|
||||
if not expr:
|
||||
return False
|
||||
if expr.valueType and expr.valueType.type == 'bool':
|
||||
if expr.valueType and (expr.valueType.type == 'bool' or expr.valueType.bits == 1):
|
||||
return True
|
||||
return expr.str in ['!', '==', '!=', '<', '<=', '>', '>=', '&&', '||', '0', '1']
|
||||
|
||||
|
|
|
@ -153,12 +153,18 @@ void misra_14_2() {
|
|||
// TODO check more variants
|
||||
}
|
||||
|
||||
struct {
|
||||
unsigned int x:1;
|
||||
unsigned int y:1;
|
||||
} _14_4_struct;
|
||||
void misra_14_4(bool b) {
|
||||
if (x+4){} // 14.4
|
||||
else {}
|
||||
|
||||
if (b) {}
|
||||
else {}
|
||||
|
||||
if (_14_4_struct.x) {}
|
||||
}
|
||||
|
||||
void misra_15_1() {
|
||||
|
|
Loading…
Reference in New Issue