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 suite portability improvements #98527

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Jul 11, 2024

This patch contains a number of small portability improvements for the test suite, making it easier to run the test suite with other standard library implementations.

  • Guard checks for _LIBCPP_HARDENING_MODE to avoid -Wundef
  • Avoid defining _LIBCPP_HARDENING_MODE even when no hardening mode is specified -- we should use the default mode of the library in that case.
  • Add missing includes and qualify a few function calls.
  • Avoid opening namespace std to forward declare stdlib containers. The test suite should represent user code, and user code isn't allowed to do that.

This patch contains a number of small portability improvements for the
test suite, making it easier to run the test suite with other standard
library implementations.

- Guard checks for _LIBCPP_HARDENING_MODE to avoid -Wundef
- Avoid defining _LIBCPP_HARDENING_MODE even when no hardening mode is
  specified -- we should use the default mode of the library in that case.
- Add missing includes and qualify a few function calls.
- Avoid opening namespace std to forward declare stdlib containers. The
  test suite should represent user code, and user code isn't allowed to
  do that.
@ldionne ldionne requested a review from a team as a code owner July 11, 2024 19:34
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 11, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 11, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

This patch contains a number of small portability improvements for the test suite, making it easier to run the test suite with other standard library implementations.

  • Guard checks for _LIBCPP_HARDENING_MODE to avoid -Wundef
  • Avoid defining _LIBCPP_HARDENING_MODE even when no hardening mode is specified -- we should use the default mode of the library in that case.
  • Add missing includes and qualify a few function calls.
  • Avoid opening namespace std to forward declare stdlib containers. The test suite should represent user code, and user code isn't allowed to do that.

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

11 Files Affected:

  • (modified) libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp (+3-1)
  • (modified) libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp (+1-1)
  • (modified) libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp (+1-1)
  • (modified) libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp (+1-1)
  • (modified) libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp (+1-1)
  • (modified) libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp (+1-1)
  • (modified) libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp (+2-2)
  • (modified) libcxx/test/support/check_assertion.h (+1-1)
  • (modified) libcxx/test/support/container_test_types.h (+8-33)
  • (modified) libcxx/test/support/filesystem_test_helper.h (+23-23)
  • (modified) libcxx/utils/libcxx/test/params.py (+5-4)
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
index 539e234750e00..d59864eb87023 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
@@ -108,7 +108,9 @@ constexpr bool test() {
       return value;
     };
     assert(std::ranges::clamp(3, 2, 4, std::ranges::less{}, projection_function) == 3);
