PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtins / strrchr.c
blob3cc8faa2e23a41ae51dfe489cc5772e9cf8d17e7
1 /* Copyright (C) 2000, 2003, 2004 Free Software Foundation.
3 Ensure all expected transformations of builtin strrchr and rindex
4 occur and perform correctly.
6 Written by Jakub Jelinek, 11/7/2000. */
8 extern void abort (void);
9 extern char *strrchr (const char *, int);
10 extern char *rindex (const char *, int);
12 char *bar = "hi world";
13 int x = 7;
15 void
16 main_test (void)
18 const char *const foo = "hello world";
20 if (strrchr (foo, 'x'))
21 abort ();
22 if (strrchr (foo, 'o') != foo + 7)
23 abort ();
24 if (strrchr (foo, 'e') != foo + 1)
25 abort ();
26 if (strrchr (foo + 3, 'e'))
27 abort ();
28 if (strrchr (foo, '\0') != foo + 11)
29 abort ();
30 if (strrchr (bar, '\0') != bar + 8)
31 abort ();
32 if (strrchr (bar + 4, '\0') != bar + 8)
33 abort ();
34 if (strrchr (bar + (x++ & 3), '\0') != bar + 8)
35 abort ();
36 if (x != 8)
37 abort ();
38 /* Test only one instance of rindex since the code path is the same
39 as that of strrchr. */
40 if (rindex ("hello", 'z') != 0)
41 abort ();
43 /* Test at least one instance of the __builtin_ style. We do this
44 to ensure that it works and that the prototype is correct. */
45 if (__builtin_strrchr (foo, 'o') != foo + 7)
46 abort ();
47 if (__builtin_rindex (foo, 'o') != foo + 7)
48 abort ();