Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.dg / duff-2.c
blob8b8923eb94340b7f965b0eda4eaff30d05907b79
1 /* Duff's device is legal C; test to make sure the compiler
2 doesn't complain about it.
4 Jason Thorpe <thorpej@wasabisystems.com>
5 Derived from the BSD Telnet Kerberos 4 checksum routine.
6 See also PR 5230. */
8 /* { dg-do run } */
9 /* { dg-options "-O2" } */
11 extern void abort (void);
12 extern void exit (int);
14 #if __INT_MAX__ >= 2147483647
15 /* At least 32-bit integers. */
16 typedef int type32;
17 #else
18 typedef long type32;
19 #endif
21 type32
22 cksum (const unsigned char *src, unsigned long size)
24 type32 ck = 0;
26 switch (size & 3)
28 while (size > 0)
30 case 0:
31 ck ^= (type32)*src++ << 24;
32 --size;
33 case 3:
34 ck ^= (type32)*src++ << 16;
35 --size;
36 case 2:
37 ck ^= (type32)*src++ << 8;
38 --size;
39 case 1:
40 ck ^= (type32)*src++;
41 --size;
45 return ck;
48 const char testpat[] = "The quick brown fox jumped over the lazy dog.";
50 int
51 main()
53 type32 ck;
55 ck = cksum ((const unsigned char *) testpat, sizeof (testpat));
56 if (ck != 925902908)
57 abort ();
59 exit (0);