2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / string-opt-2.c
blobd8ebb77be514aa165c7df0488e6ff5bfaed472b7
1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strpbrk occur and
4 perform correctly.
6 Written by Kaveh R. Ghazi, 11/6/2000. */
8 extern void abort(void);
9 extern char *strpbrk (const char *, const char *);
10 extern int strcmp (const char *, const char *);
12 void fn (const char *foo, const char *const *bar)
14 if (strcmp(strpbrk ("hello world", "lrooo"), "llo world") != 0)
15 abort();
16 if (strpbrk (foo, "") != 0)
17 abort();
18 if (strpbrk (foo + 4, "") != 0)
19 abort();
20 if (strpbrk (*bar--, "") != 0)
21 abort();
22 if (strpbrk (*bar, "h") != foo)
23 abort();
24 if (strpbrk (foo, "h") != foo)
25 abort();
26 if (strpbrk (foo, "w") != foo + 6)
27 abort();
28 if (strpbrk (foo + 6, "o") != foo + 7)
29 abort();
31 /* Test at least one instance of the __builtin_ style. We do this
32 to ensure that it works and that the prototype is correct. */
33 if (__builtin_strpbrk (foo + 6, "o") != foo + 7)
34 abort();
37 int main()
39 const char *const foo[] = { "hello world", "bye bye world" };
40 fn (foo[0], foo + 1);
41 return 0;
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 __attribute__ ((noinline))
50 static char *
51 strpbrk(const char *s1, const char *s2)
53 abort();
55 #endif