PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtins / strcpy-2.c
blobc3cb6d0e52119a59a051de333ee4f57d2ebf2248
1 /* Copyright (C) 2004 Free Software Foundation.
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.
8 Written by Jakub Jelinek, 9/15/2004. */
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);
16 char buf[32], *p;
17 int i;
19 char *
20 __attribute__((noinline))
21 test (void)
23 int j;
24 const char *q = "abcdefg";
25 for (j = 0; j < 3; ++j)
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";
34 p = strcpy (buf, q);
35 return strcpy (buf + 16, q);
38 void
39 main_test (void)
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