-#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && \
+      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
+      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
     assert(counter <= 3);
 #endif
   }
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp
index 3b7c0ae0b80f0..c7ab362604474 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp
@@ -69,7 +69,7 @@ int main(int, char**) {
     std::sort_heap(first, last);
     LIBCPP_ASSERT(stats.copied == 0);
     LIBCPP_ASSERT(stats.moved <= 2 * n + n * logn);
-#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
     LIBCPP_ASSERT(stats.compared <= n * logn);
 #else
     LIBCPP_ASSERT(stats.compared <= 2 * n * logn + debug_comparisons);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp
index 1e636ea9afac4..ff69f39f6c06d 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp
@@ -246,7 +246,7 @@ void test_complexity() {
     std::ranges::sort_heap(first, last, &MyInt::Comp);
     LIBCPP_ASSERT(stats.copied == 0);
     LIBCPP_ASSERT(stats.moved <= 2 * n + n * logn);
-#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
     LIBCPP_ASSERT(stats.compared <= n * logn);
 #else
     LIBCPP_ASSERT(stats.compared <= 2 * n * logn + debug_comparisons);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
index 0a35fad40e89a..d103e8c2ddb33 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp
@@ -79,7 +79,7 @@ test_one(unsigned N, unsigned M)
         assert(ia[0] == static_cast<int>(N)-1);
         assert(ia[N-1] == 0);
         assert(std::is_sorted(ia, ia+N, std::greater<value_type>()));
-#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
         assert(pred.count() <= (N-1));
 #endif
     }
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp
index f2f7d538d773f..edacf3ce5d87f 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp
@@ -156,7 +156,7 @@ constexpr void test_comparator_invocation_count() {
   // The comparator is invoked only `min(left.size(), right.size())` times
   test_lexicographical_compare<const int*, const int*>(
       std::array{0, 1, 2}, std::array{0, 1, 2, 3}, compare_last_digit_counting, std::strong_ordering::less);
-#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
   assert(compare_invocation_count <= 3);
 #else
   assert(compare_invocation_count <= 6);
diff --git a/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp b/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp
index 92bb7c9caea83..064d5c3a3fac4 100644
--- a/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp
+++ b/libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp
@@ -50,7 +50,7 @@ void test_iterator_sentinel() {
   assert(s.data() == std::data(arr));
   }
 
-#if _LIBCPP_STD_VER >= 26
+#if TEST_STD_VER >= 26
   // P3029R1: deduction from `integral_constant`
   {
     std::span s{std::begin(arr), std::integral_constant<size_t, 3>{}};
diff --git a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp
index acb1e1f7d4075..0749617d056ab 100644
--- a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp
@@ -110,7 +110,7 @@ int main(int, char**)
         err = std::ios_base::goodbit;
         t = std::tm();
         I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
-#if _LIBCPP_VERSION
+#if defined(_LIBCPP_VERSION)
           // libc++ points to the '/' after the month.
           assert(base(i) == in+2);
 #else
@@ -129,7 +129,7 @@ int main(int, char**)
         err = std::ios_base::goodbit;
         t = std::tm();
         I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
-#if _LIBCPP_VERSION
+#if defined(_LIBCPP_VERSION)
           // libc++ points to the '/' after the month.
           assert(base(i) == in+2);
 #else
diff --git a/libcxx/test/support/check_assertion.h b/libcxx/test/support/check_assertion.h
index cc841ceb237d8..329ce819a6c8d 100644
--- a/libcxx/test/support/check_assertion.h
+++ b/libcxx/test/support/check_assertion.h
@@ -392,7 +392,7 @@ bool ExpectDeath(DeathCause expected_cause, const char* stmt, Func&& func) {
 #define EXPECT_STD_TERMINATE(...)                 \
     assert(  ExpectDeath(DeathCause::StdTerminate, #__VA_ARGS__, __VA_ARGS__)  )
 
-#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
 #define TEST_LIBCPP_ASSERT_FAILURE(expr, message) \
     assert(( ExpectDeath(DeathCause::VerboseAbort, #expr, [&]() { (void)(expr); }, MakeAssertionMessageMatcher(message)) ))
 #else
diff --git a/libcxx/test/support/container_test_types.h b/libcxx/test/support/container_test_types.h
index ed26ba5d40af5..b72bbbeaccf77 100644
--- a/libcxx/test/support/container_test_types.h
+++ b/libcxx/test/support/container_test_types.h
@@ -87,9 +87,16 @@
 
 #include <cassert>
 #include <cstddef>
+#include <deque>
 #include <functional>
+#include <list>
+#include <map>
 #include <new>
+#include <set>
+#include <unordered_map>
+#include <unordered_set>
 #include <utility>
+#include <vector>
 
 #include "test_macros.h"
 
@@ -420,12 +427,7 @@ bool operator <(CopyInsertable<ID> const& L, CopyInsertable<ID> const& R) {
   return L.data < R.data;
 }
 
-
-#ifdef _LIBCPP_BEGIN_NAMESPACE_STD
-_LIBCPP_BEGIN_NAMESPACE_STD
-#else
 namespace std {
-#endif
   template <int ID>
   struct hash< ::CopyInsertable<ID> > {
     typedef ::CopyInsertable<ID> argument_type;
@@ -435,34 +437,7 @@ namespace std {
       return arg.data;
     }
   };
-  template <class T, class Alloc>
-  class vector;
-  template <class T, class Alloc>
-  class deque;
-  template <class T, class Alloc>
-  class list;
-  template <class _Key, class _Value, class _Less, class _Alloc>
-  class map;
-  template <class _Key, class _Value, class _Less, class _Alloc>
-  class multimap;
-  template <class _Value, class _Less, class _Alloc>
-  class set;
-  template <class _Value, class _Less, class _Alloc>
-  class multiset;
-  template <class _Key, class _Value, class _Hash, class _Equals, class _Alloc>
-  class unordered_map;
-  template <class _Key, class _Value, class _Hash, class _Equals, class _Alloc>
-  class unordered_multimap;
-  template <class _Value, class _Hash, class _Equals, class _Alloc>
-  class unordered_set;
-  template <class _Value, class _Hash, class _Equals, class _Alloc>
-  class unordered_multiset;
-
-#ifdef _LIBCPP_END_NAMESPACE_STD
-_LIBCPP_END_NAMESPACE_STD
-#else
-} // end namespace std
-#endif
+}
 
 // TCT - Test container type
 namespace TCT {
diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h
index 1b3313d0c1cfb..29bc846fbbc83 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -18,6 +18,7 @@
 #include <chrono>
 #include <cstdint>
 #include <cstdio> // for printf
+#include <cstring>
 #include <string>
 #include <system_error>
 #include <type_traits>
@@ -232,9 +233,9 @@ struct scoped_test_env
         if (size >
             static_cast<typename std::make_unsigned<utils::off64_t>::type>(
                 std::numeric_limits<utils::off64_t>::max())) {
-            fprintf(stderr, "create_file(%s, %ju) too large\n",
-                    filename.c_str(), size);
-            abort();
+            std::fprintf(stderr, "create_file(%s, %ju) too large\n",
+                         filename.c_str(), size);
+            std::abort();
         }
 
 #if defined(_WIN32) || defined(__MVS__)
@@ -244,20 +245,20 @@ struct scoped_test_env
 #endif
         FILE* file = utils::fopen64(filename.c_str(), "w" FOPEN_CLOEXEC_FLAG);
         if (file == nullptr) {
-            fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(),
-                    strerror(errno));
-            abort();
+            std::fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(),
+                         std::strerror(errno));
+            std::abort();
         }
 
         if (utils::ftruncate64(
                 fileno(file), static_cast<utils::off64_t>(size)) == -1) {
-            fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(),
-                    size, strerror(errno));
-            fclose(file);
-            abort();
+            std::fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(),
+                         size, std::strerror(errno));
+            std::fclose(file);
+            std::abort();
         }
 
-        fclose(file);
+        std::fclose(file);
         return filename;
     }
 
@@ -616,10 +617,9 @@ struct ExceptionChecker {
     }();
     assert(format == Err.what());
     if (format != Err.what()) {
-      fprintf(stderr,
-              "filesystem_error::what() does not match expected output:\n");
-      fprintf(stderr, "  expected: \"%s\"\n", format.c_str());
-      fprintf(stderr, "  actual:   \"%s\"\n\n", Err.what());
+      std::fprintf(stderr, "filesystem_error::what() does not match expected output:\n");
+      std::fprintf(stderr, "  expected: \"%s\"\n", format.c_str());
+      std::fprintf(stderr, "  actual:   \"%s\"\n\n", Err.what());
     }
   }
 
@@ -639,23 +639,23 @@ inline fs::path GetWindowsInaccessibleDir() {
       continue;
     // Basic sanity checks on the directory_entry
     if (!ent.exists() || !ent.is_directory()) {
-      fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
-                      "but doesn't behave as expected, skipping tests "
-                      "regarding it\n", dir.string().c_str());
+      std::fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
+                           "but doesn't behave as expected, skipping tests "
+                           "regarding it\n", dir.string().c_str());
       return fs::path();
     }
     // Check that it indeed is inaccessible as expected
     (void)fs::exists(ent, ec);
     if (!ec) {
-      fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
-                      "but seems to be accessible, skipping tests "
-                      "regarding it\n", dir.string().c_str());
+      std::fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
+                           "but seems to be accessible, skipping tests "
+                           "regarding it\n", dir.string().c_str());
       return fs::path();
     }
     return ent;
   }
