OSDN Git Service

* gcc.c-torture/execute/ieee/rbug.x: XFAIL FreeBSD 5.x.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / string-opt-9.c
1 /* Copyright (C) 2000  Free Software Foundation.
2
3    Ensure all expected transformations of builtin strcat occur and
4    perform correctly.
5
6    Written by Kaveh R. Ghazi, 11/27/2000.  */
7
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 *);
13
14 int main ()
15 {
16   const char *const s1 = "hello world";
17   const char *const s2 = "";
18   char dst[64], *d2;
19   
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();
35
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();
41
42   return 0;
43 }
44
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 static char *
50 strcat (char *s1, const char *s2)
51 {
52   abort();
53 }
54 #endif