Skip to content

Commit 0a1d3fa

Browse files
committed
Auto merge of #151485 - JonathanBrouwer:rollup-uTKVd4J, r=JonathanBrouwer
Rollup of 8 pull requests Successful merges: - #148206 (Deduplicated float tests and unified in floats/mod.rs) - #151042 (fix fallback impl for select_unpredictable intrinsic) - #151220 (option: Use Option::map in Option::cloned) - #151260 (Handle unevaluated ConstKind in in_operand) - #151441 (Fix ICE: Don't try to evaluate type_consts when eagerly collecting items) - #151465 (codegen: clarify some variable names around function calls) - #151469 (llvm: Tolerate dead_on_return attribute changes) - #151476 (Avoid `-> ()` in derived functions.) r? @ghost
2 parents d29e478 + a96fc9b commit 0a1d3fa

File tree

25 files changed

+855
-1465
lines changed

25 files changed

+855
-1465
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -986,16 +986,6 @@ impl<'a> MethodDef<'a> {
986986
f(cx, span, &substructure)
987987
}
988988

989-
fn get_ret_ty(
990-
&self,
991-
cx: &ExtCtxt<'_>,
992-
trait_: &TraitDef<'_>,
993-
generics: &Generics,
994-
type_ident: Ident,
995-
) -> Box<ast::Ty> {
996-
self.ret_ty.to_ty(cx, trait_.span, type_ident, generics)
997-
}
998-
999989
fn is_static(&self) -> bool {
1000990
!self.explicit_self
1001991
}
@@ -1068,10 +1058,14 @@ impl<'a> MethodDef<'a> {
10681058
self_arg.into_iter().chain(nonself_args).collect()
10691059
};
10701060

1071-
let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);
1061+
let ret_type = if let Ty::Unit = &self.ret_ty {
1062+
ast::FnRetTy::Default(span)
1063+
} else {
1064+
ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics))
1065+
};
10721066

10731067
let method_ident = Ident::new(self.name, span);
1074-
let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type));
1068+
let fn_decl = cx.fn_decl(args, ret_type);
10751069
let body_block = body.into_block(cx, span);
10761070

