(
&mut self,
sig: &ir::Signature,
flags: &settings::Flags,
)
| 878 | } |
| 879 | |
| 880 | pub fn from_func_sig<M: ABIMachineSpec>( |
| 881 | &mut self, |
| 882 | sig: &ir::Signature, |
| 883 | flags: &settings::Flags, |
| 884 | ) -> CodegenResult<SigData> { |
| 885 | // Keep in sync with ensure_struct_return_ptr_is_returned |
| 886 | if sig.uses_special_return(ArgumentPurpose::StructReturn) { |
| 887 | panic!("Explicit StructReturn return value not allowed: {sig:?}") |
| 888 | } |
| 889 | let tmp; |
| 890 | let returns = if let Some(struct_ret_index) = |
| 891 | sig.special_param_index(ArgumentPurpose::StructReturn) |
| 892 | { |
| 893 | if !sig.returns.is_empty() { |
| 894 | panic!("No return values are allowed when using StructReturn: {sig:?}"); |
| 895 | } |
| 896 | tmp = [sig.params[struct_ret_index]]; |
| 897 | &tmp |
| 898 | } else { |
| 899 | sig.returns.as_slice() |
| 900 | }; |
| 901 | |
| 902 | // Compute args and retvals from signature. Handle retvals first, |
| 903 | // because we may need to add a return-area arg to the args. |
| 904 | |
| 905 | // NOTE: We rely on the order of the args (rets -> args) inserted to compute the offsets in |
| 906 | // `SigSet::args()` and `SigSet::rets()`. Therefore, we cannot change the two |
| 907 | // compute_arg_locs order. |
| 908 | let (sized_stack_ret_space, _) = M::compute_arg_locs( |
| 909 | sig.call_conv, |
| 910 | flags, |
| 911 | &returns, |
| 912 | ArgsOrRets::Rets, |
| 913 | /* extra ret-area ptr = */ false, |
| 914 | ArgsAccumulator::new(&mut self.abi_args), |
| 915 | )?; |
| 916 | if !flags.enable_multi_ret_implicit_sret() { |
| 917 | assert_eq!(sized_stack_ret_space, 0); |
| 918 | } |
| 919 | let rets_end = u32::try_from(self.abi_args.len()).unwrap(); |
| 920 | |
| 921 | // To avoid overflow issues, limit the return size to something reasonable. |
| 922 | if sized_stack_ret_space > M::STACK_ARG_RET_SIZE_LIMIT { |
| 923 | return Err(CodegenError::ImplLimitExceeded); |
| 924 | } |
| 925 | |
| 926 | let need_stack_return_area = sized_stack_ret_space > 0; |
| 927 | if need_stack_return_area { |
| 928 | assert!(!sig.uses_special_param(ir::ArgumentPurpose::StructReturn)); |
| 929 | } |
| 930 | |
| 931 | let (sized_stack_arg_space, stack_ret_arg) = M::compute_arg_locs( |
| 932 | sig.call_conv, |
| 933 | flags, |
| 934 | &sig.params, |
| 935 | ArgsOrRets::Args, |
| 936 | need_stack_return_area, |
| 937 | ArgsAccumulator::new(&mut self.abi_args), |
nothing calls this directly
no test coverage detected