Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions cpp/src/arrow/util/ubsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cstring>
#include <memory>
#include <type_traits>
#include <bit>

#include "arrow/util/aligned_storage.h"
#include "arrow/util/macros.h"
Expand Down Expand Up @@ -75,20 +76,17 @@ ARROW_FORCE_INLINE std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoad
return data;
}


template <typename U, typename T>
ARROW_FORCE_INLINE
std::enable_if_t<std::is_trivially_copyable_v<T> && std::is_trivially_copyable_v<U> &&
sizeof(T) == sizeof(U),
U>
SafeCopy(T value) {
using TypeU = std::remove_const_t<U>;
arrow::internal::AlignedStorage<TypeU> raw_data;
std::memcpy(raw_data.get(), static_cast<const void*>(&value), sizeof(T));
auto data = *raw_data.get();
raw_data.destroy();
return data;
return std::bit_cast<std::remove_const_t<U>>(value);
}


template <typename T>
ARROW_FORCE_INLINE std::enable_if_t<std::is_trivially_copyable_v<T>, void> SafeStore(
void* unaligned, T value) {
Expand Down