libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / strncmp-3.c
blob0e8101cd61b0df3926ac5ccbca6cdb0f28bf7f74
1 /* PR middle-end/95189 - memcmp being wrongly stripped like strcmp
2 { dg-do run }
3 { dg-options "-O2 -Wall" } */
5 #define AB_D "ab\0d"
6 #define ABCDEF_H "abcdef\0h"
7 #define ABCDEFGHIJKLMN_P "abcdefghijklmn\0p"
9 char ab_d[] = AB_D;
10 char abcdef_h[] = ABCDEF_H;
12 extern int strncmp (const char*, const char*, __SIZE_TYPE__);
14 __attribute__((noipa)) void sink (const void *p, ...) { (void)&p; }
16 #define strncmp(a, b, n) (sink (a, b), strncmp (a, b, n))
18 int main (void)
20 int zero = 0;
22 zero += strncmp (ab_d, AB_D, 1);
23 zero += strncmp (ab_d, AB_D, 2);
24 zero += strncmp (ab_d, AB_D, 3);
25 zero += strncmp (ab_d, AB_D, 4);
26 zero += strncmp (ab_d, AB_D, 5);
28 zero += strncmp (ab_d, ABCDEF_H, 1);
29 zero += strncmp (ab_d, ABCDEF_H, 2);
31 zero += strncmp (abcdef_h, AB_D, 2);
33 zero += strncmp (abcdef_h, ABCDEF_H, 2);
34 zero += strncmp (abcdef_h, ABCDEF_H, 3);
35 zero += strncmp (abcdef_h, ABCDEF_H, 4);
36 zero += strncmp (abcdef_h, ABCDEF_H, 5);
37 zero += strncmp (abcdef_h, ABCDEF_H, 6);
38 zero += strncmp (abcdef_h, ABCDEF_H, 7);
39 zero += strncmp (abcdef_h, ABCDEF_H, 8);
40 zero += strncmp (abcdef_h, ABCDEF_H, 9);
42 if (zero != 0)
43 __builtin_abort ();
45 int neg = 0;
47 neg -= strncmp (ab_d, ABCDEF_H, 3) < 0;
48 neg -= strncmp (ab_d, ABCDEF_H, 4) < 0;
49 neg -= strncmp (ab_d, ABCDEF_H, 5) < 0;
50 neg -= strncmp (ab_d, ABCDEF_H, 6) < 0;
51 neg -= strncmp (ab_d, ABCDEF_H, 7) < 0;
52 neg -= strncmp (ab_d, ABCDEF_H, 8) < 0;
53 neg -= strncmp (ab_d, ABCDEF_H, 9) < 0;
55 if (neg != -7)
56 __builtin_abort ();