From a5850e1097515b9afd401a9bc6b265ced288c360 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 18 Oct 2024 18:51:32 +0200 Subject: [PATCH] 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: https://github.com/llvm/llvm-project/pull/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 Co-authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- cpp/src/arrow/util/ubsan.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/util/ubsan.h b/cpp/src/arrow/util/ubsan.h index 900d8011dfd69..2308ee33519ca 100644 --- a/cpp/src/arrow/util/ubsan.h +++ b/cpp/src/arrow/util/ubsan.h @@ -63,7 +63,7 @@ inline std::enable_if_t, T> SafeLoadAs( template inline std::enable_if_t, T> SafeLoad(const T* unaligned) { std::remove_const_t ret; - std::memcpy(&ret, unaligned, sizeof(T)); + std::memcpy(&ret, static_cast(unaligned), sizeof(T)); return ret; } @@ -73,7 +73,7 @@ inline std::enable_if_t && U> SafeCopy(T value) { std::remove_const_t ret; - std::memcpy(&ret, &value, sizeof(T)); + std::memcpy(&ret, static_cast(&value), sizeof(T)); return ret; }