1 /* Copyright (C) 2004 Free Software Foundation.
2
3 Ensure builtin strcpy is optimized into memcpy
4 even when there is more than one possible string literal
5 passed to it, but all string literals passed to it
6 have equal length.
7
8 Written by Jakub Jelinek, 9/15/2004. */
9
10 extern void abort (void);
11 extern char *strcpy (char *, const char *);
12 typedef __SIZE_TYPE__ size_t;
13 extern void *memcpy (void *, const void *, size_t);
14 extern int memcmp (const void *, const void *, size_t);
15
16 char buf[32], *p;
17 int i;
18
19 char *
20 __attribute__((noinline))
test(void)21 test (void)
22 {
23 int j;
24 const char *q = "abcdefg";
25 for (j = 0; j < 3; ++j)
26 {
27 if (j == i)
28 q = "bcdefgh";
29 else if (j == i + 1)
30 q = "cdefghi";
31 else if (j == i + 2)
32 q = "defghij";
33 }
34 p = strcpy (buf, q);
35 return strcpy (buf + 16, q);
36 }
37
38 void
main_test(void)39 main_test (void)
40 {
41 #ifndef __OPTIMIZE_SIZE__
42 /* For -Os, strcpy above is not replaced with
43 memcpy (buf, q, 8);, as that is larger. */
44 if (test () != buf + 16 || p != buf)
45 abort ();
46 #endif
47 }
48