Skip to content

Commit b56d8c8

Browse files
authored
Unrolled build for #147638
Rollup merge of #147638 - alessandrod:indirect-res, r=wesleywiser bpf: return results larger than one register indirectly Fixes triggering the "only small returns supported" error in the BPF target.
2 parents 844264a + 056c2da commit b56d8c8

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

compiler/rustc_target/src/callconv/bpf.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ pub(crate) fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
2929
classify_arg(arg);
3030
}
3131
}
32+
33+
pub(crate) fn compute_rust_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
34+
if !fn_abi.ret.is_ignore() {
35+
classify_ret(&mut fn_abi.ret);
36+
}
37+
}

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
715715
"riscv32" | "riscv64" => riscv::compute_rust_abi_info(cx, self),
716716
"loongarch32" | "loongarch64" => loongarch::compute_rust_abi_info(cx, self),
717717
"aarch64" => aarch64::compute_rust_abi_info(cx, self),
718+
"bpf" => bpf::compute_rust_abi_info(self),
718719
_ => {}
719720
};
720721

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Checks that results larger than one register are returned indirectly
2+
//@ only-bpf
3+
//@ needs-llvm-components: bpf
4+
//@ compile-flags: --target bpfel-unknown-none
5+
6+
#![no_std]
7+
#![no_main]
8+
9+
#[no_mangle]
10+
fn outer(a: u64) -> u64 {
11+
let v = match inner_res(a) {
12+
Ok(v) => v,
13+
Err(()) => 0,
14+
};
15+
16+
inner_big(v).a[0] as u64
17+
}
18+
19+
// CHECK-LABEL: define {{.*}} @_ZN{{.*}}inner_res{{.*}}E(
20+
// CHECK-SAME: ptr{{[^,]*}},
21+
// CHECK-SAME: i64{{[^)]*}}
22+
#[inline(never)]
23+
fn inner_res(a: u64) -> Result<u64, ()> {
24+
if a == 0 { Err(()) } else { Ok(a + 1) }
25+
}
26+
27+
struct Big {
28+
a: [u16; 32],
29+
b: u64,
30+
}
31+
32+
// CHECK-LABEL: define {{.*}} @_ZN{{.*}}inner_big{{.*}}E(
33+
// CHECK-SAME: ptr{{[^,]*}},
34+
// CHECK-SAME: i64{{[^)]*}}
35+
#[inline(never)]
36+
fn inner_big(a: u64) -> Big {
37+
Big { a: [a as u16; 32], b: 42 }
38+
}
39+
40+
#[panic_handler]
41+
fn panic(_info: &core::panic::PanicInfo) -> ! {
42+
loop {}
43+
}

0 commit comments

Comments
 (0)