Skip to content

Commit e7ce833

Browse files
authored
Unrolled build for rust-lang#138398
Rollup merge of rust-lang#138398 - RalfJung:atomic-intrinsics-provenance, r=nnethercote atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance The provenance semantics match what Miri implements and what the `AtomicPtr` API expects.
2 parents 523c507 + 88b206d commit e7ce833

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
@@ -433,6 +433,40 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
433433
}
434434

435435
// These are all AtomicRMW ops
436+
"max" | "min" => {
437+
let atom_op = if instruction == "max" {
438+
AtomicRmwBinOp::AtomicMax
439+
} else {
440+
AtomicRmwBinOp::AtomicMin
441+
};
442+
443+
let ty = fn_args.type_at(0);
444+
if matches!(ty.kind(), ty::Int(_)) {
445+
let ptr = args[0].immediate();
446+
let val = args[1].immediate();
447+
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
448+
} else {
449+
invalid_monomorphization(ty);
450+
return Ok(());
451+
}
452+
}
453+
"umax" | "umin" => {
454+
let atom_op = if instruction == "umax" {
455+
AtomicRmwBinOp::AtomicUMax
456+
} else {
457+
AtomicRmwBinOp::AtomicUMin
458+
};
459+
460+
let ty = fn_args.type_at(0);
461+
if matches!(ty.kind(), ty::Uint(_)) {
462+
let ptr = args[0].immediate();
463+
let val = args[1].immediate();
464+
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
465+
} else {
466+
invalid_monomorphization(ty);
467+
return Ok(());
468+
}
469+
}
436470
op => {
437471
let atom_op = match op {
438472
"xchg" => AtomicRmwBinOp::AtomicXchg,
@@ -442,10 +476,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
442476
"nand" => AtomicRmwBinOp::AtomicNand,
443477
"or" => AtomicRmwBinOp::AtomicOr,
444478
"xor" => AtomicRmwBinOp::AtomicXor,
445-
"max" => AtomicRmwBinOp::AtomicMax,
446-
"min" => AtomicRmwBinOp::AtomicMin,
447-
"umax" => AtomicRmwBinOp::AtomicUMax,
448-
"umin" => AtomicRmwBinOp::AtomicUMin,
449479
_ => bx.sess().dcx().emit_fatal(errors::UnknownAtomicOperation),
450480
};
451481

0 commit comments

Comments
 (0)