FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / string-opt-9.c
blob0a3edbeb99ec303675071ee7865a09b15fdfe3fa
1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strcat occur and
4 perform correctly.
6 Written by Kaveh R. Ghazi, 11/27/2000. */
8 extern void abort (void);
9 typedef __SIZE_TYPE__ size_t;
10 extern char *strcat (char *, const char *);
11 extern char *strcpy (char *, const char *);
12 extern char *strcmp (const char *, const char *);
14 int main ()
16 const char *const s1 = "hello world";
17 const char *const s2 = "";
18 char dst[64], *d2;
20 strcpy (dst, s1);
21 if (strcat (dst, "") != dst || strcmp (dst, s1))
22 abort();
23 strcpy (dst, s1);
24 if (strcat (dst, s2) != dst || strcmp (dst, s1))
25 abort();
26 strcpy (dst, s1); d2 = dst;
27 if (strcat (++d2, s2) != dst+1 || d2 != dst+1 || strcmp (dst, s1))
28 abort();
29 strcpy (dst, s1); d2 = dst;
30 if (strcat (++d2+5, s2) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
31 abort();
32 strcpy (dst, s1); d2 = dst;
33 if (strcat (++d2+5, s1+11) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
34 abort();
36 /* Test at least one instance of the __builtin_ style. We do this
37 to ensure that it works and that the prototype is correct. */
38 strcpy (dst, s1);
39 if (__builtin_strcat (dst, "") != dst || strcmp (dst, s1))
40 abort();
42 return 0;
45 #ifdef __OPTIMIZE__
46 /* When optimizing, all the above cases should be transformed into
47 something else. So any remaining calls to the original function
48 should abort. */
49 __attribute__ ((noinline))
50 static char *
51 strcat (char *s1, const char *s2)
53 abort();
55 #endif