2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / string-opt-1.c
blob6b59c10f29b7a8e59aa45f4e345efe55ceb2b66a
1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strstr occur and
4 perform correctly.
6 Written by Kaveh R. Ghazi, 11/6/2000. */
8 extern void abort(void);
9 extern char *strstr (const char *, const char *);
11 int main()
13 const char *const foo = "hello world";
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();
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();
33 return 0;
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. */
40 __attribute__ ((noinline))
41 static char *
42 strstr(const char *s1, const char *s2)
44 abort();
46 #endif