Skip to content

Commit ffb9d94

Browse files
committed
Auto merge of #145126 - tgross35:rollup-6w87usd, r=tgross35
Rollup of 8 pull requests Successful merges: - #139451 (Add `target_env = "macabi"` and `target_env = "sim"`) - #144039 (Use `tcx.short_string()` in more diagnostics) - #144192 (atomicrmw on pointers: move integer-pointer cast hacks into backend) - #144545 (In rustc_pattern_analysis, put `true` witnesses before `false` witnesses) - #144579 (Implement declarative (`macro_rules!`) attribute macros (RFC 3697)) - #144649 (Account for bare tuples and `Pin` methods in field searching logic) - #144775 (more strongly dissuade use of `skip_binder`) - #144987 (Enable f16 and f128 on targets that were fixed in LLVM21) r? `@ghost` `@rustbot` modify labels: rollup
2 parents de3efa7 + 660bf91 commit ffb9d94

File tree

179 files changed

+1734
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+1734
-791
lines changed

compiler/rustc_codegen_cranelift/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 => {

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
16711671
dst: RValue<'gcc>,
16721672
src: RValue<'gcc>,
16731673
order: AtomicOrdering,
1674+
ret_ptr: bool,
16741675
) -> RValue<'gcc> {
16751676
let size = get_maybe_pointer_size(src);
16761677
let name = match op {
@@ -1698,14 +1699,18 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
16981699
let atomic_function = self.context.get_builtin_function(name);
16991700
let order = self.context.new_rvalue_from_int(self.i32_type, order.to_gcc());
17001701

1702+
// FIXME: If `ret_ptr` is true and `src` is an integer, we should really tell GCC
1703+
// that this is a pointer operation that needs to preserve provenance -- but like LLVM,
1704+
// GCC does not currently seems to support that.
17011705
let void_ptr_type = self.context.new_type::<*mut ()>();
17021706
let volatile_void_ptr_type = void_ptr_type.make_volatile();
17031707
let dst = self.context.new_cast(self.location, dst, volatile_void_ptr_type);
17041708
// FIXME(antoyo): not sure why, but we have the wrong type here.
17051709
let new_src_type = atomic_function.get_param(1).to_rvalue().get_type();
17061710
let src = self.context.new_bitcast(self.location, src, new_src_type);
17071711
let res = self.context.new_call(self.location, atomic_function, &[dst, src, order]);
1708-
self.context.new_cast(self.location, res, src.get_type())
1712+
let res_type = if ret_ptr { void_ptr_type } else { src.get_type() };
1713+
self.context.new_cast(self.location, res, res_type)
17091714
}
17101715

