Skip to content

Commit 125fb0f

Browse files
committed
bpf: return results larger than one register indirectly
Fixes triggering the "only small returns supported" error in the BPF target.
1 parent 41a79f1 commit 125fb0f

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

compiler/rustc_target/src/callconv/bpf.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ 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+
compute_abi_info(fn_abi);
35+
}

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

0 commit comments

Comments
 (0)