Skip to content

Commit a5ed461

Browse files
committed
EssentialTypes: Add test cases for shifts
1 parent 8f81b4e commit a5ed461

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

c/misra/test/c/misra/EssentialTypes.expected

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,76 @@
365365
| test.c:161:3:161:9 | ... ^ ... | int | int | essentially Signed type |
366366
| test.c:161:8:161:9 | (int)... | int | int | essentially Signed type |
367367
| test.c:161:8:161:9 | u8 | uint8_t | uint8_t | essentially Unsigned type |
368+
| test.c:165:16:165:17 | 1 | signed char | signed char | essentially Signed type |
369+
| test.c:170:3:170:4 | 1 | unsigned char | unsigned char | essentially Unsigned type |
370+
| test.c:170:3:170:9 | ... << ... | unsigned char | unsigned char | essentially Unsigned type |
371+
| test.c:170:9:170:9 | 1 | signed char | signed char | essentially Signed type |
372+
| test.c:171:3:171:6 | 256 | unsigned short | unsigned short | essentially Unsigned type |
373+
| test.c:171:3:171:11 | ... << ... | unsigned short | unsigned short | essentially Unsigned type |
374+
| test.c:171:11:171:11 | 1 | signed char | signed char | essentially Signed type |
375+
| test.c:172:3:172:8 | 65536 | unsigned int | unsigned int | essentially Unsigned type |
376+
| test.c:172:3:172:13 | ... << ... | unsigned int | unsigned int | essentially Unsigned type |
377+
| test.c:172:13:172:13 | 1 | signed char | signed char | essentially Signed type |
378+
| test.c:173:3:173:4 | 2 | unsigned char | unsigned char | essentially Unsigned type |
379+
| test.c:173:3:173:9 | ... >> ... | unsigned char | unsigned char | essentially Unsigned type |
380+
| test.c:173:9:173:9 | 1 | signed char | signed char | essentially Signed type |
381+
| test.c:174:3:174:8 | 32768 | unsigned short | unsigned short | essentially Unsigned type |
382+
| test.c:174:3:174:13 | ... >> ... | unsigned short | unsigned short | essentially Unsigned type |
383+
| test.c:174:13:174:13 | 1 | signed char | signed char | essentially Signed type |
384+
| test.c:175:3:175:13 | 2147483648 | unsigned int | unsigned int | essentially Unsigned type |
385+
| test.c:175:3:175:18 | ... >> ... | unsigned int | unsigned int | essentially Unsigned type |
386+
| test.c:175:18:175:18 | 1 | signed char | signed char | essentially Signed type |
387+
| test.c:176:3:176:14 | 4294967295 | unsigned long | unsigned long | essentially Unsigned type |
388+
| test.c:176:3:176:19 | ... << ... | unsigned long | unsigned long | essentially Unsigned type |
389+
| test.c:176:3:176:19 | ... << ... | unsigned long | unsigned long long | essentially Unsigned type |
390+
| test.c:176:3:176:19 | ... << ... | unsigned long long | unsigned long | essentially Unsigned type |
391+
| test.c:176:3:176:19 | ... << ... | unsigned long long | unsigned long long | essentially Unsigned type |
392+
| test.c:176:19:176:19 | 1 | signed char | signed char | essentially Signed type |
393+
| test.c:181:3:181:6 | 256 | unsigned short | unsigned short | essentially Unsigned type |
394+
| test.c:181:3:181:11 | ... >> ... | unsigned char | unsigned char | essentially Unsigned type |
395+
| test.c:181:11:181:11 | 1 | signed char | signed char | essentially Signed type |
396+
| test.c:182:3:182:8 | 65536 | unsigned int | unsigned int | essentially Unsigned type |
397+
| test.c:182:3:182:13 | ... >> ... | unsigned short | unsigned short | essentially Unsigned type |
398+
| test.c:182:13:182:13 | 1 | signed char | signed char | essentially Signed type |
399+
| test.c:183:3:183:13 | 4294967296 | unsigned long | unsigned long | essentially Unsigned type |
400+
| test.c:183:3:183:18 | ... >> ... | unsigned int | unsigned int | essentially Unsigned type |
401+
| test.c:183:18:183:18 | 1 | signed char | signed char | essentially Signed type |
402+
| test.c:184:3:184:6 | 255 | unsigned char | unsigned char | essentially Unsigned type |
403+
| test.c:184:3:184:11 | ... << ... | unsigned short | unsigned short | essentially Unsigned type |
404+
| test.c:184:11:184:11 | 1 | signed char | signed char | essentially Signed type |
405+
| test.c:185:3:185:8 | 65535 | unsigned short | unsigned short | essentially Unsigned type |
406+
| test.c:185:3:185:13 | ... << ... | unsigned int | unsigned int | essentially Unsigned type |
407+
| test.c:185:13:185:13 | 1 | signed char | signed char | essentially Signed type |
408+
| test.c:189:3:189:6 | 255 | unsigned char | unsigned char | essentially Unsigned type |
409+
| test.c:189:3:189:13 | ... >> ... | unsigned char | unsigned char | essentially Unsigned type |
410+
| test.c:189:11:189:13 | s32 | int32_t | int32_t | essentially Signed type |
411+
| test.c:190:3:190:8 | 65535 | unsigned short | unsigned short | essentially Unsigned type |
412+
| test.c:190:3:190:15 | ... >> ... | unsigned short | unsigned short | essentially Unsigned type |
413+
| test.c:190:13:190:15 | s32 | int32_t | int32_t | essentially Signed type |
414+
| test.c:191:3:191:13 | 4294967295 | unsigned int | unsigned int | essentially Unsigned type |
415+
| test.c:191:3:191:20 | ... >> ... | unsigned int | unsigned int | essentially Unsigned type |
416+
| test.c:191:18:191:20 | s32 | int32_t | int32_t | essentially Signed type |
417+
| test.c:192:3:192:6 | 255 | unsigned char | unsigned char | essentially Unsigned type |
418+
| test.c:192:3:192:13 | ... << ... | unsigned char | unsigned char | essentially Unsigned type |
419+
| test.c:192:11:192:13 | s32 | int32_t | int32_t | essentially Signed type |
420+
| test.c:193:3:193:8 | 65535 | unsigned short | unsigned short | essentially Unsigned type |
421+
| test.c:193:3:193:15 | ... << ... | unsigned short | unsigned short | essentially Unsigned type |
422+
| test.c:193:13:193:15 | s32 | int32_t | int32_t | essentially Signed type |
423+
| test.c:194:3:194:13 | 4294967295 | unsigned int | unsigned int | essentially Unsigned type |
424+
| test.c:194:3:194:20 | ... << ... | unsigned int | unsigned int | essentially Unsigned type |
425+
| test.c:194:18:194:20 | s32 | int32_t | int32_t | essentially Signed type |
426+
| test.c:197:3:197:5 | 257 | short | short | essentially Signed type |
427+
| test.c:197:3:197:5 | 257 | short | signed short | essentially Signed type |
428+
| test.c:197:3:197:5 | 257 | signed short | short | essentially Signed type |
429+
| test.c:197:3:197:5 | 257 | signed short | signed short | essentially Signed type |
430+
| test.c:197:3:197:10 | ... >> ... | int | int | essentially Signed type |
431+
| test.c:197:10:197:10 | 1 | signed char | signed char | essentially Signed type |
432+
| test.c:198:3:198:7 | 65537 | int | int | essentially Signed type |
433+
| test.c:198:3:198:7 | 65537 | int | signed int | essentially Signed type |
434+
| test.c:198:3:198:7 | 65537 | signed int | int | essentially Signed type |
435+
| test.c:198:3:198:7 | 65537 | signed int | signed int | essentially Signed type |
436+
| test.c:198:3:198:12 | ... >> ... | int | int | essentially Signed type |
437+
| test.c:198:12:198:12 | 1 | signed char | signed char | essentially Signed type |
438+
| test.c:199:3:199:12 | 4294967297 | long | long | essentially Signed type |
439+
| test.c:199:3:199:17 | ... >> ... | long | long | essentially Signed type |
440+
| test.c:199:17:199:17 | 1 | signed char | signed char | essentially Signed type |

