1 /* PRE tree-optimization/90626 - fold strcmp(a, b) == 0 to zero when
2 one string length is exact and the other is unequal
4 { dg-options "-O2 -Wall" } */
11 : (__builtin_printf ("assertion failed on line %i: %s\n", \
16 __attribute__ ((noclone
, noinline
, noipa
)) void
17 clobber (void *p
, int x
, size_t n
)
19 for (volatile unsigned char *q
= p
; n
--; )
23 __attribute__ ((noclone
, noinline
, noipa
)) void
32 clobber (a
, 0, sizeof a
);
33 clobber (b
, 0, sizeof b
);
34 clobber (b
+ 4, '5', 1);
36 memcpy (a
, "1234", 4);
37 memcpy (b
, "1234", 4);
39 A (0 > strcmp (a
, b
));
40 A (0 < strcmp (b
, a
));
43 __attribute__ ((noclone
, noinline
, noipa
)) void
50 A (0 == strncmp (a
, b
, 1));
51 A (0 == strncmp (a
, b
, 2));
52 A (0 == strncmp (a
, b
, 3));
53 A (0 < strncmp (a
, b
, 4));
54 A (0 > strncmp (b
, a
, 4));
56 clobber (a
, 0, sizeof a
);
57 clobber (b
, 0, sizeof b
);
58 clobber (b
+ 4, '5', 1);
60 memcpy (a
, "1234", 4);
61 memcpy (b
, "1234", 4);
63 A (0 == strncmp (a
, b
, 4));
64 A (0 > strncmp (a
, b
, 5));
65 A (0 < strncmp (b
, a
, 5));
69 __attribute__ ((noclone
, noinline
, noipa
)) void
70 test_strncmp_a4_cond_s5_s2_2 (const char *s
, int i
)
74 A (0 == strncmp (a4
, i
? "12345" : "12", 2));
78 __attribute__ ((noclone
, noinline
, noipa
)) void
79 test_strncmp_a4_cond_a5_s2_5 (const char *s
, const char *t
, int i
)
84 A (0 == strncmp (a4
, i
? a5
: "12", 5));
87 __attribute__ ((noclone
, noinline
, noipa
)) void
88 test_strncmp_a4_cond_a5_a3_n (const char *s1
, const char *s2
, const char *s3
,
91 char a3
[3], a4
[4], a5
[5];
95 A (0 == strncmp (a4
, i
? a5
: a3
, n
));
103 test_strncmp_a4_cond_s5_s2_2 ("12", 0);
104 test_strncmp_a4_cond_a5_s2_5 ("12", "1234", 0);
106 test_strncmp_a4_cond_a5_a3_n ("12", "1", "1", 0, 1);
107 test_strncmp_a4_cond_a5_a3_n ("", "1", "1234", 1, 1);
109 test_strncmp_a4_cond_a5_a3_n ("12", "12", "1", 0, 2);
110 test_strncmp_a4_cond_a5_a3_n ("", "12", "1234", 1, 2);
112 test_strncmp_a4_cond_a5_a3_n ("12", "123", "1", 0, 2);
113 test_strncmp_a4_cond_a5_a3_n ("", "123", "1234", 1, 3);