Skip to content

Commit 10cc2ea

Browse files
authored
Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikic
atomicrmw on pointers: move integer-pointer cast hacks into backend 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 rust-lang/rust#134617
2 parents f4fde20 + 66503c1 commit 10cc2ea

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/intrinsics/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
969969

970970
let layout = amount.layout();
971971
match layout.ty.kind() {
972-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
972+
ty::Uint(_) | ty::Int(_) => {}
973973
_ => {
974974
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
975975
return Ok(());
@@ -982,7 +982,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
982982
let old =
983983
fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Add, ptr, amount);
984984

985-
let old = CValue::by_val(old, layout);
985+
let old = CValue::by_val(old, ret.layout());
986986
ret.write_cvalue(fx, old);
987987
}
988988
sym::atomic_xsub => {
@@ -991,7 +991,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
991991

992992
let layout = amount.layout();
993993
match layout.ty.kind() {
994-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
994+
ty::Uint(_) | ty::Int(_) => {}
995995
_ => {
996996
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
997997
return Ok(());
@@ -1004,7 +1004,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10041004
let old =
10051005
fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Sub, ptr, amount);
10061006

1007-
let old = CValue::by_val(old, layout);
1007+
let old = CValue::by_val(old, ret.layout());
10081008
ret.write_cvalue(fx, old);
10091009
}
10101010
sym::atomic_and => {
@@ -1013,7 +1013,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10131013

10141014
let layout = src.layout();
10151015
match layout.ty.kind() {
1016-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1016+
ty::Uint(_) | ty::Int(_) => {}
10171017
_ => {
10181018
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10191019
return Ok(());
@@ -1025,7 +1025,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10251025

10261026
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::And, ptr, src);
10271027

1028-
let old = CValue::by_val(old, layout);
1028+
let old = CValue::by_val(old, ret.layout());
10291029
ret.write_cvalue(fx, old);
10301030
}
10311031
sym::atomic_or => {
@@ -1034,7 +1034,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10341034

10351035
let layout = src.layout();
10361036
match layout.ty.kind() {
1037-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1037+
ty::Uint(_) | ty::Int(_) => {}
10381038
_ => {
10391039
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10401040
return Ok(());
@@ -1046,7 +1046,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10461046

10471047
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Or, ptr, src);
10481048

1049-
let old = CValue::by_val(old, layout);
1049+
let old = CValue::by_val(old, ret.layout());
10501050
ret.write_cvalue(fx, old);
10511051
}
10521052
sym::atomic_xor => {
@@ -1055,7 +1055,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10551055

10561056
let layout = src.layout();
10571057
match layout.ty.kind() {
1058-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1058+
ty::Uint(_) | ty::Int(_) => {}
10591059
_ => {
10601060
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10611061
return Ok(());
@@ -1067,7 +1067,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10671067

10681068
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Xor, ptr, src);
10691069

1070-
let old = CValue::by_val(old, layout);
1070+
let old = CValue::by_val(old, ret.layout());
10711071
ret.write_cvalue(fx, old);
10721072
}
10731073
sym::atomic_nand => {
@@ -1076,7 +1076,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10761076

10771077
let layout = src.layout();
10781078
match layout.ty.kind() {
1079-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1079+
ty::Uint(_) | ty::Int(_) => {}
10801080
_ => {
10811081
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10821082
return Ok(());
@@ -1088,7 +1088,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10881088

10891089
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Nand, ptr, src);
10901090

1091-
let old = CValue::by_val(old, layout);
1091+
let old = CValue::by_val(old, ret.layout());
10921092
ret.write_cvalue(fx, old);
10931093
}
10941094
sym::atomic_max => {

0 commit comments

Comments
 (0)