Debian Codegraph @

gcc/testsuite/gcc.dg/torture/crc-16.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fdump-tree-crc-details" } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */
4
5 /* A test from busybox - we don't verify, as unsigned is used for the
6 "expected" variable, but 16-bit CRC is calculated. We verify only those cases
7 when CRC variable's size and calculated CRC are equal. In the algorithm we don't
8 check whether "expected" variable's only low half is used. */
9 int receive(/*int read_fd, */int file_fd)
10 {
11 /* Initialization is not the same as in Busybox. */
12 unsigned blockLength = 13;
13 unsigned char blockBuf[1024] = "sgdfsgdfsgdfs";
14 int cksum_or_crc = 0x4561;
15
16 unsigned expected;
17 int i, j;
18 /* ... */
19 expected = 0;
20 for (i = 0; i < blockLength; i++)
21 {
22 expected = expected ^ blockBuf[i] << 8;
23 for (j = 0; j < 8; j++)
24 {
25 if (expected & 0x8000)
26 expected = (expected << 1) ^ 0x1021;
27 else
28 expected = (expected << 1);
29 }
30 }
31 expected &= 0xffff;
32
33 if (cksum_or_crc != expected) {
34 /* ... */
35 return 1; // was - goto timout
36 }
37
38 /* ... */
39 return -1;
40 }