Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 49b21f2

Browse files
committed
Fix returning (u128, u128)
1 parent 63646b1 commit 49b21f2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

example/mini_core_hello_world.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,23 @@ impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsiz
117117
fn take_f32(_f: f32) {}
118118
fn take_unique(_u: Unique<()>) {}
119119

120+
fn return_u128_pair() -> (u128, u128) {
121+
(0, 0)
122+
}
123+
124+
fn call_return_u128_pair() {
125+
return_u128_pair();
126+
}
127+
120128
fn main() {
121129
take_unique(Unique {
122130
pointer: 0 as *const (),
123131
_marker: PhantomData,
124132
});
125133
take_f32(0.1);
126134

135+
call_return_u128_pair();
136+
127137
//return;
128138

129139
unsafe {

src/abi.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@ fn get_pass_mode<'tcx>(
113113
PassMode::ByVal(scalar_to_clif_type(tcx, scalar.clone()))
114114
}
115115
layout::Abi::ScalarPair(a, b) => {
116-
PassMode::ByValPair(
117-
scalar_to_clif_type(tcx, a.clone()),
118-
scalar_to_clif_type(tcx, b.clone()),
119-
)
116+
let a = scalar_to_clif_type(tcx, a.clone());
117+
let b = scalar_to_clif_type(tcx, b.clone());
118+
if a == types::I128 && b == types::I128 {
119+
// Returning (i128, i128) by-val-pair would take 4 regs, while only 3 are
120+
// available on x86_64. Cranelift gets confused when too many return params
121+
// are used.
122+
PassMode::ByRef
123+
} else {
124+
PassMode::ByValPair(a, b)
125+
}
120126
}
121127

122128
// FIXME implement Vector Abi in a cg_llvm compatible way

0 commit comments

Comments
 (0)