From 2d87f946acc373891f72dda28d4464c7ab439d68 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 12 Mar 2024 12:22:45 -0300 Subject: [PATCH] Fix ABI bug --- compiler/rustc_target/src/abi/call/sbf.rs | 32 +++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_target/src/abi/call/sbf.rs b/compiler/rustc_target/src/abi/call/sbf.rs index d762c7fae9734..9c35e9a54bbdc 100644 --- a/compiler/rustc_target/src/abi/call/sbf.rs +++ b/compiler/rustc_target/src/abi/call/sbf.rs @@ -1,23 +1,33 @@ // see https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/BPF/BPFCallingConv.td -use crate::abi::call::{ArgAbi, FnAbi}; +use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform}; fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { - if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 { - if ret.layout.size.bits() != 128 { - ret.make_indirect(); - } - } else { + let size = ret.layout.size; + let bits = size.bits(); + if !ret.layout.is_aggregate() && bits <= 64 { ret.extend_integer_width_to(64); + return; + } + + if bits <= 128 { + ret.cast_to(Uniform {unit: Reg::i64(), total: size}); + } else { + ret.make_indirect(); } } fn classify_arg(arg: &mut ArgAbi<'_, Ty>) { - if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 { - if arg.layout.size.bits() != 128 { - arg.make_indirect(); - } - } else { + let size = arg.layout.size; + let bits = size.bits(); + if !arg.layout.is_aggregate() && bits <= 64 { arg.extend_integer_width_to(64); + return; + } + + if bits <= 128 { + arg.cast_to(Uniform {unit: Reg::i64(), total: size}); + } else { + arg.make_indirect(); } }