-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-44372: [C++] Fix unaligned load/store implementation for clang-18 #44468
Conversation
…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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workaround seems fine, just a few nits
cpp/src/arrow/util/ubsan.h
Outdated
@@ -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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one surprises me. If value is on the stack, then it is already correctly aligned for T
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's possible. I couldn't reproduce the original error...
@github-actions crossbow submit -g cpp |
Revision: ab378dd Submitted crossbow builds: ursacomputing/crossbow @ actions-be2686045c |
After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit a5850e1. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them. |
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.
misaligned-pointer-use
after clang-18 upgrade #44372