Skip to content

Commit 49a5bd2

Browse files
authored
Fix nvhpc __builtin_(add|sub)_overflow condition (#7887)
1 parent 84ec795 commit 49a5bd2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

libcudacxx/include/cuda/__numeric/add_overflow.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ _CCCL_REQUIRES((::cuda::std::is_void_v<_Result> || ::cuda::std::__cccl_is_intege
256256
[[nodiscard]]
257257
_CCCL_API constexpr overflow_result<_ActualResult> add_overflow(const _Lhs __lhs, const _Rhs __rhs) noexcept
258258
{
259-
using ::cuda::std::is_signed_v;
259+
using ::cuda::std::is_same_v;
260260

261261
// We want to use __builtin_add_overflow only in host code. When compiling CUDA source file, we cannot use it in
262262
// constant expressions, because it doesn't work before nvcc 13.1 and is buggy in 13.1. When compiling C++ source
@@ -269,7 +269,7 @@ _CCCL_API constexpr overflow_result<_ActualResult> add_overflow(const _Lhs __lhs
269269
// nvc++ doesn't support overflow builtins for 128-bit integers of different signedness.
270270
# if _CCCL_COMPILER(NVHPC)
271271
if constexpr ((sizeof(_ActualResult) != 16 && sizeof(_Lhs) != 16 && sizeof(_Rhs) != 16)
272-
|| (is_signed_v<_ActualResult> == is_signed_v<_Lhs> == is_signed_v<_Rhs>) )
272+
|| (is_same_v<_ActualResult, _Lhs> && is_same_v<_ActualResult, _Rhs>) )
273273
# endif // _CCCL_COMPILER(NVHPC)
274274
{
275275
NV_IF_TARGET(NV_IS_HOST, ({
@@ -286,7 +286,7 @@ _CCCL_API constexpr overflow_result<_ActualResult> add_overflow(const _Lhs __lhs
286286
using ::cuda::std::__make_nbit_int_t;
287287
using ::cuda::std::__make_nbit_uint_t;
288288
using ::cuda::std::__num_bits_v;
289-
using ::cuda::std::is_same_v;
289+
using ::cuda::std::is_signed_v;
290290
using ::cuda::std::is_unsigned_v;
291291
using _CommonAll = ::cuda::std::common_type_t<_Common, _ActualResult>;
292292
[[maybe_unused]] const bool __is_lhs_ge_zero = is_unsigned_v<_Lhs> || __lhs >= 0;

libcudacxx/include/cuda/__numeric/sub_overflow.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ _CCCL_REQUIRES((::cuda::std::is_void_v<_Result> || ::cuda::std::__cccl_is_intege
271271
[[nodiscard]]
272272
_CCCL_API constexpr overflow_result<_ActualResult> sub_overflow(const _Lhs __lhs, const _Rhs __rhs) noexcept
273273
{
274-
using ::cuda::std::is_signed_v;
274+
using ::cuda::std::is_same_v;
275275

276276
// We want to use __builtin_sub_overflow only in host code. When compiling CUDA source file, we cannot use it in
277277
// constant expressions, because it doesn't work before nvcc 13.1 and is buggy in 13.1. When compiling C++ source
@@ -284,7 +284,7 @@ _CCCL_API constexpr overflow_result<_ActualResult> sub_overflow(const _Lhs __lhs
284284
// nvc++ doesn't support overflow builtins for 128-bit integers of different signedness.
285285
# if _CCCL_COMPILER(NVHPC)
286286
if constexpr ((sizeof(_ActualResult) != 16 && sizeof(_Lhs) != 16 && sizeof(_Rhs) != 16)
287-
|| (is_signed_v<_ActualResult> == is_signed_v<_Lhs> == is_signed_v<_Rhs>) )
287+
|| (is_same_v<_ActualResult, _Lhs> && is_same_v<_ActualResult, _Rhs>) )
288288
# endif // _CCCL_COMPILER(NVHPC)
289289
{
290290
NV_IF_TARGET(NV_IS_HOST, ({
@@ -299,6 +299,7 @@ _CCCL_API constexpr overflow_result<_ActualResult> sub_overflow(const _Lhs __lhs
299299
// Host fallback + device implementation.
300300
#if _CCCL_CUDA_COMPILATION() || !defined(_CCCL_BUILTIN_SUB_OVERFLOW) || (_CCCL_COMPILER(NVHPC) && _CCCL_HAS_INT128())
301301
using ::cuda::std::common_type_t;
302+
using ::cuda::std::is_signed_v;
302303
using ::cuda::std::is_unsigned_v;
303304
using ::cuda::std::make_signed_t;
304305
using ::cuda::std::make_unsigned_t;

0 commit comments

Comments
 (0)