17111716
fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope) {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,13 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13271327
&mut self,
13281328
op: rustc_codegen_ssa::common::AtomicRmwBinOp,
13291329
dst: &'ll Value,
1330-
mut src: &'ll Value,
1330+
src: &'ll Value,
13311331
order: rustc_middle::ty::AtomicOrdering,
1332+
ret_ptr: bool,
13321333
) -> &'ll Value {
1333-
// The only RMW operation that LLVM supports on pointers is compare-exchange.
1334-
let requires_cast_to_int = self.val_ty(src) == self.type_ptr()
1335-
&& op != rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg;
1336-
if requires_cast_to_int {
1337-
src = self.ptrtoint(src, self.type_isize());
1338-
}
1334+
// FIXME: If `ret_ptr` is true and `src` is not a pointer, we *should* tell LLVM that the
1335+
// LHS is a pointer and the operation should be provenance-preserving, but LLVM does not
1336+
// currently support that (https://github.com/llvm/llvm-project/issues/120837).
13391337
let mut res = unsafe {
13401338
llvm::LLVMBuildAtomicRMW(
13411339
self.llbuilder,
@@ -1346,7 +1344,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13461344
llvm::False, // SingleThreaded
13471345
)
13481346
};
1349-
if requires_cast_to_int {
1347+
if ret_ptr && self.val_ty(res) != self.type_ptr() {
13501348
res = self.inttoptr(res, self.type_ptr());
13511349
}
13521350
res

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,24 +377,25 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
377377
let target_abi = sess.target.options.abi.as_ref();
378378
let target_pointer_width = sess.target.pointer_width;
379379
let version = get_version();
380+
let lt_20_1_1 = version < (20, 1, 1);
381+
let lt_21_0_0 = version < (21, 0, 0);
380382

381383
cfg.has_reliable_f16 = match (target_arch, target_os) {
382-
// Selection failure <https://github.com/llvm/llvm-project/issues/50374>
383-
("s390x", _) => false,
384-
// LLVM crash without neon <https://github.com/llvm/llvm-project/issues/129394> (now fixed)
384+
// LLVM crash without neon <https://github.com/llvm/llvm-project/issues/129394> (fixed in llvm20)
385385
("aarch64", _)
386-
if !cfg.target_features.iter().any(|f| f.as_str() == "neon")
387-
&& version < (20, 1, 1) =>
386+
if !cfg.target_features.iter().any(|f| f.as_str() == "neon") && lt_20_1_1 =>
388387
{
389388
false
390389
}
391390
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
392391
("arm64ec", _) => false,
392+
// Selection failure <https://github.com/llvm/llvm-project/issues/50374> (fixed in llvm21)
393+
("s390x", _) if lt_21_0_0 => false,
393394
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
394395
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
395396
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
396397
("csky", _) => false,
397-
("hexagon", _) => false,
398+
("hexagon", _) if lt_21_0_0 => false, // (fixed in llvm21)
398399
("powerpc" | "powerpc64", _) => false,
399400
("sparc" | "sparc64", _) => false,
400401
("wasm32" | "wasm64", _) => false,
@@ -407,9 +408,10 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
407408
cfg.has_reliable_f128 = match (target_arch, target_os) {
408409
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
409410
("arm64ec", _) => false,
410-
// Selection bug <https://github.com/llvm/llvm-project/issues/96432>
411-
("mips64" | "mips64r6", _) => false,
412-
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>
411+
// Selection bug <https://github.com/llvm/llvm-project/issues/96432> (fixed in llvm20)
412+
("mips64" | "mips64r6", _) if lt_20_1_1 => false,
413+
// Selection bug <https://github.com/llvm/llvm-project/issues/95471>. This issue is closed
414+
// but basic math still does not work.
413415
("nvptx64", _) => false,
414416
// Unsupported https://github.com/llvm/llvm-project/issues/121122
415417
("amdgpu", _) => false,
@@ -419,8 +421,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
419421
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
420422
("sparc", _) => false,
421423
// Stack alignment bug <https://github.com/llvm/llvm-project/issues/77401>. NB: tests may
422-
// not fail if our compiler-builtins is linked.
423-
("x86", _) => false,
424+
// not fail if our compiler-builtins is linked. (fixed in llvm21)
425+
("x86", _) if lt_21_0_0 => false,
424426
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
425427
("x86_64", "windows") if target_env == "gnu" && target_abi != "llvm" => false,
426428
// There are no known problems on other platforms, so the only requirement is that symbols

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ codegen_ssa_invalid_monomorphization_basic_float_type = invalid monomorphization
101101
102102
codegen_ssa_invalid_monomorphization_basic_integer_type = invalid monomorphization of `{$name}` intrinsic: expected basic integer type, found `{$ty}`
103103
104+
codegen_ssa_invalid_monomorphization_basic_integer_or_ptr_type = invalid monomorphization of `{$name}` intrinsic: expected basic integer or pointer type, found `{$ty}`
105+
104106
codegen_ssa_invalid_monomorphization_cannot_return = invalid monomorphization of `{$name}` intrinsic: cannot return `{$ret_ty}`, expected `u{$expected_int_bits}` or `[u8; {$expected_bytes}]`
105107
106108
codegen_ssa_invalid_monomorphization_cast_wide_pointer = invalid monomorphization of `{$name}` intrinsic: cannot cast wide pointer `{$ty}`

compiler/rustc_codegen_ssa/src/back/apple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod tests;
1717

1818
/// The canonical name of the desired SDK for a given target.
1919
pub(super) fn sdk_name(target: &Target) -> &'static str {
20-
match (&*target.os, &*target.abi) {
20+
match (&*target.os, &*target.env) {
2121
("macos", "") => "MacOSX",
2222
("ios", "") => "iPhoneOS",
2323
("ios", "sim") => "iPhoneSimulator",
@@ -34,7 +34,7 @@ pub(super) fn sdk_name(target: &Target) -> &'static str {
3434
}
3535

3636
pub(super) fn macho_platform(target: &Target) -> u32 {
37-
match (&*target.os, &*target.abi) {
37+
match (&*target.os, &*target.env) {
3838
("macos", _) => object::macho::PLATFORM_MACOS,
3939
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST,
4040
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR,

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
30263026
/// We need to communicate five things to the linker on Apple/Darwin targets:
30273027
/// - The architecture.
30283028
/// - The operating system (and that it's an Apple platform).
3029-
/// - The environment / ABI.
3029+
/// - The environment.
30303030
/// - The deployment target.
30313031
/// - The SDK version.
30323032
fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
@@ -3040,7 +3040,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
30403040
// `sess.target.arch` (`target_arch`) is not detailed enough.
30413041
let llvm_arch = sess.target.llvm_target.split_once('-').expect("LLVM target must have arch").0;
30423042
let target_os = &*sess.target.os;
3043-
let target_abi = &*sess.target.abi;
3043+
let target_env = &*sess.target.env;
30443044

30453045
// The architecture name to forward to the linker.
30463046
//
@@ -3091,14 +3091,14 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
30913091
// > - visionos-simulator
30923092
// > - xros-simulator
30933093
// > - driverkit
3094-
let platform_name = match (target_os, target_abi) {
3094+
let platform_name = match (target_os, target_env) {
30953095
(os, "") => os,
30963096
("ios", "macabi") => "mac-catalyst",
30973097
("ios", "sim") => "ios-simulator",
30983098
("tvos", "sim") => "tvos-simulator",
30993099
("watchos", "sim") => "watchos-simulator",
31003100
("visionos", "sim") => "visionos-simulator",
3101-
_ => bug!("invalid OS/ABI combination for Apple target: {target_os}, {target_abi}"),
3101+
_ => bug!("invalid OS/env combination for Apple target: {target_os}, {target_env}"),
31023102
};
31033103

31043104
let min_version = sess.apple_deployment_target().fmt_full().to_string();

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,14 @@ pub enum InvalidMonomorphization<'tcx> {
764764
ty: Ty<'tcx>,
765765
},
766766

767+
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_or_ptr_type, code = E0511)]
768+
BasicIntegerOrPtrType {
769+
#[primary_span]
770+
span: Span,
771+
name: Symbol,
772+
ty: Ty<'tcx>,
773+
},
774+
767775
#[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
768776
BasicFloatType {
769777
#[primary_span]

0 commit comments

Comments
 (0)