From 4271bf6b37ac94116899fe3d6c5b08310a12341f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 13 Mar 2024 09:15:52 +0000 Subject: [PATCH 1/3] Assert that we only use compare-exchange on pointers and no other rmw op --- compiler/rustc_codegen_llvm/src/builder.rs | 5 ++--- compiler/rustc_codegen_ssa/src/common.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 63e59ea13fc35..79490c9f51bb4 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1136,9 +1136,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { order: rustc_codegen_ssa::common::AtomicOrdering, ) -> &'ll Value { // The only RMW operation that LLVM supports on pointers is compare-exchange. - if self.val_ty(src) == self.type_ptr() - && op != rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg - { + if self.val_ty(src) == self.type_ptr() { + assert_eq!(op, rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg); src = self.ptrtoint(src, self.type_isize()); } unsafe { diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index 44a2434238dad..36a13c6469dad 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -42,7 +42,7 @@ pub enum RealPredicate { RealPredicateTrue, } -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Debug)] pub enum AtomicRmwBinOp { AtomicXchg, AtomicAdd, From ef85fd40e2c8e4a31ab94a4f54a2bbe9f1daa2e7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 13 Mar 2024 14:52:42 +0100 Subject: [PATCH 2/3] Update builder.rs --- compiler/rustc_codegen_llvm/src/builder.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 79490c9f51bb4..a9368c05af51a 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1138,7 +1138,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { // The only RMW operation that LLVM supports on pointers is compare-exchange. if self.val_ty(src) == self.type_ptr() { assert_eq!(op, rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg); - src = self.ptrtoint(src, self.type_isize()); } unsafe { llvm::LLVMBuildAtomicRMW( From 8c4b78dee6a0345bf59d580c9479f0a930c2dfc7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 13 Mar 2024 15:05:06 +0100 Subject: [PATCH 3/3] Update builder.rs --- compiler/rustc_codegen_llvm/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index a9368c05af51a..24dadfd960e7e 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1132,7 +1132,7 @@ 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_codegen_ssa::common::AtomicOrdering, ) -> &'ll Value { // The only RMW operation that LLVM supports on pointers is compare-exchange.