1 /* Copyright (C) 2000, 2001 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);
14 const char *const s1 = "hello world";
18 if (strncmp (s1, "hello world", 12) != 0)
20 if (strncmp ("hello world", s1, 12) != 0)
22 if (strncmp ("hello", "hello", 6) != 0)
24 if (strncmp ("hello", "hello", 2) != 0)
26 if (strncmp ("hello", "hello", 100) != 0)
28 if (strncmp (s1+10, "d", 100) != 0)
30 if (strncmp (10+s1, "d", 100) != 0)
32 if (strncmp ("d", s1+10, 1) != 0)
34 if (strncmp ("d", 10+s1, 1) != 0)
36 if (strncmp ("hello", "aaaaa", 100) <= 0)
38 if (strncmp ("aaaaa", "hello", 100) >= 0)
40 if (strncmp ("hello", "aaaaa", 1) <= 0)
42 if (strncmp ("aaaaa", "hello", 1) >= 0)
46 if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5)
49 if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1)
51 if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2)
53 if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3)
55 if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4)
57 if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5)
59 if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6)
61 if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7)
63 if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8)
66 if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5)
68 #if defined(__i386__) || defined (__pj__) || defined (__i370__)
69 /* These tests work on platforms which support cmpstrsi. */
71 if (strncmp (++s2, "ello", 3) != 0 || s2 != s1+1)
74 if (strncmp ("ello", ++s2, 3) != 0 || s2 != s1+1)
77 if (strncmp (++s2, "ello", 4) != 0 || s2 != s1+1)
80 if (strncmp ("ello", ++s2, 4) != 0 || s2 != s1+1)
83 if (strncmp (++s2, "ello", 5) <= 0 || s2 != s1+1)
86 if (strncmp ("ello", ++s2, 5) >= 0 || s2 != s1+1)
89 if (strncmp (++s2, "ello", 6) <= 0 || s2 != s1+1)
92 if (strncmp ("ello", ++s2, 6) >= 0 || s2 != s1+1)
96 if (strncmp (++s2, "zllo", 3) >= 0 || s2 != s1+1)
99 if (strncmp ("zllo", ++s2, 3) <= 0 || s2 != s1+1)
102 if (strncmp (++s2, "zllo", 4) >= 0 || s2 != s1+1)
105 if (strncmp ("zllo", ++s2, 4) <= 0 || s2 != s1+1)
108 if (strncmp (++s2, "zllo", 5) >= 0 || s2 != s1+1)
111 if (strncmp ("zllo", ++s2, 5) <= 0 || s2 != s1+1)
114 if (strncmp (++s2, "zllo", 6) >= 0 || s2 != s1+1)
117 if (strncmp ("zllo", ++s2, 6) <= 0 || s2 != s1+1)
121 if (strncmp (++s2, "allo", 3) <= 0 || s2 != s1+1)
124 if (strncmp ("allo", ++s2, 3) >= 0 || s2 != s1+1)
127 if (strncmp (++s2, "allo", 4) <= 0 || s2 != s1+1)
130 if (strncmp ("allo", ++s2, 4) >= 0 || s2 != s1+1)
133 if (strncmp (++s2, "allo", 5) <= 0 || s2 != s1+1)
136 if (strncmp ("allo", ++s2, 5) >= 0 || s2 != s1+1)
139 if (strncmp (++s2, "allo", 6) <= 0 || s2 != s1+1)
142 if (strncmp ("allo", ++s2, 6) >= 0 || s2 != s1+1)
145 s2 = s1; n = 2; x = 1;
146 if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 3)
148 s2 = s1; n = 2; x = 1;
149 if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 3)
151 s2 = s1; n = 3; x = 1;
152 if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 4)
154 s2 = s1; n = 3; x = 1;
155 if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 4)
157 s2 = s1; n = 4; x = 1;
158 if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 5)
160 s2 = s1; n = 4; x = 1;
161 if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 5)
163 s2 = s1; n = 5; x = 1;
164 if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 6)
166 s2 = s1; n = 5; x = 1;
167 if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 6)
171 if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 3)
173 s2 = s1; n = 2; x = 1;
174 if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 3)
176 s2 = s1; n = 3; x = 1;
177 if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 4)
179 s2 = s1; n = 3; x = 1;
180 if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 4)
182 s2 = s1; n = 4; x = 1;
183 if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 5)
185 s2 = s1; n = 4; x = 1;
186 if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 5)
188 s2 = s1; n = 5; x = 1;
189 if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 6)
191 s2 = s1; n = 5; x = 1;
192 if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 6)
196 if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 3)
198 s2 = s1; n = 2; x = 1;
199 if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 3)
201 s2 = s1; n = 3; x = 1;
202 if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 4)
204 s2 = s1; n = 3; x = 1;
205 if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 4)
207 s2 = s1; n = 4; x = 1;
208 if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 5)
210 s2 = s1; n = 4; x = 1;
211 if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 5)
213 s2 = s1; n = 5; x = 1;
214 if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 6)
216 s2 = s1; n = 5; x = 1;
217 if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 6)
222 /* Test at least one instance of the __builtin_ style. We do this
223 to ensure that it works and that the prototype is correct. */
224 if (__builtin_strncmp ("hello", "a", 100) <= 0)
231 /* When optimizing, all the above cases should be transformed into
232 something else. So any remaining calls to the original function
235 strncmp(const char *s1, const char *s2, size_t n)