1 /* Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation.
3 Ensure all expected transformations of builtin strncmp occur and
6 Written by Kaveh R. Ghazi, 11/26/2000. */
8 extern void abort (void);
9 typedef __SIZE_TYPE__
size_t;
10 extern int strncmp (const char *, const char *, size_t);
15 #if !defined(__OPTIMIZE__) || ((defined(__i386__) || defined (__x86_64__)) && !defined(__OPTIMIZE_SIZE__))
16 /* These tests work on platforms which support cmpstrsi. We test it
17 at -O0 on all platforms to ensure the strncmp logic is correct. */
18 const char *const s1
= "hello world";
23 if (strncmp (++s2
, "ello", 3) != 0 || s2
!= s1
+1)
26 if (strncmp ("ello", ++s2
, 3) != 0 || s2
!= s1
+1)
29 if (strncmp (++s2
, "ello", 4) != 0 || s2
!= s1
+1)
32 if (strncmp ("ello", ++s2
, 4) != 0 || s2
!= s1
+1)
35 if (strncmp (++s2
, "ello", 5) <= 0 || s2
!= s1
+1)
38 if (strncmp ("ello", ++s2
, 5) >= 0 || s2
!= s1
+1)
41 if (strncmp (++s2
, "ello", 6) <= 0 || s2
!= s1
+1)
44 if (strncmp ("ello", ++s2
, 6) >= 0 || s2
!= s1
+1)
48 if (strncmp (++s2
, "zllo", 3) >= 0 || s2
!= s1
+1)
51 if (strncmp ("zllo", ++s2
, 3) <= 0 || s2
!= s1
+1)
54 if (strncmp (++s2
, "zllo", 4) >= 0 || s2
!= s1
+1)
57 if (strncmp ("zllo", ++s2
, 4) <= 0 || s2
!= s1
+1)
60 if (strncmp (++s2
, "zllo", 5) >= 0 || s2
!= s1
+1)
63 if (strncmp ("zllo", ++s2
, 5) <= 0 || s2
!= s1
+1)
66 if (strncmp (++s2
, "zllo", 6) >= 0 || s2
!= s1
+1)
69 if (strncmp ("zllo", ++s2
, 6) <= 0 || s2
!= s1
+1)
73 if (strncmp (++s2
, "allo", 3) <= 0 || s2
!= s1
+1)
76 if (strncmp ("allo", ++s2
, 3) >= 0 || s2
!= s1
+1)
79 if (strncmp (++s2
, "allo", 4) <= 0 || s2
!= s1
+1)
82 if (strncmp ("allo", ++s2
, 4) >= 0 || s2
!= s1
+1)
85 if (strncmp (++s2
, "allo", 5) <= 0 || s2
!= s1
+1)
88 if (strncmp ("allo", ++s2
, 5) >= 0 || s2
!= s1
+1)
91 if (strncmp (++s2
, "allo", 6) <= 0 || s2
!= s1
+1)
94 if (strncmp ("allo", ++s2
, 6) >= 0 || s2
!= s1
+1)
97 s2
= s1
; n
= 2; x
= 1;
98 if (strncmp (++s2
, s1
+(x
&3), ++n
) != 0 || s2
!= s1
+1 || n
!= 3)
100 s2
= s1
; n
= 2; x
= 1;
101 if (strncmp (s1
+(x
&3), ++s2
, ++n
) != 0 || s2
!= s1
+1 || n
!= 3)
103 s2
= s1
; n
= 3; x
= 1;
104 if (strncmp (++s2
, s1
+(x
&3), ++n
) != 0 || s2
!= s1
+1 || n
!= 4)
106 s2
= s1
; n
= 3; x
= 1;
107 if (strncmp (s1
+(x
&3), ++s2
, ++n
) != 0 || s2
!= s1
+1 || n
!= 4)
109 s2
= s1
; n
= 4; x
= 1;
110 if (strncmp (++s2
, s1
+(x
&3), ++n
) != 0 || s2
!= s1
+1 || n
!= 5)
112 s2
= s1
; n
= 4; x
= 1;
113 if (strncmp (s1
+(x
&3), ++s2
, ++n
) != 0 || s2
!= s1
+1 || n
!= 5)
115 s2
= s1
; n
= 5; x
= 1;
116 if (strncmp (++s2
, s1
+(x
&3), ++n
) != 0 || s2
!= s1
+1 || n
!= 6)
118 s2
= s1
; n
= 5; x
= 1;
119 if (strncmp (s1
+(x
&3), ++s2
, ++n
) != 0 || s2
!= s1
+1 || n
!= 6)
123 if (strncmp (++s2
, "zllo", ++n
) >= 0 || s2
!= s1
+1 || n
!= 3)
125 s2
= s1
; n
= 2; x
= 1;
126 if (strncmp ("zllo", ++s2
, ++n
) <= 0 || s2
!= s1
+1 || n
!= 3)
128 s2
= s1
; n
= 3; x
= 1;
129 if (strncmp (++s2
, "zllo", ++n
) >= 0 || s2
!= s1
+1 || n
!= 4)
131 s2
= s1
; n
= 3; x
= 1;
132 if (strncmp ("zllo", ++s2
, ++n
) <= 0 || s2
!= s1
+1 || n
!= 4)
134 s2
= s1
; n
= 4; x
= 1;
135 if (strncmp (++s2
, "zllo", ++n
) >= 0 || s2
!= s1
+1 || n
!= 5)
137 s2
= s1
; n
= 4; x
= 1;
138 if (strncmp ("zllo", ++s2
, ++n
) <= 0 || s2
!= s1
+1 || n
!= 5)
140 s2
= s1
; n
= 5; x
= 1;
141 if (strncmp (++s2
, "zllo", ++n
) >= 0 || s2
!= s1
+1 || n
!= 6)
143 s2
= s1
; n
= 5; x
= 1;
144 if (strncmp ("zllo", ++s2
, ++n
) <= 0 || s2
!= s1
+1 || n
!= 6)
148 if (strncmp (++s2
, "allo", ++n
) <= 0 || s2
!= s1
+1 || n
!= 3)
150 s2
= s1
; n
= 2; x
= 1;
151 if (strncmp ("allo", ++s2
, ++n
) >= 0 || s2
!= s1
+1 || n
!= 3)
153 s2
= s1
; n
= 3; x
= 1;
154 if (strncmp (++s2
, "allo", ++n
) <= 0 || s2
!= s1
+1 || n
!= 4)
156 s2
= s1
; n
= 3; x
= 1;
157 if (strncmp ("allo", ++s2
, ++n
) >= 0 || s2
!= s1
+1 || n
!= 4)
159 s2
= s1
; n
= 4; x
= 1;
160 if (strncmp (++s2
, "allo", ++n
) <= 0 || s2
!= s1
+1 || n
!= 5)
162 s2
= s1
; n
= 4; x
= 1;
163 if (strncmp ("allo", ++s2
, ++n
) >= 0 || s2
!= s1
+1 || n
!= 5)
165 s2
= s1
; n
= 5; x
= 1;
166 if (strncmp (++s2
, "allo", ++n
) <= 0 || s2
!= s1
+1 || n
!= 6)
168 s2
= s1
; n
= 5; x
= 1;
169 if (strncmp ("allo", ++s2
, ++n
) >= 0 || s2
!= s1
+1 || n
!= 6)