10771071
let trait_lo_sp = span.shrink_to_lo();
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
From aacbac292e8b470c8be0e284f3005192f94a0481 Mon Sep 17 00:00:00 2001
2+
From: xonx <119700621+xonx4l@users.noreply.github.com>
3+
Date: Tue, 13 Jan 2026 17:20:06 +0000
4+
Subject: [PATCH] Disable f16 math tests for cranelift
5+
6+
---
7+
coretests/tests/floats/mod.rs | 26 +++++++++++++-------------
8+
1 file changed, 13 insertions(+), 13 deletions(-)
9+
10+
diff --git a/coretests/tests/floats/mod.rs b/coretests/tests/floats/mod.rs
11+
index 58892b3daa6..dc3da4a3311 100644
12+
--- a/coretests/tests/floats/mod.rs
13+
+++ b/coretests/tests/floats/mod.rs
14+
@@ -1536,7 +1536,7 @@ fn s_nan() -> Float {
15+
name: powf,
16+
attrs: {
17+
const: #[cfg(false)],
18+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
19+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
20+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
21+
},
22+
test<Float> {
23+
@@ -1559,7 +1559,7 @@ fn s_nan() -> Float {
24+
name: exp,
25+
attrs: {
26+
const: #[cfg(false)],
27+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
28+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
29+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
30+
},
31+
test<Float> {
32+
@@ -1580,7 +1580,7 @@ fn s_nan() -> Float {
33+
name: exp2,
34+
attrs: {
35+
const: #[cfg(false)],
36+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
37+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
38+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
39+
},
40+
test<Float> {
41+
@@ -1600,7 +1600,7 @@ fn s_nan() -> Float {
42+
name: ln,
43+
attrs: {
44+
const: #[cfg(false)],
45+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
46+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
47+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
48+
},
49+
test<Float> {
50+
@@ -1622,7 +1622,7 @@ fn s_nan() -> Float {
51+
name: log,
52+
attrs: {
53+
const: #[cfg(false)],
54+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
55+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
56+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
57+
},
58+
test<Float> {
59+
@@ -1647,7 +1647,7 @@ fn s_nan() -> Float {
60+
name: log2,
61+
attrs: {
62+
const: #[cfg(false)],
63+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
64+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
65+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
66+
},
67+
test<Float> {
68+
@@ -1670,7 +1670,7 @@ fn s_nan() -> Float {
69+
name: log10,
70+
attrs: {
71+
const: #[cfg(false)],
72+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
73+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
74+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
75+
},
76+
test<Float> {
77+
@@ -1694,7 +1694,7 @@ fn s_nan() -> Float {
78+
name: asinh,
79+
attrs: {
80+
const: #[cfg(false)],
81+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
82+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
83+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
84+
},
85+
test<Float> {
86+
@@ -1725,7 +1725,7 @@ fn s_nan() -> Float {
87+
name: acosh,
88+
attrs: {
89+
const: #[cfg(false)],
90+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
91+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
92+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
93+
},
94+
test<Float> {
95+
@@ -1752,7 +1752,7 @@ fn s_nan() -> Float {
96+
name: atanh,
97+
attrs: {
98+
const: #[cfg(false)],
99+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
100+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
101+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
102+
},
103+
test<Float> {
104+
@@ -1778,7 +1778,7 @@ fn s_nan() -> Float {
105+
name: gamma,
106+
attrs: {
107+
const: #[cfg(false)],
108+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
109+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
110+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
111+
},
112+
test<Float> {
113+
@@ -1804,7 +1804,7 @@ fn s_nan() -> Float {
114+
name: ln_gamma,
115+
attrs: {
116+
const: #[cfg(false)],
117+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
118+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
119+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
120+
},
121+
test<Float> {
122+
@@ -1942,7 +1942,7 @@ fn s_nan() -> Float {
123+
attrs: {
124+
// FIXME(f16_f128): add math tests when available
125+
const: #[cfg(false)],
126+
- f16: #[cfg(any(miri, target_has_reliable_f16_math))],
127+
+ f16: #[cfg(false)], // FIXME(rust-lang/rustc_codegen_cranelift#1622)
128+
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
129+
},
130+
test<Float> {
131+
--
132+
2.50.1
133+

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13971397
fn call(
13981398
&mut self,
13991399
llty: &'ll Type,
1400-
fn_call_attrs: Option<&CodegenFnAttrs>,
1400+
caller_attrs: Option<&CodegenFnAttrs>,
14011401
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
14021402
llfn: &'ll Value,
14031403
args: &[&'ll Value],
14041404
funclet: Option<&Funclet<'ll>>,
1405-
instance: Option<Instance<'tcx>>,
1405+
callee_instance: Option<Instance<'tcx>>,
14061406
) -> &'ll Value {
14071407
debug!("call {:?} with args ({:?})", llfn, args);
14081408

@@ -1414,10 +1414,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14141414
}
14151415

14161416
// Emit CFI pointer type membership test
1417-
self.cfi_type_test(fn_call_attrs, fn_abi, instance, llfn);
1417+
self.cfi_type_test(caller_attrs, fn_abi, callee_instance, llfn);
14181418

14191419
// Emit KCFI operand bundle
1420-
let kcfi_bundle = self.kcfi_operand_bundle(fn_call_attrs, fn_abi, instance, llfn);
1420+
let kcfi_bundle = self.kcfi_operand_bundle(caller_attrs, fn_abi, callee_instance, llfn);
14211421
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
14221422
bundles.push(kcfi_bundle);
14231423
}
@@ -1435,17 +1435,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14351435
)
14361436
};
14371437

1438-
if let Some(instance) = instance {
1438+
if let Some(callee_instance) = callee_instance {
14391439
// Attributes on the function definition being called
1440-
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
1441-
if let Some(fn_call_attrs) = fn_call_attrs
1440+
let callee_attrs = self.cx.tcx.codegen_fn_attrs(callee_instance.def_id());
1441+
if let Some(caller_attrs) = caller_attrs
14421442
// If there is an inline attribute and a target feature that matches
14431443
// we will add the attribute to the callsite otherwise we'll omit
14441444
// this and not add the attribute to prevent soundness issues.
1445-
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance)
1445+
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, callee_instance)
14461446
&& self.cx.tcx.is_target_feature_call_safe(
1447-
&fn_defn_attrs.target_features,
1448-
&fn_call_attrs.target_features.iter().cloned().chain(
1447+
&callee_attrs.target_features,
1448+
&caller_attrs.target_features.iter().cloned().chain(
14491449
self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature {
14501450
name: *feat,
14511451
kind: TargetFeatureKind::Implied,
@@ -1470,14 +1470,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14701470
fn tail_call(
14711471
&mut self,
14721472
llty: Self::Type,
1473-
fn_attrs: Option<&CodegenFnAttrs>,
1473+
caller_attrs: Option<&CodegenFnAttrs>,
14741474
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
14751475
llfn: Self::Value,
14761476
args: &[Self::Value],
14771477
funclet: Option<&Self::Funclet>,
1478-
instance: Option<Instance<'tcx>>,
1478+
callee_instance: Option<Instance<'tcx>>,
14791479
) {
1480-
let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance);
1480+
let call =
1481+
self.call(llty, caller_attrs, Some(fn_abi), llfn, args, funclet, callee_instance);
14811482
llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail);
14821483

14831484
match &fn_abi.ret.mode {

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
199199
// do an invoke, otherwise do a call.
200200
let fn_ty = bx.fn_decl_backend_type(fn_abi);
201201

202-
let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
202+
let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
203203
Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
204204
} else {
205205
None
206206
};
207-
let fn_attrs = fn_attrs.as_deref();
207+
let caller_attrs = caller_attrs.as_deref();
208208

209209
if !fn_abi.can_unwind {
210210
unwind = mir::UnwindAction::Unreachable;
@@ -233,7 +233,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
233233
};
234234

235235
if kind == CallKind::Tail {
236-
bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
236+
bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
237237
return MergingSucc::False;
238238
}
239239

@@ -245,7 +245,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
245245
};
246246
let invokeret = bx.invoke(
247247
fn_ty,
248-
fn_attrs,
248+
caller_attrs,
249249
Some(fn_abi),
250250
fn_ptr,
251251
llargs,
@@ -268,8 +268,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
268268
}
269269
MergingSucc::False
270270
} else {
271-
let llret =
272-
bx.call(fn_ty, fn_attrs, Some(fn_abi), fn_ptr, llargs, self.funclet(fx), instance);
271+
let llret = bx.call(
272+
fn_ty,
273+
caller_attrs,
274+
Some(fn_abi),
275+
fn_ptr,
276+
llargs,
277+
self.funclet(fx),
278+
instance,
279+
);
273280
if fx.mir[self.bb].is_cleanup {
274281
bx.apply_attrs_to_cleanup_callsite(llret);
275282
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,13 @@ pub trait BuilderMethods<'a, 'tcx>:
600600
///
601601
/// ## Arguments
602602
///
603-
/// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory.
604-
/// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se.
605-
/// Any ABI-related transformations should be handled by different, earlier stages of codegen.
606-
/// For instance, in the caller of `BuilderMethods::call`.
603+
/// `caller_attrs` are the attributes of the surrounding caller; they have nothing to do with
604+
/// the callee.
605+
///
606+
/// The `caller_attrs`, `fn_abi`, and `callee_instance` arguments are Options because they are
607+
/// advisory. They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI
608+
/// per se. Any ABI-related transformations should be handled by different, earlier stages of
609+
/// codegen. For instance, in the caller of `BuilderMethods::call`.
607610
///
608611
/// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance`
609612
/// should still do correct codegen, and code should not be miscompiled if they are omitted.
@@ -620,23 +623,23 @@ pub trait BuilderMethods<'a, 'tcx>:
620623
fn call(
621624
&mut self,
622625
llty: Self::Type,
623-
fn_attrs: Option<&CodegenFnAttrs>,
626+
caller_attrs: Option<&CodegenFnAttrs>,
624627
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
625628
fn_val: Self::Value,
626629
args: &[Self::Value],
627630
funclet: Option<&Self::Funclet>,
628-
instance: Option<Instance<'tcx>>,
631+
callee_instance: Option<Instance<'tcx>>,
629632
) -> Self::Value;
630633

631634
fn tail_call(
632635
&mut self,
633636
llty: Self::Type,
634-
fn_attrs: Option<&CodegenFnAttrs>,
637+
caller_attrs: Option<&CodegenFnAttrs>,
635638
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
636639
llfn: Self::Value,
637640
args: &[Self::Value],
638641
funclet: Option<&Self::Funclet>,
639-
instance: Option<Instance<'tcx>>,
642+
callee_instance: Option<Instance<'tcx>>,
640643
);
641644

642645
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,18 @@ where
343343

344344
// Check the qualifs of the value of `const` items.
345345
let uneval = match constant.const_ {
346-
Const::Ty(_, ct)
347-
if matches!(
348-
ct.kind(),
349-
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_)
350-
) =>
351-
{
352-
None
353-
}
354-
Const::Ty(_, c) => {
355-
bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c)
356-
}
346+
Const::Ty(_, ct) => match ct.kind() {
347+
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
348+
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`).
349+
ty::ConstKind::Unevaluated(_) => None,
350+
// FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
351+
// strict, and if instead we should be doing some kind of value-based analysis.
352+
ty::ConstKind::Value(_) => None,
353+
_ => bug!(
354+
"expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}",
355+
ct
356+
),
357+
},
357358
Const::Unevaluated(uv, _) => Some(uv),
358359
Const::Val(..) => None,
359360
};
@@ -364,10 +365,8 @@ where
364365
// check performed after the promotion. Verify that with an assertion.
365366
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
366367

367-
// Don't peak inside trait associated constants, also `#[type_const] const` items
368-
// don't have bodies so there's nothing to look at
369-
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !cx.tcx.is_type_const(def)
370-
{
368+
// Don't peak inside trait associated constants.
369+
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
371370
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
372371

373372
if !Q::in_qualifs(&qualifs) {

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) {
527527
*unwrap(C), CaptureInfo(CaptureComponents::Address |
528528
CaptureComponents::ReadProvenance)));
529529
}
530+
#endif
531+
#if LLVM_VERSION_GE(23, 0)
532+
if (RustAttr == LLVMRustAttributeKind::DeadOnReturn) {
533+
return wrap(Attribute::getWithDeadOnReturnInfo(*unwrap(C),
534+
llvm::DeadOnReturnInfo()));
535+
}
530536
#endif
531537
return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr)));
532538
}

0 commit comments

Comments
 (0)