Skip to content

Commit b802b19

Browse files
committed
linker issue fix
1 parent 9c72d10 commit b802b19

File tree

2 files changed

+29
-8
lines changed
  • compiler/rustc_codegen_cranelift/src/intrinsics
  • library/coretests/tests/floats

2 files changed

+29
-8
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,29 @@ fn codegen_float_intrinsic_call<'tcx>(
500500
CValue::by_val(codegen_f16_f128::f32_to_f16(fx, ret_val), fx.layout_of(ty))
501501
}
502502
_ => {
503-
let input_tys: Vec<_> = args.iter().map(|_| AbiParam::new(clif_ty)).collect();
504-
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
503+
let mut converted_args: Option<Vec<Value>> = None;
504+
let mut call_args: &[Value] = args;
505+
let mut call_name = name;
506+
let mut call_ty = clif_ty;
507+
let mut convert_back_to_f16 = false;
508+
509+
if clif_ty == types::F16 {
510+
if let Some(f32_name) = name.strip_suffix("16") {
511+
converted_args = Some(
512+
args.iter().map(|&arg| codegen_f16_f128::f16_to_f32(fx, arg)).collect(),
513+
);
514+
call_args = converted_args.as_deref().unwrap();
515+
call_name = f32_name;
516+
call_ty = types::F32;
517+
convert_back_to_f16 = true;
518+
}
519+
}
520+
521+
let input_tys: Vec<_> = call_args.iter().map(|_| AbiParam::new(call_ty)).collect();
522+
let ret_val =
523+
fx.lib_call(call_name, input_tys, vec![AbiParam::new(call_ty)], call_args)[0];
524+
let ret_val =
525+
if convert_back_to_f16 { codegen_f16_f128::f32_to_f16(fx, ret_val) } else { ret_val };
505526
CValue::by_val(ret_val, fx.layout_of(ty))
506527
}
507528
};

library/coretests/tests/floats/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ float_test! {
15571557
name: exp,
15581558
attrs: {
15591559
const: #[cfg(false)],
1560-
f16: #[cfg(all(not(miri), target_has_reliable_f16_math, not(bootstrap_cg_clif)))],
1560+
f16: #[cfg(all(not(miri), target_has_reliable_f16_math))],
15611561
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
15621562
},
15631563
test<Float> {
@@ -1578,7 +1578,7 @@ float_test! {
15781578
name: exp2,
15791579
attrs: {
15801580
const: #[cfg(false)],
1581-
f16: #[cfg(all(not(miri), target_has_reliable_f16_math, not(bootstrap_cg_clif)))],
1581+
f16: #[cfg(all(not(miri), target_has_reliable_f16_math))],
15821582
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
15831583
},
15841584
test<Float> {
@@ -1598,7 +1598,7 @@ float_test! {
15981598
name: ln,
15991599
attrs: {
16001600
const: #[cfg(false)],
1601-
f16: #[cfg(all(not(miri), target_has_reliable_f16_math, not(bootstrap_cg_clif)))],
1601+
f16: #[cfg(all(not(miri), target_has_reliable_f16_math))],
16021602
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
16031603
},
16041604
test<Float> {
@@ -1620,7 +1620,7 @@ float_test! {
16201620
name: log_generic,
16211621
attrs: {
16221622
const: #[cfg(false)],
1623-
f16: #[cfg(all(not(miri), target_has_reliable_f16_math, not(bootstrap_cg_clif)))],
1623+
f16: #[cfg(all(not(miri), target_has_reliable_f16_math))],
16241624
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
16251625
},
16261626
test<Float> {
@@ -1645,7 +1645,7 @@ float_test! {
16451645
name: log2,
16461646
attrs: {
16471647
const: #[cfg(false)],
1648-
f16: #[cfg(all(not(miri), target_has_reliable_f16_math, not(bootstrap_cg_clif)))],
1648+
f16: #[cfg(all(not(miri), target_has_reliable_f16_math))],
16491649
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
16501650
},
16511651
test<Float> {
@@ -1668,7 +1668,7 @@ float_test! {
16681668
name: log10,
16691669
attrs: {
16701670
const: #[cfg(false)],
1671-
f16: #[cfg(all(not(miri), target_has_reliable_f16_math, not(bootstrap_cg_clif)))],
1671+
f16: #[cfg(all(not(miri), target_has_reliable_f16_math))],
16721672
f128: #[cfg(all(not(miri), target_has_reliable_f128_math))],
16731673
},
16741674
test<Float> {

0 commit comments

Comments
 (0)