c/misra/test/c/misra/test.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,42 @@ void testBitwise() {
159159
s32 ^ u8; // Essentially signed, int
160160
u8 ^ s8; // Essentially signed, int
161161
s8 ^ u8; // Essentially signed, int
162+
}
163+
164+
void testShifts() {
165+
int32_t s32 = 1;
166+
167+
// Left hand is unsigned and both are constants, so UTLR
168+
// In these cases the UTLR is the same as the essential type of
169+
// the left operand
170+
1U << 1; // Essentially unsigned char
171+
256U << 1; // Essentially unsigned short
172+
65536U << 1; // Essentially unsigned int
173+
2U >> 1; // Essentially unsigned char
174+
32768U >> 1; // Essentially unsigned short - 2^15 >> 1 = 2^14
175+
2147483648U >> 1; // Essentially unsigned int - 2^31 >> 1 = 2^30
176+
4294967295LU << 1; // Essentially unsigned long
177+
178+
// Left hand is unsigned and both are constants, so UTLR
179+
// In these cases the UTLR is not the same as the essential type of
180+
// the left operand
181+
256U >> 1; // Essentially unsigned char
182+
65536U >> 1; // Essentially unsigned short
183+
4294967296U >> 1; // Essentially unsigned int
184+
255U << 1; // Essentially unsigned short
185+
65535U << 1; // Essentially unsigned int
186+
187+
// Left hand is unsigned, but left isn't a constant, so essential type of left
188+
// operand
189+
255U >> s32; // Essentially unsigned char
190+
65535U >> s32; // Essentially unsigned short
191+
4294967295U >> s32; // Essentially unsigned int
192+
255U << s32; // Essentially unsigned char
193+
65535U << s32; // Essentially unsigned short
194+
4294967295U << s32; // Essentially unsigned int
195+
196+
// Left hand operand signed int, so result is standard type
197+
257 >> 1; // Essentially signed int
198+
65537 >> 1; // Essentially signed int
199+
4294967297 >> 1; // Essentially signed long
162200
}

0 commit comments

Comments
 (0)