PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtins / lib / strncmp.c
blob7a8eb6fd27eb1044e11273d6b2deb16469b8254c
1 extern void abort (void);
2 extern int inside_main;
4 typedef __SIZE_TYPE__ size_t;
6 __attribute__ ((__noinline__))
7 int
8 strncmp(const char *s1, const char *s2, size_t n)
10 const unsigned char *u1 = (const unsigned char *)s1;
11 const unsigned char *u2 = (const unsigned char *)s2;
12 unsigned char c1, c2;
14 #ifdef __OPTIMIZE__
15 if (inside_main)
16 abort();
17 #endif
19 while (n > 0)
21 c1 = *u1++, c2 = *u2++;
22 if (c1 == '\0' || c1 != c2)
23 return c1 - c2;
24 n--;
26 return c1 - c2;