diff options
author | thorpej <thorpej@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-19 04:27:13 +0000 |
---|---|---|
committer | thorpej <thorpej@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-19 04:27:13 +0000 |
commit | 2ef337819dbd11db5ebf26d2101180c621c152e6 (patch) | |
tree | 234e4b72677896d4394c8cc46f85801a9ed648c2 /gcc/testsuite/gcc.dg/duff-1.c | |
parent | 68df2b7c7214c12580453e6087905f89968753de (diff) | |
download | gcc-2ef337819dbd11db5ebf26d2101180c621c152e6.tar.gz |
* gcc.dg/duff-1.c: New test.
* gcc.dg/duff-2.c: New test.
* gcc.dg/duff-3.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59240 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/duff-1.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/duff-1.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/duff-1.c b/gcc/testsuite/gcc.dg/duff-1.c new file mode 100644 index 00000000000..b718f6c05e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/duff-1.c @@ -0,0 +1,50 @@ +/* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe <thorpej@wasabisystems.com> + Derived from PR 3846. */ + +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); +extern void exit (int); + +typedef __SIZE_TYPE__ size_t; +extern int memcmp (const void *, const void *, size_t); + +void +duffcpy (char *dst, const char *src, unsigned long size) +{ + switch (size & 3) + { + for (;;) + { + *dst++ = *src++; + case 3: + *dst++ = *src++; + case 2: + *dst++ = *src++; + case 1: + *dst++ = *src++; + case 0: + if (size <= 3) + break; + size -= 4; + } + } +} + +const char testpat[] = "The quick brown fox jumped over the lazy dog."; + +int +main() +{ + char buf[64]; + + duffcpy (buf, testpat, sizeof (testpat)); + if (memcmp (buf, testpat, sizeof (testpat)) != 0) + abort (); + + exit (0); +} |