Skip to content

Commit aba9528

Browse files
committed
RULE-10-3: Expand test cases for binary bitwise operators
1 parent a5ed461 commit aba9528

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

c/misra/test/rules/RULE-10-3/AssignmentOfIncompatibleEssentialType.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,9 @@
131131
| test.c:356:10:356:11 | e1 | Assignment of essentially Enum Type value to an object of essentially Floating type. |
132132
| test.c:357:10:357:10 | s | Assignment of essentially Signed type value to an object of essentially Floating type. |
133133
| test.c:358:10:358:10 | u | Assignment of essentially Unsigned type value to an object of essentially Floating type. |
134+
| test.c:369:12:369:20 | ... & ... | Assignment of essentially Unsigned type value to an object of essentially Signed type. |
135+
| test.c:370:12:370:20 | ... \| ... | Assignment of essentially Unsigned type value to an object of essentially Signed type. |
136+
| test.c:371:12:371:20 | ... ^ ... | Assignment of essentially Unsigned type value to an object of essentially Signed type. |
137+
| test.c:376:20:376:27 | ... & ... | Assignment of value of essentially Signed type of size 2 bytes to an object narrower essential type of size 1 bytes. |
138+
| test.c:381:23:381:30 | ... & ... | Assignment of value of essentially Unsigned type of size 2 bytes to an object narrower essential type of size 1 bytes. |
139+
| test.c:384:22:384:29 | ... & ... | Assignment of essentially Signed type value to an object of essentially Unsigned type. |

c/misra/test/rules/RULE-10-3/test.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,29 @@ void testStructAssignment() {
357357
s1.f = s; // NON_COMPLIANT
358358
s1.f = u; // NON_COMPLIANT
359359
s1.f = f; // COMPLIANT
360+
}
361+
362+
void testBinaryBitwise() {
363+
signed int s32 = 100; // COMPLIANT - wider
364+
signed short s16 = 0; // COMPLIANT - wider
365+
signed char s8 = 0; // COMPLIANT - wider
366+
unsigned int u32 = 100; // COMPLIANT - by exception 1
367+
unsigned char u8 = 0; // COMPLIANT - by exception 1
368+
unsigned short u16 = 0; // COMPLIANT - by exception 1
369+
int x1 = s32 & u32; // NON_COMPLIANT - integer promotion to u32
370+
int x2 = s32 | u32; // NON_COMPLIANT - integer promotion to u32
371+
int x3 = s32 ^ u32; // NON_COMPLIANT - integer promotion to u32
372+
int x4 = s16 & s32; // COMPLIANT
373+
int x5 = s16 & u16; // COMPLIANT
374+
int x6 = s16 & s8; // COMPLIANT
375+
signed short x7 = s16 & s8; // COMPLIANT
376+
signed char x8 = s16 & s8; // NON_COMPLIANT
377+
signed char x9 = s8 & s8; // COMPLIANT
378+
signed short x10 = s8 & s8; // COMPLIANT
379+
unsigned int x11 = u16 & u8; // COMPLIANT
380+
unsigned short x12 = u16 & u8; // COMPLIANT
381+
unsigned char x13 = u16 & u8; // NON_COMPLIANT
382+
unsigned char x14 = u8 & u8; // COMPLIANT
383+
unsigned short x15 = u8 & u8; // COMPLIANT
384+
unsigned int x16 = s16 & s8; // NON_COMPLIANT
360385
}

0 commit comments

Comments
 (0)