Skip to content
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

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

pitrou
Copy link
Member

@pitrou pitrou commented Oct 18, 2024

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.

…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
Copy link

⚠️ GitHub issue #44372 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions bot added awaiting review Awaiting review Component: C++ and removed awaiting review Awaiting review labels Oct 18, 2024
@pitrou pitrou requested review from bkietz and felipecrv October 18, 2024 09:47
Copy link
Member

@bkietz bkietz left a 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

@@ -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));
Copy link
Member

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

Copy link
Member Author

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...

cpp/src/arrow/util/ubsan.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added awaiting merge Awaiting merge awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Oct 18, 2024
cpp/src/arrow/util/ubsan.h Outdated Show resolved Hide resolved
cpp/src/arrow/util/ubsan.h Outdated Show resolved Hide resolved
@pitrou
Copy link
Member Author

pitrou commented Oct 18, 2024

@github-actions crossbow submit -g cpp

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Oct 18, 2024
Copy link

Revision: ab378dd

Submitted crossbow builds: ursacomputing/crossbow @ actions-be2686045c

Task Status
example-cpp-minimal-build-static GitHub Actions
example-cpp-minimal-build-static-system-dependency GitHub Actions
example-cpp-tutorial GitHub Actions
test-alpine-linux-cpp GitHub Actions
test-build-cpp-fuzz GitHub Actions
test-conda-cpp GitHub Actions
test-conda-cpp-valgrind GitHub Actions
test-cuda-cpp-ubuntu-20.04-cuda-11.2.2 GitHub Actions
test-cuda-cpp-ubuntu-22.04-cuda-11.7.1 GitHub Actions
test-debian-12-cpp-amd64 GitHub Actions
test-debian-12-cpp-i386 GitHub Actions
test-fedora-39-cpp GitHub Actions
test-ubuntu-20.04-cpp GitHub Actions
test-ubuntu-20.04-cpp-bundled GitHub Actions
test-ubuntu-22.04-cpp GitHub Actions
test-ubuntu-22.04-cpp-20 GitHub Actions
test-ubuntu-22.04-cpp-emscripten GitHub Actions
test-ubuntu-22.04-cpp-no-threading GitHub Actions
test-ubuntu-24.04-cpp GitHub Actions
test-ubuntu-24.04-cpp-gcc-13-bundled GitHub Actions
test-ubuntu-24.04-cpp-gcc-14 GitHub Actions
test-ubuntu-24.04-cpp-minimal-with-formats GitHub Actions
test-ubuntu-24.04-cpp-thread-sanitizer GitHub Actions

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Oct 18, 2024
@pitrou pitrou merged commit a5850e1 into apache:main Oct 18, 2024
42 of 43 checks passed
@pitrou pitrou removed the awaiting changes Awaiting changes label Oct 18, 2024
@pitrou pitrou deleted the gh44372-ubsan branch October 18, 2024 16:51
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants