Skip to content

Commit e34efd3

Browse files
committed
apacheGH-44372: [C++] Fix unaligned load/store implementation for clang-18
CLang 18 complains about undefined behavior when memcpy is called on a T-unaligned `T*` pointer. Workaround by casting to `void*`. This is due to this upstream change: llvm/llvm-project#67766
1 parent 0c32067 commit e34efd3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cpp/src/arrow/util/ubsan.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoadAs(
6363
template <typename T>
6464
inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoad(const T* unaligned) {
6565
std::remove_const_t<T> ret;
66-
std::memcpy(&ret, unaligned, sizeof(T));
66+
std::memcpy(&ret, reinterpret_cast<const void*>(unaligned), sizeof(T));
6767
return ret;
6868
}
6969

@@ -73,7 +73,7 @@ inline std::enable_if_t<std::is_trivially_copyable_v<T> &&
7373
U>
7474
SafeCopy(T value) {
7575
std::remove_const_t<U> ret;
76-
std::memcpy(&ret, &value, sizeof(T));
76+
std::memcpy(&ret, reinterpret_cast<const void*>(&value), sizeof(T));
7777
return ret;
7878
}
7979

0 commit comments

Comments
 (0)