Skip to content

Commit 781ea18

Browse files
committed
Always inline functions signatures containing f16 or f128
There are a handful of tier 2 and tier 3 targets that cause a LLVM crash or linker error when generating code that contains `f16` or `f128`. The cranelift backend also does not support these types. To work around this, every function in `std` or `core` that contains these types must be marked `#[inline]` in order to avoid sending any code to the backend unless specifically requested. However, this is inconvenient and easy to forget. Introduce a check for these types in the frontend that automatically inlines any function signatures that take or return `f16` or `f128`. Note that this is not a perfect fix because it does not account for the types being passed by reference or as members of aggregate types, but this is sufficient for what is currently needed in the standard library. Fixes: #133035 Closes: #133037
1 parent b77dbbd commit 781ea18

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

compiler/rustc_mir_transform/src/cross_crate_inline.rs

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
5050
_ => {}
5151
}
5252

53+
let sig = tcx.fn_sig(def_id).instantiate_identity();
54+
for ty in sig.inputs().skip_binder().iter().chain(std::iter::once(&sig.output().skip_binder()))
55+
{
56+
// FIXME(f16_f128): in order to avoid crashes building `core`, always inline to skip
57+
// codegen if the function is not used.
58+
if ty == &tcx.types.f16 || ty == &tcx.types.f128 {
59+
return true;
60+
}
61+
}
62+
5363
// Don't do any inference when incremental compilation is enabled; the additional inlining that
5464
// inference permits also creates more work for small edits.
5565
if tcx.sess.opts.incremental.is_some() {
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ revisions: default nopt
2+
//@[nopt] compile-flags: -Zcross-crate-inline-threshold=never -Zmir-opt-level=0 -Cno-prepopulate-passes
3+
4+
// Ensure that functions using `f16` and `f128` are always inlined to avoid crashes
5+
// when the backend does not support these types.
6+
7+
#![crate_type = "lib"]
8+
#![feature(f128)]
9+
#![feature(f16)]
10+
11+
pub fn f16_arg(_a: f16) {
12+
// CHECK-NOT: f16_arg
13+
todo!()
14+
}
15+
16+
pub fn f16_ret() -> f16 {
17+
// CHECK-NOT: f16_ret
18+
todo!()
19+
}
20+
21+
pub fn f128_arg(_a: f128) {
22+
// CHECK-NOT: f128_arg
23+
todo!()
24+
}
25+
26+
pub fn f128_ret() -> f128 {
27+
// CHECK-NOT: f128_ret
28+
todo!()
29+
}

0 commit comments

Comments
 (0)