1 /* Copyright (C) 2000 Free Software Foundation.
2
3 Ensure all expected transformations of builtin strpbrk occur and
4 perform correctly.
5
6 Written by Kaveh R. Ghazi, 11/6/2000. */
7
8 extern void abort(void);
9 extern char *strpbrk (const char *, const char *);
10 extern int strcmp (const char *, const char *);
11
fn(const char * foo,const char * const * bar)12 void fn (const char *foo, const char *const *bar)
13 {
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();
30
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();
35 }
36
main()37 int main()
38 {
39 const char *const foo[] = { "hello world", "bye bye world" };
40 fn (foo[0], foo + 1);
41 return 0;
42 }
43
44
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 *
strpbrk(const char * s1,const char * s2)51 strpbrk(const char *s1, const char *s2)
52 {
53 abort();
54 }
55 #endif
56