1/* Copyright (C) 2000  Free Software Foundation.
2
3   Ensure all expected transformations of builtin strstr occur and
4   perform correctly.
5
6   Written by Kaveh R. Ghazi, 11/6/2000.  */
7
8extern void abort(void);
9extern char *strstr (const char *, const char *);
10
11int main()
12{
13  const char *const foo = "hello world";
14
15  if (strstr (foo, "") != foo)
16    abort();
17  if (strstr (foo + 4, "") != foo + 4)
18    abort();
19  if (strstr (foo, "h") != foo)
20    abort();
21  if (strstr (foo, "w") != foo + 6)
22    abort();
23  if (strstr (foo + 6, "o") != foo + 7)
24    abort();
25  if (strstr (foo + 1, "world") != foo + 6)
26    abort();
27
28  /* Test at least one instance of the __builtin_ style.  We do this
29     to ensure that it works and that the prototype is correct.  */
30  if (__builtin_strstr (foo + 1, "world") != foo + 6)
31    abort();
32
33  return 0;
34}
35
36#ifdef __OPTIMIZE__
37/* When optimizing, all the above cases should be transformed into
38   something else.  So any remaining calls to the original function
39   should abort.  */
40static char *
41strstr(const char *s1, const char *s2)
42{
43  abort();
44}
45#endif
46