Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.dg / duff-1.c
blobb718f6c05e28368bdea288317c73ee12226168a8
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 PR 3846. */
7 /* { dg-do run } */
8 /* { dg-options "-O2" } */
10 extern void abort (void);
11 extern void exit (int);
13 typedef __SIZE_TYPE__ size_t;
14 extern int memcmp (const void *, const void *, size_t);
16 void
17 duffcpy (char *dst, const char *src, unsigned long size)
19 switch (size & 3)
21 for (;;)
23 *dst++ = *src++;
24 case 3:
25 *dst++ = *src++;
26 case 2:
27 *dst++ = *src++;
28 case 1:
29 *dst++ = *src++;
30 case 0:
31 if (size <= 3)
32 break;
33 size -= 4;
38 const char testpat[] = "The quick brown fox jumped over the lazy dog.";
40 int
41 main()
43 char buf[64];
45 duffcpy (buf, testpat, sizeof (testpat));
46 if (memcmp (buf, testpat, sizeof (testpat)) != 0)
47 abort ();
49 exit (0);