Skip to content

Commit adb703c

Browse files
committed
Fixed #10487 (FP: misra-c2012-10.6 (bit fields))
1 parent c6f8995 commit adb703c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

addons/misra.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,8 @@ def misra_10_6(self, data):
22652265
e = getEssentialType(token.astOperand2)
22662266
if not e:
22672267
continue
2268-
if bitsOfEssentialType(vt1.type) > bitsOfEssentialType(e):
2268+
lhsbits = vt1.bits if vt1.bits else bitsOfEssentialType(vt1.type)
2269+
if lhsbits > bitsOfEssentialType(e):
22692270
self.reportError(token, 10, 6)
22702271
except ValueError:
22712272
pass

addons/test/misra/misra-test.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,16 @@ static void misra_10_5(uint16_t x) {
707707
res = (float) 'x';
708708
}
709709

710+
struct misra_10_6_s {
711+
unsigned int a:4;
712+
};
710713
static void misra_10_6(u8 x, u32 a, u32 b, char c1, char c2) {
711714
u16 y = x+x; // 10.6
712715
u16 z = ~u8 x ;//10.6
713716
u32 c = ( u16) ( u32 a + u32 b ); //10.6
714717
s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488
718+
struct misra_10_6_s s;
719+
s.a = x & 1U; // no-warning (#10487)
715720
}
716721
static void misra_10_6_1(uint32_t *a, uint16_t b, uint16_t c)
717722
{

0 commit comments

Comments
 (0)