[libcxx-commits] [libcxx] Fix one case in saturate_cast.pass.cpp for 64-bit on z/OS (PR #86724)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 26 12:55:55 PDT 2024


https://github.com/zibi2 created https://github.com/llvm/llvm-project/pull/86724

On z/OS int128 is disabled causing one of the cases in `saturate_cast.pass.cpp` to fail. The failure is only in 64-bit mode.
In this case `the std::numeric_limits<long long int>::max()` is within `std::numeric_limits<unsigned long int>::min()`
and `std::numeric_limits<unsigned long int>::max()` therefore, saturate_cast<unsigned long int>( sBigMax) == LONG_MAX and not ULONG_MAX as original test.

In 32-bit, `saturate_cast<unsigned long int>( sBigMax) == ULONG_MAX` like on other platforms where int128 is enabled.

This PR is required to pass this test case on z/OS and possibly on other platforms where int128 is not supported/enabled. 

>From 25855437ca36a968f8ab86ed759076ae973049f0 Mon Sep 17 00:00:00 2001
From: Zibi Sarbinowski <zibi at ca.ibm.com>
Date: Tue, 26 Mar 2024 13:33:59 -0500
Subject: [PATCH] Fix one case in saturate_cast.pass.cpp for 64-bit on z/OS

Co-authored-by: Sean Perry <perry at ca.ibm.com>
---
 .../numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp
index c06a9ed2d5cb42..59f397d5c0ee76 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp
@@ -329,7 +329,7 @@ constexpr bool test() {
   { [[maybe_unused]] std::same_as<unsigned long int> decltype(auto) _ = std::saturate_cast<unsigned long int>(sBigMax); }
   assert(std::saturate_cast<unsigned long int>(  sBigMin) == 0UL);       // saturated
   assert(std::saturate_cast<unsigned long int>(    sZero) == 0UL);
-  assert(std::saturate_cast<unsigned long int>(  sBigMax) == ULONG_MAX); // saturated
+  assert(std::saturate_cast<unsigned long int>(  sBigMax) == (sizeof(UIntT)>sizeof(unsigned long int)?ULONG_MAX:LONG_MAX)); // saturated depending on underlying types
 
   { [[maybe_unused]] std::same_as<unsigned long int> decltype(auto) _ = std::saturate_cast<unsigned long int>(uBigMax); }
   assert(std::saturate_cast<unsigned long int>(    uZero) == 0UL);



More information about the libcxx-commits mailing list