First version committed to git
[zpugcc/jano.git] / toolchain / gcc / gcc / testsuite / gcc.c-torture / execute / builtins / string-2.c
blob08e87c63d301d8c43f81ad6d3156afe39843e382
1 /* Copyright (C) 2000, 2003 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);
12 void
13 main_test (void)
15 const char *const foo = "hello world";
17 if (strchr (foo, 'x'))
18 abort ();
19 if (strchr (foo, 'o') != foo + 4)
20 abort ();
21 if (strchr (foo + 5, 'o') != foo + 7)
22 abort ();
23 if (strchr (foo, '\0') != foo + 11)
24 abort ();
25 /* Test only one instance of index since the code path is the same
26 as that of strchr. */
27 if (index ("hello", 'z') != 0)
28 abort ();
30 /* Test at least one instance of the __builtin_ style. We do this
31 to ensure that it works and that the prototype is correct. */
32 if (__builtin_strchr (foo, 'o') != foo + 4)
33 abort ();
34 if (__builtin_index (foo, 'o') != foo + 4)
35 abort ();