1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strchr and index
4 occur and perform correctly.
6 Written by Jakub Jelinek, 11/7/2000. */
8 extern void abort (void);
9 extern char *strchr (const char *, int);
10 extern char *index (const char *, int);
14 const char *const foo
= "hello world";
16 if (strchr (foo
, 'x'))
18 if (strchr (foo
, 'o') != foo
+ 4)
20 if (strchr (foo
+ 5, 'o') != foo
+ 7)
22 if (strchr (foo
, '\0') != foo
+ 11)
24 /* Test only one instance of index since the code path is the same
26 if (index ("hello", 'z') != 0)
29 /* Test at least one instance of the __builtin_ style. We do this
30 to ensure that it works and that the prototype is correct. */
31 if (__builtin_strchr (foo
, 'o') != foo
+ 4)
33 if (__builtin_index (foo
, 'o') != foo
+ 4)
40 index (const char *s
, int c
)
42 /* For systems which don't have index, we ensure no link failures
43 occur by always providing a backup definition. During
44 optimization this function aborts to catch errors. */
53 /* When optimizing, all the above cases should be transformed into
54 something else. So any remaining calls to the original function
56 __attribute__ ((noinline
))
58 strchr (const char *s
, int c
)