-  fprintf(stderr, "No inaccessible directory \"%s\" found, skipping tests "
-                  "regarding it\n", dir.string().c_str());
+  std::fprintf(stderr, "No inaccessible directory \"%s\" found, skipping tests "
+                       "regarding it\n", dir.string().c_str());
   return fs::path();
 }
 
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index ea841acf3a3d4..3aadc54cf92dc 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -374,11 +374,12 @@ def getSuitableClangTidy(cfg):
     ),
     Parameter(
         name="hardening_mode",
-        choices=["none", "fast", "extensive", "debug"],
+        choices=["none", "fast", "extensive", "debug", "undefined"],
         type=str,
-        default="none",
+        default="undefined",
         help="Whether to enable one of the hardening modes when compiling the test suite. This is only "
-        "meaningful when running the tests against libc++.",
+        "meaningful when running the tests against libc++. By default, no hardening mode is specified "
+        "so the default hardening mode of the standard library will be used (if any).",
         actions=lambda hardening_mode: filter(
             None,
             [
@@ -386,7 +387,7 @@ def getSuitableClangTidy(cfg):
                 AddCompileFlag("-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST")      if hardening_mode == "fast" else None,
                 AddCompileFlag("-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") if hardening_mode == "extensive" else None,
                 AddCompileFlag("-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG")     if hardening_mode == "debug" else None,
-                AddFeature("libcpp-hardening-mode={}".format(hardening_mode)),
+                AddFeature("libcpp-hardening-mode={}".format(hardening_mode))               if hardening_mode != "undefined" else None,
             ],
         ),
     ),

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff b64c1de714c50bec7493530446ebf5e540d5f96a e9af4c6a8203731f6494ff402eca429aeee5214c --extensions h,cpp -- libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/ranges_sort_heap.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp libcxx/test/std/containers/views/views.span/span.cons/deduct.pass.cpp libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp libcxx/test/support/check_assertion.h libcxx/test/support/container_test_types.h libcxx/test/support/filesystem_test_helper.h
View the diff from clang-format here.
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
index d59864eb87..8be408fa0b 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp
@@ -108,9 +108,8 @@ constexpr bool test() {
       return value;
     };
     assert(std::ranges::clamp(3, 2, 4, std::ranges::less{}, projection_function) == 3);
