Skip to content

Commit

Permalink
fix spurious missing return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpearson committed Apr 14, 2023
1 parent 7e32d5c commit bb68066
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion common/src/KokkosKernels_ComparableCast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef KOKKOSKERNELS_COMPARABLE_CAST_HPP
#define KOKKOSKERNELS_COMPARABLE_CAST_HPP

#include <Kokkos_Core.hpp> // CUDA_VERSION

namespace KokkosKernels {
namespace Impl {

Expand Down Expand Up @@ -69,7 +71,7 @@ KOKKOS_INLINE_FUNCTION constexpr auto comparable_cast(const A &a) {
std::is_signed_v<A> ? sizeof(A) : 2 * sizeof(A);

// how wide to compare T and U
constexpr size_t width = std::max(t_width, a_width);
constexpr size_t width = KOKKOSKERNELS_MACRO_MAX(t_width, a_width);
if constexpr (width == 1) {
return int8_t(a);
} else if constexpr (width == 2) {
Expand All @@ -91,6 +93,16 @@ KOKKOS_INLINE_FUNCTION constexpr auto comparable_cast(const A &a) {
}
}
}

// CUDA 11 emits a spurious warning about a missing return statement.
// It is very hard to write an expression with a type that matches the
// result of the above, so mark as unreacable for the affected compiler
// instead
#if defined(KOKKOS_ENABLE_CUDA)
#if CUDA_VERSION >= 11030
__builting_unreachable();
#endif
#endif
}

} // namespace Impl
Expand Down
2 changes: 2 additions & 0 deletions common/unit_test/Test_Common_LowerBound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ void test_lower_bound() {
} else {
return T(rand()) % n;
}
// avoid CUDA 11 issuing a spurious missing return statement warning
return T(4); // chosen by dice roll, guaranteed to be random
};

T maxEntry = 20;
Expand Down
2 changes: 2 additions & 0 deletions common/unit_test/Test_Common_UpperBound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void test_upper_bound() {
} else {
return T(rand()) % n;
}
// avoid CUDA 11 issuing a spurious missing return statement warning
return T(4); // chosen by dice roll, guaranteed to be random
};

constexpr T maxEntry = 20;
Expand Down

0 comments on commit bb68066

Please sign in to comment.