1 /* PR tree-optimization/92683 - strncmp incorrect result with equal substrings
4 { dg-options "-O1 -Wall -fdump-tree-forwprop1" } */
6 #define SIZE_MAX __SIZE_MAX__
11 typedef __SIZE_TYPE__
size_t;
17 extern void failure_on_line (int);
19 /* Verify that the test in 'if (EQL strncmp (S, T, N))' is folded. */
20 #define T(eql, s, t, n) do { \
22 if (!(eql __builtin_strncmp (s, t, max))) \
23 failure_on_line (__LINE__); \
26 void test_literal (void)
30 T (0 ==, S123
, S1234
, 0);
31 T (0 ==, S123
, S1234
, 1);
32 T (0 ==, S123
, S1234
, 2);
33 T (0 ==, S123
, S1234
, 3);
34 T (0 >, S123
, S1234
, 4);
35 T (0 >, S123
, S1234
, 5);
36 T (0 >, S123
, S1234
, SIZE_MAX
- 2);
37 T (0 >, S123
, S1234
, SIZE_MAX
- 1);
38 T (0 >, S123
, S1234
, SIZE_MAX
);
40 T (0 ==, S123
+ 1, S1234
, 0);
41 T (0 <, S123
+ 1, S1234
, 1);
42 T (0 <, S123
+ 1, S1234
, 2);
43 T (0 <, S123
+ 1, S1234
, 3);
44 T (0 <, S123
+ 1, S1234
, 4);
45 T (0 <, S123
+ 1, S1234
, SIZE_MAX
- 2);
46 T (0 <, S123
+ 1, S1234
, SIZE_MAX
- 1);
47 T (0 <, S123
+ 1, S1234
, SIZE_MAX
);
49 T (0 ==, S123
+ 1, S1234
+ 1, 0);
50 T (0 ==, S123
+ 1, S1234
+ 1, 1);
51 T (0 ==, S123
+ 1, S1234
+ 1, 2);
52 T (0 >, S123
+ 1, S1234
+ 1, 3);
53 T (0 >, S123
+ 1, S1234
+ 1, SIZE_MAX
- 1);
54 T (0 >, S123
+ 1, S1234
+ 1, SIZE_MAX
);
56 T (0 ==, S123
+ 3, S1234
+ 1, 0);
57 T (0 >, S123
+ 3, S1234
+ 1, 1);
58 T (0 >, S123
+ 3, S1234
+ 1, 2);
59 T (0 >, S123
+ 3, S1234
+ 1, 3);
60 T (0 >, S123
+ 3, S1234
+ 1, SIZE_MAX
- 1);
61 T (0 >, S123
+ 3, S1234
+ 1, SIZE_MAX
);
65 T (zero
==, S123
, S1234
, 0);
66 T (zero
==, S123
, S1234
, 1);
67 T (zero
==, S123
, S1234
, 2);
68 T (zero
==, S123
, S1234
, 3);
69 T (zero
>, S123
, S1234
, 4);
70 T (zero
>, S123
, S1234
, 5);
71 T (zero
>, S123
, S1234
, SIZE_MAX
- 2);
72 T (zero
>, S123
, S1234
, SIZE_MAX
- 1);
73 T (zero
>, S123
, S1234
, SIZE_MAX
);
75 T (zero
==, S123
+ 1, S1234
, 0);
76 T (zero
<, S123
+ 1, S1234
, 1);
77 T (zero
<, S123
+ 1, S1234
, 2);
78 T (zero
<, S123
+ 1, S1234
, 3);
79 T (zero
<, S123
+ 1, S1234
, 4);
80 T (zero
<, S123
+ 1, S1234
, SIZE_MAX
- 2);
81 T (zero
<, S123
+ 1, S1234
, SIZE_MAX
- 1);
82 T (zero
<, S123
+ 1, S1234
, SIZE_MAX
);
84 T (zero
==, S123
+ 1, S1234
+ 1, 0);
85 T (zero
==, S123
+ 1, S1234
+ 1, 1);
86 T (zero
==, S123
+ 1, S1234
+ 1, 2);
87 T (zero
>, S123
+ 1, S1234
+ 1, 3);
88 T (zero
>, S123
+ 1, S1234
+ 1, SIZE_MAX
- 1);
89 T (zero
>, S123
+ 1, S1234
+ 1, SIZE_MAX
);
91 T (zero
==, S123
+ 3, S1234
+ 1, 0);
92 T (zero
>, S123
+ 3, S1234
+ 1, 1);
93 T (zero
>, S123
+ 3, S1234
+ 1, 2);
94 T (zero
>, S123
+ 3, S1234
+ 1, 3);
95 T (zero
>, S123
+ 3, S1234
+ 1, SIZE_MAX
- 1);
96 T (zero
>, S123
+ 3, S1234
+ 1, SIZE_MAX
);
99 const char s123
[] = S123
;
100 const char s1234
[] = S1234
;
102 void test_cst_array (void)
106 T (0 ==, s123
, s1234
, 0);
107 T (0 ==, s123
, s1234
, 1);
108 T (0 ==, s123
, s1234
, 2);
109 T (0 ==, s123
, s1234
, 3);
110 T (0 >, s123
, s1234
, 4);
111 T (0 >, s123
, s1234
, 5);
112 T (0 >, s123
, s1234
, SIZE_MAX
- 2);
113 T (0 >, s123
, s1234
, SIZE_MAX
- 1);
114 T (0 >, s123
, s1234
, SIZE_MAX
);
116 T (0 ==, s123
+ 1, s1234
, 0);
117 T (0 <, s123
+ 1, s1234
, 1);
118 T (0 <, s123
+ 1, s1234
, 2);
119 T (0 <, s123
+ 1, s1234
, 3);
120 T (0 <, s123
+ 1, s1234
, 4);
121 T (0 <, s123
+ 1, s1234
, SIZE_MAX
- 2);
122 T (0 <, s123
+ 1, s1234
, SIZE_MAX
- 1);
123 T (0 <, s123
+ 1, s1234
, SIZE_MAX
);
125 T (0 ==, s123
+ 1, s1234
+ 1, 0);
126 T (0 ==, s123
+ 1, s1234
+ 1, 1);
127 T (0 ==, s123
+ 1, s1234
+ 1, 2);
128 T (0 >, s123
+ 1, s1234
+ 1, 3);
129 T (0 >, s123
+ 1, s1234
+ 1, SIZE_MAX
- 1);
130 T (0 >, s123
+ 1, s1234
+ 1, SIZE_MAX
);
132 T (0 ==, s123
+ 3, s1234
+ 1, 0);
133 T (0 >, s123
+ 3, s1234
+ 1, 1);
134 T (0 >, s123
+ 3, s1234
+ 1, 2);
135 T (0 >, s123
+ 3, s1234
+ 1, 3);
136 T (0 >, s123
+ 3, s1234
+ 1, SIZE_MAX
- 1);
137 T (0 >, s123
+ 3, s1234
+ 1, SIZE_MAX
);
141 T (zero
==, s123
, s1234
, 0);
142 T (zero
==, s123
, s1234
, 1);
143 T (zero
==, s123
, s1234
, 2);
144 T (zero
==, s123
, s1234
, 3);
145 T (zero
>, s123
, s1234
, 4);
146 T (zero
>, s123
, s1234
, 5);
147 T (zero
>, s123
, s1234
, SIZE_MAX
- 2);
148 T (zero
>, s123
, s1234
, SIZE_MAX
- 1);
149 T (zero
>, s123
, s1234
, SIZE_MAX
);
151 T (zero
==, s123
+ 1, s1234
, 0);
152 T (zero
<, s123
+ 1, s1234
, 1);
153 T (zero
<, s123
+ 1, s1234
, 2);
154 T (zero
<, s123
+ 1, s1234
, 3);
155 T (zero
<, s123
+ 1, s1234
, 4);
156 T (zero
<, s123
+ 1, s1234
, SIZE_MAX
- 2);
157 T (zero
<, s123
+ 1, s1234
, SIZE_MAX
- 1);
158 T (zero
<, s123
+ 1, s1234
, SIZE_MAX
);
160 T (zero
==, s123
+ 1, s1234
+ 1, 0);
161 T (zero
==, s123
+ 1, s1234
+ 1, 1);
162 T (zero
==, s123
+ 1, s1234
+ 1, 2);
163 T (zero
>, s123
+ 1, s1234
+ 1, 3);
164 T (zero
>, s123
+ 1, s1234
+ 1, SIZE_MAX
- 1);
165 T (zero
>, s123
+ 1, s1234
+ 1, SIZE_MAX
);
167 T (zero
==, s123
+ 3, s1234
+ 1, 0);
168 T (zero
>, s123
+ 3, s1234
+ 1, 1);
169 T (zero
>, s123
+ 3, s1234
+ 1, 2);
170 T (zero
>, s123
+ 3, s1234
+ 1, 3);
171 T (zero
>, s123
+ 3, s1234
+ 1, SIZE_MAX
- 1);
172 T (zero
>, s123
+ 3, s1234
+ 1, SIZE_MAX
);
175 /* { dg-final { scan-tree-dump-not "strcmp" "forwprop1" } }
176 { dg-final { scan-tree-dump-not "strncmp" "forwprop1" } }
177 { dg-final { scan-tree-dump-not "failure_on_line_" "forwprop1" } } */