[libcxx] r285346 - [PATCH] D25483: [libcxx] [test] Fix non-Standard assumptions about how many elements are allocated

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 27 14:25:13 PDT 2016


Author: stl_msft
Date: Thu Oct 27 16:25:12 2016
New Revision: 285346

URL: http://llvm.org/viewvc/llvm-project?rev=285346&view=rev
Log:
[PATCH] D25483: [libcxx] [test] Fix non-Standard assumptions about how many elements are allocated

Modified:
    libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp
    libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp
    libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
    libcxx/trunk/test/std/containers/sequences/list/list.cons/size_type.pass.cpp
    libcxx/trunk/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp
    libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp

Modified: libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp Thu Oct 27 16:25:12 2016
@@ -98,7 +98,7 @@ int main()
     test<DefaultOnly, std::allocator<DefaultOnly> >(4096);
     test<DefaultOnly, std::allocator<DefaultOnly> >(4097);
 
-    test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095);
+    LIBCPP_ONLY(test1<DefaultOnly, limited_allocator<DefaultOnly, 4096> >(4095));
 
 #if TEST_STD_VER >= 11
     test<DefaultOnly, min_allocator<DefaultOnly> >(4095);

Modified: libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp Thu Oct 27 16:25:12 2016
@@ -44,7 +44,7 @@ int main()
     test<int, std::allocator<int> >(4095, 78);
     test<int, std::allocator<int> >(4096, 1165);
     test<int, std::allocator<int> >(4097, 157);
-    test<int, limited_allocator<int, 4096> >(4095, 90);
+    LIBCPP_ONLY(test<int, limited_allocator<int, 4096> >(4095, 90));
 #if TEST_STD_VER >= 11
     test<int, min_allocator<int> >(4095, 90);
 #endif

Modified: libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp Thu Oct 27 16:25:12 2016
@@ -43,7 +43,8 @@ int main()
     }
     {
         int a[] = {0, 1, 2, 3};
-        std::list<int, limited_allocator<int, sizeof(a)/sizeof(a[0])> > l(input_iterator<const int*>(a),
+        // Add 2 for implementations that dynamically allocate a sentinel node and container proxy.
+        std::list<int, limited_allocator<int, sizeof(a)/sizeof(a[0]) + 2> > l(input_iterator<const int*>(a),
                          input_iterator<const int*>(a + sizeof(a)/sizeof(a[0])));
         assert(l.size() == sizeof(a)/sizeof(a[0]));
         assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0]));

Modified: libcxx/trunk/test/std/containers/sequences/list/list.cons/size_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/list/list.cons/size_type.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/list/list.cons/size_type.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/list/list.cons/size_type.pass.cpp Thu Oct 27 16:25:12 2016
@@ -48,7 +48,8 @@ int main()
         assert(*i == 0);
     }
     {
-        std::list<int, limited_allocator<int, 3> > l(3);
+        // Add 2 for implementations that dynamically allocate a sentinel node and container proxy.
+        std::list<int, limited_allocator<int, 3 + 2> > l(3);
         assert(l.size() == 3);
         assert(std::distance(l.begin(), l.end()) == 3);
         std::list<int>::const_iterator i = l.begin();

Modified: libcxx/trunk/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp Thu Oct 27 16:25:12 2016
@@ -42,7 +42,8 @@ int main()
         assert(*i == 2);
     }
     {
-        std::list<int, limited_allocator<int, 3> > l(3, 2);
+        // Add 2 for implementations that dynamically allocate a sentinel node and container proxy.
+        std::list<int, limited_allocator<int, 3 + 2> > l(3, 2);
         assert(l.size() == 3);
         assert(std::distance(l.begin(), l.end()) == 3);
         std::list<int>::const_iterator i = l.begin();

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp Thu Oct 27 16:25:12 2016
@@ -37,7 +37,8 @@ int main()
         assert(is_contiguous_container_asan_correct(v));
     }
     {
-        std::vector<int, limited_allocator<int, 250> > v(100);
+        // Add 1 for implementations that dynamically allocate a container proxy.
+        std::vector<int, limited_allocator<int, 250 + 1> > v(100);
         assert(v.capacity() == 100);
         v.reserve(50);
         assert(v.size() == 100);

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp Thu Oct 27 16:25:12 2016
@@ -33,7 +33,8 @@ int main()
         assert(is_contiguous_container_asan_correct(v));
     }
     {
-        std::vector<MoveOnly, limited_allocator<MoveOnly, 300> > v(100);
+        // Add 1 for implementations that dynamically allocate a container proxy.
+        std::vector<MoveOnly, limited_allocator<MoveOnly, 300 + 1> > v(100);
         v.resize(50);
         assert(v.size() == 50);
         assert(v.capacity() == 100);
@@ -56,7 +57,8 @@ int main()
         assert(is_contiguous_container_asan_correct(v));
     }
     {
-        std::vector<int, limited_allocator<int, 300> > v(100);
+        // Add 1 for implementations that dynamically allocate a container proxy.
+        std::vector<int, limited_allocator<int, 300 + 1> > v(100);
         v.resize(50);
         assert(v.size() == 50);
         assert(v.capacity() == 100);

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp Thu Oct 27 16:25:12 2016
@@ -35,7 +35,8 @@ int main()
             assert(v[i] == 1);
     }
     {
-        std::vector<int, limited_allocator<int, 300> > v(100);
+        // Add 1 for implementations that dynamically allocate a container proxy.
+        std::vector<int, limited_allocator<int, 300 + 1> > v(100);
         v.resize(50, 1);
         assert(v.size() == 50);
         assert(v.capacity() == 100);

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp Thu Oct 27 16:25:12 2016
@@ -43,10 +43,11 @@ int main()
     test<std::vector<int> >(a, an);
 
     test<std::vector<int, limited_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an));
