1 /* Copyright (C) 2000, 2003 Free Software Foundation.
3 Ensure all expected transformations of builtin strstr occur and
4 perform correctly in presence of redirect. */
6 typedef __SIZE_TYPE__
size_t;
7 extern void abort (void);
8 extern char *strstr (const char *, const char *)
10 extern char *strchr (const char *, int);
11 extern int strcmp (const char *, const char *);
12 extern int strncmp (const char *, const char *, size_t);
14 const char *p
= "rld", *q
= "hello world";
19 const char *const foo
= "hello world";
21 if (strstr (foo
, "") != foo
)
23 if (strstr (foo
+ 4, "") != foo
+ 4)
25 if (strstr (foo
, "h") != foo
)
27 if (strstr (foo
, "w") != foo
+ 6)
29 if (strstr (foo
+ 6, "o") != foo
+ 7)
31 if (strstr (foo
+ 1, "world") != foo
+ 6)
33 if (strstr (foo
+ 2, p
) != foo
+ 8)
35 if (strstr (q
, "") != q
)
37 if (strstr (q
+ 1, "o") != q
+ 4)
40 /* Test at least one instance of the __builtin_ style. We do this
41 to ensure that it works and that the prototype is correct. */
42 if (__builtin_strstr (foo
+ 1, "world") != foo
+ 6)
48 /* There should be no calls to real strstr. */
49 static char *real_strstr (const char *, const char *)
52 __attribute__ ((noinline
))
54 real_strstr (const char *s1
, const char *s2
)
60 strstr (const char *s1
, const char *s2
)
63 __attribute__ ((noinline
))
65 strstr (const char *s1
, const char *s2
)
67 size_t len
= strlen (s2
);
70 /* If optimizing, we should be called only in the
71 strstr (foo + 2, p) case above. All other cases should
73 if (s2
!= p
|| strcmp (s1
, "hello world" + 2) != 0)
78 for (s1
= strchr (s1
, *s2
); s1
; s1
= strchr (s1
+ 1, *s2
))
79 if (strncmp (s1
, s2
, len
) == 0)