Skip to content

atomicrmw on pointers: move integer-pointer cast hacks into backend - #144192

Merged
bors merged 2 commits into
rust-lang:masterfrom
RalfJung:atomicrmw-ptr
Aug 9, 2025
Merged

bors merged 2 commits into
rust-lang:masterfrom
RalfJung:atomicrmw-ptr

Conversation

@RalfJung

@RalfJung RalfJung commented Jul 19, 2025 •

Copy link
Copy Markdown
Member

View all comments

Conceptually, we want to have atomic operations on pointers of the form fn atomic_add(ptr: *mut T, offset: usize, ...). However, LLVM does not directly support such operations (llvm/llvm-project#120837), so we have to cast the offset to a pointer somewhere.

This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely.

Cc @nikic -- this is the best we can do right now, right?
Fixes #134617

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-atomic Area: Atomics, barriers, and sync primitives A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atomic RMW intrinsics: avoid unnecessary ptr/int conversions

8 participants