Skip to content

Commit 88b206d

Browse files
committed
atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance
1 parent 8536f20 commit 88b206d

File tree

3 files changed

+190
-9
lines changed
  • compiler
  • library/core/src/intrinsics

3 files changed

+190
-9
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10311031

10321032
let layout = src.layout();
10331033
match layout.ty.kind() {
1034-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1034+
ty::Int(_) => {}
10351035
_ => {
10361036
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10371037
return Ok(());
@@ -1052,7 +1052,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10521052

10531053
let layout = src.layout();
10541054
match layout.ty.kind() {
1055-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1055+
ty::Uint(_) => {}
10561056
_ => {
10571057
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10581058
return Ok(());
@@ -1073,7 +1073,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10731073

10741074
let layout = src.layout();
10751075
match layout.ty.kind() {
1076-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1076+
ty::Int(_) => {}
10771077
_ => {
10781078
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
10791079
return Ok(());
@@ -1094,7 +1094,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
10941094

10951095
let layout = src.layout();
10961096
match layout.ty.kind() {
1097-
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
1097+
ty::Uint(_) => {}
10981098
_ => {
10991099
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
11001100
return Ok(());

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+34-4
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,40 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
441441
}
442442

443443
// These are all AtomicRMW ops
444+
"max" | "min" => {
445+
let atom_op = if instruction == "max" {
446+
AtomicRmwBinOp::AtomicMax
447+
} else {
448+
AtomicRmwBinOp::AtomicMin
449+
};
450+
451+
let ty = fn_args.type_at(0);
452+
if matches!(ty.kind(), ty::Int(_)) {
453+
let ptr = args[0].immediate();
454+
let val = args[1].immediate();
455+
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
456+
} else {
457+
invalid_monomorphization(ty);
458+
return Ok(());
459+
}
460+
}
461+
"umax" | "umin" => {
462+
let atom_op = if instruction == "umax" {
463+
AtomicRmwBinOp::AtomicUMax
464+
} else {
465+
AtomicRmwBinOp::AtomicUMin
466+
};
467+
468+
let ty = fn_args.type_at(0);
469+
if matches!(ty.kind(), ty::Uint(_)) {
470+
let ptr = args[0].immediate();
471+
let val = args[1].immediate();
472+
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
473+
} else {
474+
invalid_monomorphization(ty);
475+
return Ok(());
476+
}
477+
}
444478
op => {
445479
let atom_op = match op {
446480
"xchg" => AtomicRmwBinOp::AtomicXchg,
@@ -450,10 +484,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
450484
"nand" => AtomicRmwBinOp::AtomicNand,
451485
"or" => AtomicRmwBinOp::AtomicOr,
452486
"xor" => AtomicRmwBinOp::AtomicXor,
453-
"max" => AtomicRmwBinOp::AtomicMax,
454-
"min" => AtomicRmwBinOp::AtomicMin,
455-
"umax" => AtomicRmwBinOp::AtomicUMax,
456-
"umin" => AtomicRmwBinOp::AtomicUMin,
457487
_ => bx.sess().dcx().emit_fatal(errors::UnknownAtomicOperation),
458488
};
459489

0 commit comments

Comments
 (0)