Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++][test] Fix issues found by MSVC's STL #131787

Merged
merged 10 commits into from
Mar 20, 2025

Conversation

StephanTLavavej
Copy link
Member

@StephanTLavavej StephanTLavavej commented Mar 18, 2025

  • libcxx/test/support/min_allocator.h
    • Fix tiny_size_allocator::rebind which mistakenly said T instead of U.
  • libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
    • std::stable_partition requires bidirectional iterators.
  • libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp
    • Fix allocator type given to std::vector<bool>. The element types are required to match, N5008 [container.alloc.reqmts]/5: "Mandates: allocator_type::value_type is the same as X::value_type."
  • libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp
    • Mark is_steady as [[maybe_unused]], as it appears within LIBCPP_STATIC_ASSERT only.
  • libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
  • libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
  • libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
    • Fix MSVC warning C4127 "conditional expression is constant". TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED was introduced for this purpose, so it should be used consistently.
  • libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
    • Fix gcd() precondition violation for signed char. This test case was causing -128 to be passed as a signed char to gcd(), which is forbidden.
  • libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp
  • libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp
  • libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
    • Split some REQUIRES and XFAIL lines. This is a "nice to have" for MSVC's internal test harness, which is extremely simple and looks for exact comment matches to skip tests. We can recognize the specific lines "REQUIRES: has-unix-headers" and "XFAIL: msvc", but it's a headache to maintain if they're chained with other conditions.
  • libcxx/test/support/sized_allocator.h
    • Fix x86 truncation warnings. std::allocator takes std::size_t, so we need to static_cast.
  • libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/offset_range.pass.cpp
    • Fix x86 truncation warning. std::min() is returning std::streamoff, which was being unnecessarily narrowed to std::size_t.
  • libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp

@StephanTLavavej StephanTLavavej requested a review from a team as a code owner March 18, 2025 11:31
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

Changes
  • libcxx/test/support/min_allocator.h
    • Fix tiny_size_allocator::rebind which mistakenly said T instead of U.
  • libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
    • std::stable_partition requires bidirectional iterators.
  • libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp
    • Fix allocator type given to std::vector&lt;bool&gt;. The element types are required to match, N5008 [container.alloc.reqmts]/5: "Mandates: allocator_type::value_type is the same as X::value_type."
  • libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp
    • Mark is_steady as [[maybe_unused]], as it appears within LIBCPP_STATIC_ASSERT only.
  • libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
  • libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
  • libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
    • Fix MSVC warning C4127 "conditional expression is constant". TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED was introduced for this purpose, so it should be used consistently.
  • libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
    • Fix gcd() precondition violation for signed char. This test case was causing -128 to be passed as a signed char to gcd(), which is forbidden.
  • libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp
  • libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp
  • libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
    • Split some REQUIRES and XFAIL lines. This is a "nice to have" for MSVC's internal test harness, which is extremely simple and looks for exact comment matches to skip tests. We can recognize the specific lines "REQUIRES: has-unix-headers" and "XFAIL: msvc", but it's a headache to maintain if they're chained with other conditions.

Full diff: https://github.com/llvm/llvm-project/pull/131787.diff

