Skip to content

Commit

Permalink
Fix undefined behavior in is_zero_byte (#7014)
Browse files Browse the repository at this point in the history
* Fix undefined behavior in is_zero_byte

* Remove include file comments
  • Loading branch information
masterleinad committed May 21, 2024
1 parent f8f0cc4 commit ce0915b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/impl/Kokkos_ViewMapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <type_traits>
#include <initializer_list>

#include <Kokkos_Array.hpp>
#include <Kokkos_BitManipulation.hpp>
#include <Kokkos_Core_fwd.hpp>
#include <Kokkos_DetectionIdiom.hpp>
#include <Kokkos_Pair.hpp>
Expand Down Expand Up @@ -2538,9 +2540,10 @@ inline bool is_zero_byte(const T& t) {
sizeof(T) % sizeof(int) == 0, int,
std::conditional_t<sizeof(T) % sizeof(short int) == 0, short int,
char>>>>;
const auto* const ptr = reinterpret_cast<const comparison_type*>(&t);
auto bit_values = Kokkos::bit_cast<
Kokkos::Array<comparison_type, sizeof(T) / sizeof(comparison_type)>>(t);
for (std::size_t i = 0; i < sizeof(T) / sizeof(comparison_type); ++i)
if (ptr[i] != 0) return false;
if (bit_values[i] != 0) return false;
return true;
}

Expand Down

0 comments on commit ce0915b

Please sign in to comment.