1 /* Copyright (C) 2000, 2003 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";
20 const char *const foo
= "hello world";
22 if (strlen (foo
) != 11)
24 if (strlen (foo
+ 4) != 7)
26 if (strlen (foo
+ (x
++ & 7)) != 5)
30 if (strcmp (foo
, "hello") <= 0)
32 if (strcmp (foo
+ 2, "llo") <= 0)
34 if (strcmp (foo
, foo
) != 0)
36 if (strcmp (foo
, "hello world ") >= 0)
38 if (strcmp (foo
+ 10, "dx") >= 0)
40 if (strcmp (10 + foo
, "dx") >= 0)
42 if (strcmp (bar
, "") <= 0)
44 if (strcmp ("", bar
) >= 0)
46 if (strcmp (bar
+8, "") != 0)
48 if (strcmp ("", bar
+8) != 0)
50 if (strcmp (bar
+(--x
), "") <= 0 || x
!= 6)
52 if (strcmp ("", bar
+(++x
)) >= 0 || x
!= 7)
54 if (strrchr (foo
, 'x'))
56 if (strrchr (foo
, 'o') != foo
+ 7)
58 if (strrchr (foo
, 'e') != foo
+ 1)
60 if (strrchr (foo
+ 3, 'e'))
62 if (strrchr (foo
, '\0') != foo
+ 11)
64 if (strrchr (bar
, '\0') != bar
+ 8)
66 if (strrchr (bar
+ 4, '\0') != bar
+ 8)
68 if (strrchr (bar
+ (x
++ & 3), '\0') != bar
+ 8)
72 /* Test only one instance of rindex since the code path is the same
73 as that of strrchr. */
74 if (rindex ("hello", 'z') != 0)
77 /* Test at least one instance of the __builtin_ style. We do this
78 to ensure that it works and that the prototype is correct. */
79 if (__builtin_rindex (foo
, 'o') != foo
+ 7)
81 if (__builtin_strrchr (foo
, 'o') != foo
+ 7)
83 if (__builtin_strlen (foo
) != 11)
85 if (__builtin_strcmp (foo
, "hello") <= 0)