11 Files Affected:

  • (modified) libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp (+1-1)
  • (modified) libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp (+2-3)
  • (modified) libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp (+2-3)
  • (modified) libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp (+2-1)
  • (modified) libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp (+1-1)
  • (modified) libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp (+2-1)
  • (modified) libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp (+2-1)
  • (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp (+1-1)
  • (modified) libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp (+5-5)
  • (modified) libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp (+3-2)
  • (modified) libcxx/test/support/min_allocator.h (+1-1)
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
index ed55a41e83938..7e8100b7949e7 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/stable_partition.pass.cpp
@@ -289,7 +289,7 @@ TEST_CONSTEXPR_CXX26 void test() {
     vec[5]                             = 6;
     getGlobalMemCounter()->throw_after = 0;
     std::stable_partition(
-        forward_iterator<int*>(vec.data()), forward_iterator<int*>(vec.data() + vec.size()), [](int i) {
+        bidirectional_iterator<int*>(vec.data()), bidirectional_iterator<int*>(vec.data() + vec.size()), [](int i) {
           return i < 5;
         });
     assert(std::is_partitioned(vec.begin(), vec.end(), [](int i) { return i < 5; }));
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
index 448abdddbb4cb..a20e96f9e4ddc 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate.pass.cpp
@@ -438,9 +438,8 @@ TEST_CONSTEXPR_CXX20 bool test_vector_bool() {
 TEST_CONSTEXPR_CXX20 bool test() {
   types::for_each(types::forward_iterator_list<int*>(), TestIter());
 
-#if TEST_STD_VER >= 11
-  if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
-    types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
+#if TEST_STD_VER >= 11 && TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED
+  types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
 #endif
 
   test_vector_bool<8>();
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
index 889794dff9fab..6c372eee720f1 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.swap/swap_ranges.pass.cpp
@@ -142,10 +142,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
 
   types::for_each(types::forward_iterator_list<int*>(), TestPtr());
 
-#if TEST_STD_VER >= 11
+#if TEST_STD_VER >= 11 && TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED
   // We can't test unique_ptr in constant evaluation before C++23 as it's constexpr only since C++23.
-  if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
-    types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
+  types::for_each(types::forward_iterator_list<std::unique_ptr<int>*>(), TestUniquePtr());
 #endif
 
   { // Test vector<bool>::iterator optimization
diff --git a/libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp
index 21a763e71e18a..85e2df1eba981 100644
--- a/libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/assert.iterators.pass.cpp
@@ -6,7 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-// REQUIRES: has-unix-headers, libcpp-has-abi-bounded-iterators-in-std-array
+// REQUIRES: has-unix-headers
+// REQUIRES: libcpp-has-abi-bounded-iterators-in-std-array
 // UNSUPPORTED: c++03
 // UNSUPPORTED: libcpp-hardening-mode=none
 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
diff --git a/libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp
index 86a163e0381ae..5ea67b56b9496 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/max_size.pass.cpp
@@ -71,7 +71,7 @@ TEST_CONSTEXPR_CXX20 bool tests() {
   // Test with various allocators and different `size_type`s
   {
     test(std::vector<bool>());
-    test(std::vector<bool, std::allocator<int> >());
+    test(std::vector<bool, std::allocator<bool> >());
     test(std::vector<bool, min_allocator<bool> >());
     test(std::vector<bool, test_allocator<bool> >(test_allocator<bool>(1)));
     test(std::vector<bool, other_allocator<bool> >(other_allocator<bool>(5)));
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp
index 193c00891da7f..4a899139d5f68 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/assert.push_back.invalidation.pass.cpp
@@ -14,7 +14,8 @@
 // the insertion point remain valid but those at or after the insertion point,
 // including the past-the-end iterator, are invalidated.
 
-// REQUIRES: has-unix-headers, libcpp-has-abi-bounded-iterators-in-vector
+// REQUIRES: has-unix-headers
+// REQUIRES: libcpp-has-abi-bounded-iterators-in-vector
 // UNSUPPORTED: c++03
 // UNSUPPORTED: libcpp-hardening-mode=none
 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
diff --git a/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
index 5561a1a8b3334..283a8fddb8e8f 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/no_file_description.pass.cpp
@@ -10,7 +10,8 @@
 // UNSUPPORTED: no-filesystem
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
-// XFAIL: msvc, target={{.+}}-windows-gnu
+// XFAIL: msvc
+// XFAIL: target={{.+}}-windows-gnu
 // XFAIL: availability-fp_to_chars-missing
 
 // fmemopen is available starting in Android M (API 23)
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
index 456176a6444a9..067872a4d9a74 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
@@ -39,7 +39,7 @@ constexpr struct {
     {36, 18, 18},
     {25, 30, 5},
     {24, 16, 8},
-    {128, 100, 4}};
+    {124, 100, 4}};
 
 template <typename Input1, typename Input2, typename Output>
 constexpr bool test0(int in1, int in2, int out)
diff --git a/libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp b/libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp
index 0322e9122e1cd..8cb3d78d97f52 100644
--- a/libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp
+++ b/libcxx/test/std/time/time.clock/time.clock.utc/types.compile.pass.cpp
@@ -36,11 +36,11 @@
 #include "test_macros.h"
 
 // class utc_clock
-using rep                = std::chrono::utc_clock::rep;
-using period             = std::chrono::utc_clock::period;
-using duration           = std::chrono::utc_clock::duration;
-using time_point         = std::chrono::utc_clock::time_point;
-constexpr bool is_steady = std::chrono::utc_clock::is_steady;
+using rep                                 = std::chrono::utc_clock::rep;
+using period                              = std::chrono::utc_clock::period;
+using duration                            = std::chrono::utc_clock::duration;
+using time_point                          = std::chrono::utc_clock::time_point;
+[[maybe_unused]] constexpr bool is_steady = std::chrono::utc_clock::is_steady;
 
 // Tests the values. Some of them are implementation-defined.
 LIBCPP_STATIC_ASSERT(std::same_as<rep, std::chrono::system_clock::rep>);
diff --git a/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp b/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
index 3a6ed3856282f..8522e0b4eeae3 100644
--- a/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
+++ b/libcxx/test/std/utilities/utility/utility.swap/swap_array.pass.cpp
@@ -137,8 +137,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
     static_assert(noexcept(std::swap(ma, ma)), "");
   }
 
-  if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
-    test_unique_ptr();
+#  if TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED
+  test_unique_ptr();
+#  endif
 #endif
 
   return true;
diff --git a/libcxx/test/support/min_allocator.h b/libcxx/test/support/min_allocator.h
index 0be7ee0554ca9..24505bbb508d6 100644
--- a/libcxx/test/support/min_allocator.h
+++ b/libcxx/test/support/min_allocator.h
@@ -481,7 +481,7 @@ struct tiny_size_allocator {
 
   template <class U>
   struct rebind {
-    using other = tiny_size_allocator<MaxSize, T>;
+    using other = tiny_size_allocator<MaxSize, U>;
   };
 
   tiny_size_allocator() = default;

@frederick-vs-ja

This comment was marked as resolved.

Fixes error: unused variable 'is_steady' [-Werror,-Wunused-const-variable]
sized_allocator.h(40): warning C4244: 'argument': conversion from 'unsigned __int64' to 'const size_t', possible loss of data
sized_allocator.h(43): warning C4244: 'argument': conversion from 'unsigned __int64' to 'const size_t', possible loss of data

std::allocator takes std::size_t, so we need to static_cast.
offset_range.pass.cpp(49): warning C4244: 'initializing': conversion from 'const _Ty' to 'size_t', possible loss of data

std::min() is returning std::streamoff, which was being unnecessarily narrowed to std::size_t.
…ways-true branch.

This was very recently introduced by LLVM-129008 making `N` constexpr. As it's a local constant
just nine lines above, we don't need to test whether 100 is greater than 0.
@frederick-vs-ja frederick-vs-ja merged commit bf5cdd6 into llvm:main Mar 20, 2025
81 checks passed
@StephanTLavavej StephanTLavavej deleted the stl-fixes branch March 20, 2025 08:13
Comment on lines +17 to +18
// REQUIRES: has-unix-headers
// REQUIRES: libcpp-has-abi-bounded-iterators-in-vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW we have a lot of these multiple requirements on a single line, and I don't think we want to commit to removing those. I'm not pushing back against the changes in this patch specifically, but our official stance here is that we're allowed to use REQUIRES: foo && bar and REQUIRES: foo, bar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, understood. Most of the multi-requirements pose no issue for our internal test harness - it's just the ones that cause MSVC skips, like REQUIRES: has-unix-headers or XFAIL: msvc, and there haven't been a lot of those being introduced or changed. If this becomes more common or disruptive for you, we can add skips on our side, or figure out how to make the internal test harness parser smarter. (We may need to do that for ADDITIONAL_COMPILE_FLAGS, which currently it doesn't understand at all.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cross that bridge when/if we get to it, for now these changes are fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants