correct parameter offset

This commit is contained in:
Brendan Hansknecht 2022-07-17 07:32:16 -07:00
parent 865e789966
commit 837ce38066
No known key found for this signature in database
GPG key ID: A2E3B0B6E483038E

View file

@ -3910,8 +3910,15 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
Attribute::get_named_enum_kind_id("nonnull"),
arg_type.into_pointer_type().get_element_type(),
);
c_function.add_attribute(AttributeLoc::Param((i + 1) as u32), byval);
c_function.add_attribute(AttributeLoc::Param((i + 1) as u32), nonnull);
// C return pointer goes at the beginning of params, and we must skip it if it exists.
let param_index = (i
+ (if matches!(cc_return, CCReturn::ByPointer) {
1
} else {
0
})) as u32;
c_function.add_attribute(AttributeLoc::Param(param_index), byval);
c_function.add_attribute(AttributeLoc::Param(param_index), nonnull);
// bitcast the ptr
let fastcc_ptr = env
.builder