annotate gcc/testsuite/gcc.dg/duff-3.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Duff's device is legal C; test to make sure the compiler
kono
parents:
diff changeset
2 doesn't complain about it.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 Jason Thorpe <thorpej@wasabisystems.com>
kono
parents:
diff changeset
5 Derived from Tom Duff's original usenet message about the device. */
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 /* { dg-do run } */
kono
parents:
diff changeset
8 /* { dg-options "-O2" } */
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 extern void abort (void);
kono
parents:
diff changeset
11 extern void exit (int);
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 typedef __SIZE_TYPE__ size_t;
kono
parents:
diff changeset
14 extern int memcmp (const void *, const void *, size_t);
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 void
kono
parents:
diff changeset
17 duffcpy (char *dst, const char *src, unsigned long size)
kono
parents:
diff changeset
18 {
kono
parents:
diff changeset
19 unsigned long n = (size + 7) / 8;
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 switch (size % 8)
kono
parents:
diff changeset
22 {
kono
parents:
diff changeset
23 case 0: do { *dst++ = *src++;
kono
parents:
diff changeset
24 case 7: *dst++ = *src++;
kono
parents:
diff changeset
25 case 6: *dst++ = *src++;
kono
parents:
diff changeset
26 case 5: *dst++ = *src++;
kono
parents:
diff changeset
27 case 4: *dst++ = *src++;
kono
parents:
diff changeset
28 case 3: *dst++ = *src++;
kono
parents:
diff changeset
29 case 2: *dst++ = *src++;
kono
parents:
diff changeset
30 case 1: *dst++ = *src++;
kono
parents:
diff changeset
31 } while (--n > 0);
kono
parents:
diff changeset
32 }
kono
parents:
diff changeset
33 }
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 const char testpat[] = "The quick brown fox jumped over the lazy dog.";
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 int
kono
parents:
diff changeset
38 main()
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 char buf[64];
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 duffcpy (buf, testpat, sizeof (testpat));
kono
parents:
diff changeset
43 if (memcmp (buf, testpat, sizeof (testpat)) != 0)
kono
parents:
diff changeset
44 abort ();
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 exit (0);
kono
parents:
diff changeset
47 }