Skip to content

Commit a5850e1

Browse files
authored
GH-44372: [C++] Fix unaligned load/store implementation for clang-18 (#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 <[email protected]> Co-authored-by: Antoine Pitrou <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent 0c32067 commit a5850e1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cpp/src/arrow/util/ubsan.h

Lines changed: 2 additions & 2 deletions
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, static_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, static_cast<const void*>(&value), sizeof(T));
7777
return ret;
7878
}
7979

0 commit comments

Comments
 (0)