1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: long_tests
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
12 // This test is super slow, in particular with msan or tsan. In order to avoid timeouts and to
13 // spend less time waiting for this particular test to complete we compile with optimizations.
14 // ADDITIONAL_COMPILE_FLAGS(msan): -O1
15 // ADDITIONAL_COMPILE_FLAGS(tsan): -O1
19 // template <class InputIterator>
20 // iterator insert (const_iterator p, InputIterator f, InputIterator l);
22 #include "asan_testing.h"
27 #include "test_macros.h"
28 #include "test_iterators.h"
30 #include "test_allocator.h"
31 #include "min_allocator.h"
35 make(int size
, int start
= 0 )
37 const int b
= 4096 / sizeof(int);
41 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
46 for (int i
= 0; i
< init
-start
; ++i
)
48 for (int i
= 0; i
< size
; ++i
)
50 for (int i
= 0; i
< start
; ++i
)
57 test(int P
, const C
& c0
, const C
& c2
)
60 typedef typename
C::const_iterator CI
;
61 typedef cpp17_input_iterator
<CI
> BCI
;
63 std::size_t c1_osize
= c1
.size();
64 CI i
= c1
.insert(c1
.begin() + P
, BCI(c2
.begin()), BCI(c2
.end()));
65 assert(i
== c1
.begin() + P
);
66 assert(c1
.size() == c1_osize
+ c2
.size());
67 assert(static_cast<std::size_t>(std::distance(c1
.begin(), c1
.end())) == c1
.size());
68 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
69 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
71 for (int j
= 0; j
< P
; ++j
, ++i
)
73 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
75 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
79 typedef typename
C::const_iterator CI
;
80 typedef forward_iterator
<CI
> BCI
;
82 std::size_t c1_osize
= c1
.size();
83 CI i
= c1
.insert(c1
.begin() + P
, BCI(c2
.begin()), BCI(c2
.end()));
84 assert(i
== c1
.begin() + P
);
85 assert(c1
.size() == c1_osize
+ c2
.size());
86 assert(static_cast<std::size_t>(std::distance(c1
.begin(), c1
.end())) == c1
.size());
88 for (int j
= 0; j
< P
; ++j
, ++i
)
90 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
92 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
96 typedef typename
C::const_iterator CI
;
97 typedef bidirectional_iterator
<CI
> BCI
;
99 std::size_t c1_osize
= c1
.size();
100 CI i
= c1
.insert(c1
.begin() + P
, BCI(c2
.begin()), BCI(c2
.end()));
101 assert(i
== c1
.begin() + P
);
102 assert(c1
.size() == c1_osize
+ c2
.size());
103 assert(static_cast<std::size_t>(std::distance(c1
.begin(), c1
.end())) == c1
.size());
105 for (int j
= 0; j
< P
; ++j
, ++i
)
107 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
109 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
116 testN(int start
, int N
, int M
)
118 for (int i
= 0; i
<= 3; ++i
)
120 if (0 <= i
&& i
<= N
)
122 C c1
= make
<C
>(N
, start
);
127 for (int i
= M
-1; i
<= M
+1; ++i
)
129 if (0 <= i
&& i
<= N
)
131 C c1
= make
<C
>(N
, start
);
136 for (int i
= N
/2-1; i
<= N
/2+1; ++i
)
138 if (0 <= i
&& i
<= N
)
140 C c1
= make
<C
>(N
, start
);
145 for (int i
= N
- M
- 1; i
<= N
- M
+ 1; ++i
)
147 if (0 <= i
&& i
<= N
)
149 C c1
= make
<C
>(N
, start
);
154 for (int i
= N
- M
- 1; i
<= N
- M
+ 1; ++i
)
156 if (0 <= i
&& i
<= N
)
158 C c1
= make
<C
>(N
, start
);
163 for (int i
= N
- 3; i
<= N
; ++i
)
165 if (0 <= i
&& i
<= N
)
167 C c1
= make
<C
>(N
, start
);
176 testI(int P
, C
& c1
, const C
& c2
)
178 typedef typename
C::const_iterator CI
;
179 typedef cpp17_input_iterator
<CI
> ICI
;
180 std::size_t c1_osize
= c1
.size();
181 CI i
= c1
.insert(c1
.begin() + P
, ICI(c2
.begin()), ICI(c2
.end()));
182 assert(i
== c1
.begin() + P
);
183 assert(c1
.size() == c1_osize
+ c2
.size());
184 assert(static_cast<std::size_t>(std::distance(c1
.begin(), c1
.end())) == c1
.size());
185 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
186 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
188 for (int j
= 0; j
< P
; ++j
, ++i
)
190 for (int j
= 0; static_cast<std::size_t>(j
) < c2
.size(); ++j
, ++i
)
192 for (int j
= P
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
198 testNI(int start
, int N
, int M
)
200 for (int i
= 0; i
<= 3; ++i
)
202 if (0 <= i
&& i
<= N
)
204 C c1
= make
<C
>(N
, start
);
209 for (int i
= M
-1; i
<= M
+1; ++i
)
211 if (0 <= i
&& i
<= N
)
213 C c1
= make
<C
>(N
, start
);
218 for (int i
= N
/2-1; i
<= N
/2+1; ++i
)
220 if (0 <= i
&& i
<= N
)
222 C c1
= make
<C
>(N
, start
);
227 for (int i
= N
- M
- 1; i
<= N
- M
+ 1; ++i
)
229 if (0 <= i
&& i
<= N
)
231 C c1
= make
<C
>(N
, start
);
236 for (int i
= N
- 3; i
<= N
; ++i
)
238 if (0 <= i
&& i
<= N
)
240 C c1
= make
<C
>(N
, start
);
251 #if TEST_STD_VER >= 11
253 typedef typename
C::const_iterator CI
;
257 c
.insert(c
.end(), std::move_iterator
<I
>(&mo
), std::move_iterator
<I
>(&mo
+1));
260 for (CI i
= c
.begin(); i
!= c
.end(); ++i
, (void) ++j
)
261 assert(*i
== MoveOnly(j
));
264 typedef cpp17_input_iterator
<MoveOnly
*> I
;
265 c
.insert(c
.end(), std::move_iterator
<I
>(I(&mo
)), std::move_iterator
<I
>(I(&mo
+1)));
268 for (CI i
= c
.begin(); i
!= c
.end(); ++i
, (void) ++j
)
269 assert(*i
== MoveOnly(j
));
273 int main(int, char**)
276 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
277 const int N
= sizeof(rng
)/sizeof(rng
[0]);
278 for (int i
= 0; i
< N
; ++i
)
279 for (int j
= 0; j
< N
; ++j
)
280 for (int k
= 0; k
< N
; ++k
)
281 testN
<std::deque
<int> >(rng
[i
], rng
[j
], rng
[k
]);
282 testNI
<std::deque
<int> >(1500, 2000, 1000);
283 #if TEST_STD_VER >= 11
284 test_move
<std::deque
<MoveOnly
, limited_allocator
<MoveOnly
, 2000> > >();
287 #if TEST_STD_VER >= 11
289 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
290 const int N
= sizeof(rng
)/sizeof(rng
[0]);
291 for (int i
= 0; i
< N
; ++i
)
292 for (int j
= 0; j
< N
; ++j
)
293 for (int k
= 0; k
< N
; ++k
)
294 testN
<std::deque
<int, min_allocator
<int>> >(rng
[i
], rng
[j
], rng
[k
]);
295 testNI
<std::deque
<int> >(1500, 2000, 1000);
296 test_move
<std::deque
<MoveOnly
, min_allocator
<MoveOnly
> > >();
299 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
300 const int N
= sizeof(rng
)/sizeof(rng
[0]);
301 for (int i
= 0; i
< N
; ++i
)
302 for (int j
= 0; j
< N
; ++j
)
303 for (int k
= 0; k
< N
; ++k
)
304 testN
<std::deque
<int, safe_allocator
<int>> >(rng
[i
], rng
[j
], rng
[k
]);
305 testNI
<std::deque
<int> >(1500, 2000, 1000);
306 test_move
<std::deque
<MoveOnly
, safe_allocator
<MoveOnly
> > >();