-#if defined(_LIBCPP_HARDENING_MODE) && \
-      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
-      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
+#if defined(_LIBCPP_HARDENING_MODE) && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                   \
+    _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
     assert(counter <= 3);
 #endif
   }
diff --git a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp
index 0749617d05..9ce4bec028 100644
--- a/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.time/locale.time.get.byname/get_date.pass.cpp
@@ -111,8 +111,8 @@ int main(int, char**)
         t = std::tm();
         I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
 #if defined(_LIBCPP_VERSION)
-          // libc++ points to the '/' after the month.
-          assert(base(i) == in+2);
+        // libc++ points to the '/' after the month.
+        assert(base(i) == in + 2);
 #else
           // libstdc++ points to the second character.
           assert(base(i) == in+1);
@@ -130,8 +130,8 @@ int main(int, char**)
         t = std::tm();
         I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
 #if defined(_LIBCPP_VERSION)
-          // libc++ points to the '/' after the month.
-          assert(base(i) == in+2);
+        // libc++ points to the '/' after the month.
+        assert(base(i) == in + 2);
 #else
           // libstdc++ points to the second character.
           assert(base(i) == in+1);
diff --git a/libcxx/test/support/container_test_types.h b/libcxx/test/support/container_test_types.h
index b72bbbeacc..c7259e8391 100644
--- a/libcxx/test/support/container_test_types.h
+++ b/libcxx/test/support/container_test_types.h
@@ -428,16 +428,14 @@ bool operator <(CopyInsertable<ID> const& L, CopyInsertable<ID> const& R) {
 }
 
 namespace std {
-  template <int ID>
-  struct hash< ::CopyInsertable<ID> > {
-    typedef ::CopyInsertable<ID> argument_type;
-    typedef std::size_t result_type;
+template <int ID>
+struct hash< ::CopyInsertable<ID> > {
+  typedef ::CopyInsertable<ID> argument_type;
+  typedef std::size_t result_type;
 
-    std::size_t operator()(argument_type const& arg) const {
-      return arg.data;
-    }
+  std::size_t operator()(argument_type const& arg) const { return arg.data; }
   };
-}
+  } // namespace std
 
 // TCT - Test container type
 namespace TCT {
diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h
index 29bc846fbb..e428757fad 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -233,9 +233,8 @@ struct scoped_test_env
         if (size >
             static_cast<typename std::make_unsigned<utils::off64_t>::type>(
                 std::numeric_limits<utils::off64_t>::max())) {
-            std::fprintf(stderr, "create_file(%s, %ju) too large\n",
-                         filename.c_str(), size);
-            std::abort();
+          std::fprintf(stderr, "create_file(%s, %ju) too large\n", filename.c_str(), size);
+          std::abort();
         }
 
 #if defined(_WIN32) || defined(__MVS__)
@@ -245,17 +244,15 @@ struct scoped_test_env
 #endif
         FILE* file = utils::fopen64(filename.c_str(), "w" FOPEN_CLOEXEC_FLAG);
         if (file == nullptr) {
-            std::fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(),
-                         std::strerror(errno));
-            std::abort();
+          std::fprintf(stderr, "fopen %s failed: %s\n", filename.c_str(), std::strerror(errno));
+          std::abort();
         }
 
         if (utils::ftruncate64(
                 fileno(file), static_cast<utils::off64_t>(size)) == -1) {
-            std::fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(),
-                         size, std::strerror(errno));
-            std::fclose(file);
-            std::abort();
+          std::fprintf(stderr, "ftruncate %s %ju failed: %s\n", filename.c_str(), size, std::strerror(errno));
+          std::fclose(file);
+          std::abort();
         }
 
         std::fclose(file);
