Skip to content

Commit

Permalink
apacheGH-44372: [C++] Fix unaligned load/store implementation for cla…
Browse files Browse the repository at this point in the history
…ng-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
  • Loading branch information
pitrou committed Oct 18, 2024
1 parent 0c32067 commit e34efd3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cpp/src/arrow/util/ubsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoadAs(
template <typename T>
inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoad(const T* unaligned) {
std::remove_const_t<T> ret;
std::memcpy(&ret, unaligned, sizeof(T));
std::memcpy(&ret, reinterpret_cast<const void*>(unaligned), sizeof(T));
return ret;
}

Expand All @@ -73,7 +73,7 @@ inline std::enable_if_t<std::is_trivially_copyable_v<T> &&
U>
SafeCopy(T value) {
std::remove_const_t<U> ret;
std::memcpy(&ret, &value, sizeof(T));
std::memcpy(&ret, reinterpret_cast<const void*>(&value), sizeof(T));
return ret;
}

Expand Down

0 comments on commit e34efd3

Please sign in to comment.