1 /* Copyright (C) 2000, 2003 Free Software Foundation.
3 Ensure all expected transformations of builtin strcat occur and
6 Written by Kaveh R. Ghazi, 11/27/2000. */
8 extern int inside_main
;
9 extern void abort (void);
10 typedef __SIZE_TYPE__
size_t;
11 extern char *strcat (char *, const char *);
12 extern char *strcpy (char *, const char *);
13 extern void *memset (void *, int, size_t);
14 extern int memcmp (const void *, const void *, size_t);
15 #define RESET_DST_WITH(FILLER) \
16 do { memset (dst, 'X', sizeof (dst)); strcpy (dst, (FILLER)); } while (0)
20 const char *const s1
= "hello world";
21 const char *const s2
= "";
25 if (strcat (dst
, "") != dst
|| memcmp (dst
, "hello world\0XXX", 15))
28 if (strcat (dst
, s2
) != dst
|| memcmp (dst
, "hello world\0XXX", 15))
30 RESET_DST_WITH (s1
); d2
= dst
;
31 if (strcat (++d2
, s2
) != dst
+1 || d2
!= dst
+1
32 || memcmp (dst
, "hello world\0XXX", 15))
34 RESET_DST_WITH (s1
); d2
= dst
;
35 if (strcat (++d2
+5, s2
) != dst
+6 || d2
!= dst
+1
36 || memcmp (dst
, "hello world\0XXX", 15))
38 RESET_DST_WITH (s1
); d2
= dst
;
39 if (strcat (++d2
+5, s1
+11) != dst
+6 || d2
!= dst
+1
40 || memcmp (dst
, "hello world\0XXX", 15))
43 #ifndef __OPTIMIZE_SIZE__
44 # if !defined __i386__ && !defined __x86_64__
45 /* The functions below might not be optimized into direct stores on all
46 arches. It depends on how many instructions would be generated and
47 what limits the architecture chooses in STORE_BY_PIECES_P. */
52 if (strcat (dst
, " 1111") != dst
53 || memcmp (dst
, "hello world 1111\0XXX", 20))
57 if (strcat (dst
+5, " 2222") != dst
+5
58 || memcmp (dst
, "hello world 2222\0XXX", 20))
61 RESET_DST_WITH (s1
); d2
= dst
;
62 if (strcat (++d2
+5, " 3333") != dst
+6 || d2
!= dst
+1
63 || memcmp (dst
, "hello world 3333\0XXX", 20))
67 strcat (strcat (strcat (strcat (strcat (strcat (dst
, ": this "), ""),
68 "is "), "a "), "test"), ".");
69 if (memcmp (dst
, "hello world: this is a test.\0X", 30))
72 /* Set inside_main again. */
76 /* Test at least one instance of the __builtin_ style. We do this
77 to ensure that it works and that the prototype is correct. */
79 if (__builtin_strcat (dst
, "") != dst
|| memcmp (dst
, "hello world\0XXX", 15))