-    test<std::vector<int, limited_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
-    test<std::vector<int, limited_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
-    test<std::vector<int, limited_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
-    test<std::vector<int, limited_allocator<int, 18> > >(a, an);
+    // Add 1 for implementations that dynamically allocate a container proxy.
+    test<std::vector<int, limited_allocator<int, 18 + 1> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
+    test<std::vector<int, limited_allocator<int, 18 + 1> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
+    test<std::vector<int, limited_allocator<int, 18 + 1> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
+    test<std::vector<int, limited_allocator<int, 18 + 1> > >(a, an);
 #if TEST_STD_VER >= 11
     test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
     test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp Thu Oct 27 16:25:12 2016
@@ -34,7 +34,8 @@ test(typename C::size_type n, const type
 int main()
 {
     test<std::vector<int> >(50, 3);
-    test<std::vector<int, limited_allocator<int, 50> > >(50, 5);
+    // Add 1 for implementations that dynamically allocate a container proxy.
+    test<std::vector<int, limited_allocator<int, 50 + 1> > >(50, 5);
 #if TEST_STD_VER >= 11
     test<std::vector<int, min_allocator<int>> >(50, 3);
 #endif

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp Thu Oct 27 16:25:12 2016
@@ -48,7 +48,10 @@ int main()
             assert(c[j] == j);
     }
     {
-        std::vector<int, limited_allocator<int, 15> > c;
+        // libc++ needs 15 because it grows by 2x (1 + 2 + 4 + 8).
+        // Use 17 for implementations that dynamically allocate a container proxy
+        // and grow by 1.5x (1 for proxy + 1 + 2 + 3 + 4 + 6).
+        std::vector<int, limited_allocator<int, 17> > c;
         c.push_back(0);
         assert(c.size() == 1);
         assert(is_contiguous_container_asan_correct(c));

Modified: libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp?rev=285346&r1=285345&r2=285346&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp Thu Oct 27 16:25:12 2016
@@ -50,7 +50,10 @@ int main()
             assert(c[j] == MoveOnly(j));
     }
     {
-        std::vector<MoveOnly, limited_allocator<MoveOnly, 15> > c;
+        // libc++ needs 15 because it grows by 2x (1 + 2 + 4 + 8).
+        // Use 17 for implementations that dynamically allocate a container proxy
+        // and grow by 1.5x (1 for proxy + 1 + 2 + 3 + 4 + 6).
+        std::vector<MoveOnly, limited_allocator<MoveOnly, 17> > c;
         c.push_back(MoveOnly(0));
         assert(c.size() == 1);
         assert(is_contiguous_container_asan_correct(c));




More information about the cfe-commits mailing list