Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_target/src/callconv/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use crate::callconv::{ArgAbi, FnAbi};
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 {
ret.make_indirect();
} else {
ret.extend_integer_width_to(32);
}
}

Expand Down Expand Up @@ -45,5 +43,6 @@ where
pub(crate) fn compute_rust_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
if !fn_abi.ret.is_ignore() {
classify_ret(&mut fn_abi.ret);
fn_abi.ret.extend_integer_width_to(32);

@bjorn3 bjorn3 Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary. We can do whatever we want for the rust ABI and it probably doesn't matter for performance if the C ABI doesn't do it either.

View changes since the review

}
}
50 changes: 50 additions & 0 deletions tests/codegen-llvm/bpf-abi-extern-narrow-ret.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//@ add-minicore
//@ needs-llvm-components: bpf
//@ compile-flags: --target bpfel-unknown-none

#![feature(no_core)]
#![crate_type = "lib"]
#![no_core]

extern crate minicore;
use minicore::*;

unsafe extern "C" {
fn c_ret_u8() -> u8;
fn c_ret_u16() -> u16;
fn c_ret_i8() -> i8;
fn c_ret_i16() -> i16;
}

// CHECK-LABEL: define {{.*}} @observe_u8(
// CHECK: call noundef i8 @c_ret_u8()
#[unsafe(no_mangle)]
pub unsafe extern "C" fn observe_u8() -> u64 {
c_ret_u8() as u64
}

// CHECK-LABEL: define {{.*}} @observe_u16(
// CHECK: call noundef i16 @c_ret_u16()
#[unsafe(no_mangle)]
pub unsafe extern "C" fn observe_u16() -> u64 {
c_ret_u16() as u64
}

// CHECK-LABEL: define {{.*}} @observe_i8(
// CHECK: call noundef i8 @c_ret_i8()
#[unsafe(no_mangle)]
pub unsafe extern "C" fn observe_i8() -> i64 {
c_ret_i8() as i64
}

// CHECK-LABEL: define {{.*}} @observe_i16(
// CHECK: call noundef i16 @c_ret_i16()
#[unsafe(no_mangle)]
pub unsafe extern "C" fn observe_i16() -> i64 {
c_ret_i16() as i64
}

// CHECK: declare noundef i8 @c_ret_u8()
// CHECK: declare noundef i16 @c_ret_u16()
// CHECK: declare noundef i8 @c_ret_i8()
// CHECK: declare noundef i16 @c_ret_i16()
Loading