[RISC-V] Avoid unnecessary extensions when value is already extended
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / coreutils-cksum-pr108664.c
blob7ae4e6b06bea96842957c4922674af2f5510c766
1 /* { dg-require-effective-target int32plus } */
2 /* { dg-require-effective-target size24plus } */
4 /* Reduced from coreutils's cksum.c: cksum_slice8 */
6 typedef long unsigned int size_t;
7 typedef unsigned int __uint32_t;
8 typedef unsigned long int __uintmax_t;
9 typedef struct _IO_FILE FILE;
11 #ifndef __cplusplus
12 typedef _Bool bool;
13 #endif
15 extern size_t
16 fread_unlocked(void* __restrict __ptr,
17 size_t __size,
18 size_t __n,
19 FILE* __restrict __stream);
20 extern int
21 feof_unlocked(FILE* __stream) __attribute__((__nothrow__, __leaf__));
22 extern int
23 ferror_unlocked(FILE* __stream) __attribute__((__nothrow__, __leaf__));
24 static __inline __uint32_t
25 __bswap_32(__uint32_t __bsx)
28 return __builtin_bswap32(__bsx);
30 typedef __uint32_t uint32_t;
31 typedef unsigned long int uint_fast32_t;
32 typedef __uintmax_t uintmax_t;
33 extern int*
34 __errno_location(void) __attribute__((__nothrow__, __leaf__))
35 __attribute__((__const__));
36 extern uint_fast32_t const crctab[8][256];
38 static bool
39 cksum_slice8(FILE* fp, uint_fast32_t* crc_out, uintmax_t* length_out)
41 uint32_t buf[(1 << 16) / sizeof(uint32_t)];
42 uint_fast32_t crc = 0;
43 uintmax_t length = 0;
44 size_t bytes_read;
46 if (!fp || !crc_out || !length_out)
47 return 0;
49 while ((bytes_read = fread_unlocked(buf, 1, (1 << 16), fp)) > 0) {
50 uint32_t* datap;
52 if (length + bytes_read < length) {
54 (*__errno_location()) = 75;
55 return 0;
57 length += bytes_read;
59 if (bytes_read == 0) {
60 if (ferror_unlocked(fp))
61 return 0;
64 datap = (uint32_t*)buf;
65 while (bytes_read >= 8) {
66 uint32_t first = *datap++, second = *datap++; /* { dg-bogus "use of uninitialized value" "PR analyzer/108664" } */
67 crc ^= __bswap_32(first);
68 second = __bswap_32(second);
69 crc =
70 (crctab[7][(crc >> 24) & 0xFF] ^ crctab[6][(crc >> 16) & 0xFF] ^
71 crctab[5][(crc >> 8) & 0xFF] ^ crctab[4][(crc)&0xFF] ^
72 crctab[3][(second >> 24) & 0xFF] ^ crctab[2][(second >> 16) & 0xFF] ^
73 crctab[1][(second >> 8) & 0xFF] ^ crctab[0][(second)&0xFF]);
74 bytes_read -= 8;
77 unsigned char* cp = (unsigned char*)datap;
78 while (bytes_read--)
79 crc = (crc << 8) ^ crctab[0][((crc >> 24) ^ *cp++) & 0xFF];
80 if (feof_unlocked(fp))
81 break;
84 *crc_out = crc;
85 *length_out = length;
87 return 1;