diff options
| author | Ralf Jung <post@ralfj.de> | 2025-07-19 23:23:40 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-07-23 08:32:55 +0200 |
| commit | de1b999ff6c981475e4491ea2fff1851655587e5 (patch) | |
| tree | 647955d91fcfb7337489f4c4fd4c8226e948aab6 /compiler/rustc_codegen_llvm/src/builder.rs | |
| parent | efcae7d31d30ba8d8c806fbb8dea634e78d7b969 (diff) | |
| download | rust-de1b999ff6c981475e4491ea2fff1851655587e5.tar.gz rust-de1b999ff6c981475e4491ea2fff1851655587e5.zip | |
atomicrmw on pointers: move integer-pointer cast hacks into backend
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/builder.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/builder.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 0ade9edb0d2..51593f3f065 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1326,15 +1326,13 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { &mut self, op: rustc_codegen_ssa::common::AtomicRmwBinOp, dst: &'ll Value, - mut src: &'ll Value, + src: &'ll Value, order: rustc_middle::ty::AtomicOrdering, + ret_ptr: bool, ) -> &'ll Value { - // The only RMW operation that LLVM supports on pointers is compare-exchange. - let requires_cast_to_int = self.val_ty(src) == self.type_ptr() - && op != rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg; - if requires_cast_to_int { - src = self.ptrtoint(src, self.type_isize()); - } + // FIXME: If `ret_ptr` is true and `src` is not a pointer, we *should* tell LLVM that the + // LHS is a pointer and the operation should be provenance-preserving, but LLVM does not + // currently support that (https://github.com/llvm/llvm-project/issues/120837). let mut res = unsafe { llvm::LLVMBuildAtomicRMW( self.llbuilder, @@ -1345,7 +1343,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llvm::False, // SingleThreaded ) }; - if requires_cast_to_int { + if ret_ptr && self.val_ty(res) != self.type_ptr() { res = self.inttoptr(res, self.type_ptr()); } res |
