1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strlen, strcmp,
4 strrchr and rindex occur and perform correctly.
6 Written by Jakub Jelinek, 11/7/2000. */
8 extern void abort (void);
9 extern __SIZE_TYPE__ strlen (const char *);
10 extern int strcmp (const char *, const char *);
11 extern char *strrchr (const char *, int);
12 extern char *rindex (const char *, int);
15 char *bar = "hi world";
19 const char *const foo = "hello world";
21 if (strlen (foo) != 11)
23 if (strlen (foo + 4) != 7)
25 if (strlen (foo + (x++ & 7)) != 5)
29 if (strcmp (foo, "hello") <= 0)
31 if (strcmp (foo + 2, "llo") <= 0)
33 if (strcmp (foo, foo) != 0)
35 if (strcmp (foo, "hello world ") >= 0)
37 if (strcmp (foo + 10, "dx") >= 0)
39 if (strcmp (10 + foo, "dx") >= 0)
41 if (strcmp (bar, "") <= 0)
43 if (strcmp ("", bar) >= 0)
45 if (strcmp (bar+8, "") != 0)
47 if (strcmp ("", bar+8) != 0)
49 if (strcmp (bar+(--x), "") <= 0 || x != 6)
51 if (strcmp ("", bar+(++x)) >= 0 || x != 7)
53 if (strrchr (foo, 'x'))
55 if (strrchr (foo, 'o') != foo + 7)
57 if (strrchr (foo, 'e') != foo + 1)
59 if (strrchr (foo + 3, 'e'))
61 if (strrchr (foo, '\0') != foo + 11)
63 if (strrchr (bar, '\0') != bar + 8)
65 if (strrchr (bar + 4, '\0') != bar + 8)
67 if (strrchr (bar + (x++ & 3), '\0') != bar + 8)
71 /* Test only one instance of rindex since the code path is the same
72 as that of strrchr. */
73 if (rindex ("hello", 'z') != 0)
76 /* Test at least one instance of the __builtin_ style. We do this
77 to ensure that it works and that the prototype is correct. */
78 if (__builtin_rindex (foo, 'o') != foo + 7)
80 if (__builtin_strrchr (foo, 'o') != foo + 7)
82 if (__builtin_strlen (foo) != 11)
84 if (__builtin_strcmp (foo, "hello") <= 0)
91 rindex (const char *s, int c)
93 /* For systems which don't have rindex, we ensure no link failures
94 occur by always providing a backup definition. During
95 optimization this function aborts to catch errors. */
104 /* When optimizing, all the above cases should be transformed into
105 something else. So any remaining calls to the original function
108 strlen (const char *s)
114 strcmp (const char *s1, const char *s2)
120 strrchr (const char *s, int c)