@@ -639,23 +636,29 @@ inline fs::path GetWindowsInaccessibleDir() {
       continue;
     // Basic sanity checks on the directory_entry
     if (!ent.exists() || !ent.is_directory()) {
-      std::fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
-                           "but doesn't behave as expected, skipping tests "
-                           "regarding it\n", dir.string().c_str());
+      std::fprintf(stderr,
+                   "The expected inaccessible directory \"%s\" was found "
+                   "but doesn't behave as expected, skipping tests "
+                   "regarding it\n",
+                   dir.string().c_str());
       return fs::path();
     }
     // Check that it indeed is inaccessible as expected
     (void)fs::exists(ent, ec);
     if (!ec) {
-      std::fprintf(stderr, "The expected inaccessible directory \"%s\" was found "
-                           "but seems to be accessible, skipping tests "
-                           "regarding it\n", dir.string().c_str());
+      std::fprintf(stderr,
+                   "The expected inaccessible directory \"%s\" was found "
+                   "but seems to be accessible, skipping tests "
+                   "regarding it\n",
+                   dir.string().c_str());
       return fs::path();
     }
     return ent;
   }
-  std::fprintf(stderr, "No inaccessible directory \"%s\" found, skipping tests "
-                       "regarding it\n", dir.string().c_str());
+  std::fprintf(stderr,
+               "No inaccessible directory \"%s\" found, skipping tests "
+               "regarding it\n",
+               dir.string().c_str());
   return fs::path();
 }
 

@ldionne ldionne merged commit 7918e62 into llvm:main Jul 12, 2024
58 of 59 checks passed
@ldionne ldionne deleted the review/test-suite-portability-fixes branch July 12, 2024 14:17
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.

None yet

2 participants