Skip to content

Commit

Permalink
GH-44372: [C++] Fix unaligned load/store implementation for clang-18 (#…
Browse files Browse the repository at this point in the history
…44468)

### Rationale for this change

CLang 18 complains about undefined behavior when memcpy is called on a T-unaligned `T*` pointer.
This is due to this upstream change: llvm/llvm-project#67766

### What changes are included in this PR?

Workaround by casting to `void*`.

### Are these changes tested?

By existing CI tests.

### Are there any user-facing changes?

No.

* GitHub Issue: #44372

Lead-authored-by: Antoine Pitrou <pitrou@free.fr>
Co-authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
pitrou and pitrou authored Oct 18, 2024
1 parent 0c32067 commit a5850e1
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, static_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, static_cast<const void*>(&value), sizeof(T));
return ret;
}

Expand Down

0 comments on commit a5850e1

Please sign in to comment.