From 71c3a65a31f7b5ce8a51b26926b0e468e659bbbc Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 29 Aug 2024 19:14:01 +0800 Subject: [PATCH] [core] codegen/stmt: Fix obtaining return type of sret functions --- nac3core/src/codegen/stmt.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 360f81cd..1def3a4f 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -1676,7 +1676,12 @@ pub fn gen_return( // Remap boolean return type into i1 let value = value.map(|ret_val| { - let expected_ty = func.get_type().get_return_type().unwrap(); + // The "return type" of a sret function is in the first parameter + let expected_ty = if ctx.need_sret { + func.get_type().get_param_types()[0] + } else { + func.get_type().get_return_type().unwrap() + }; if matches!(expected_ty, BasicTypeEnum::IntType(ty) if ty.get_bit_width() == 1) { generator.bool_to_i1(ctx, ret_val.into_int_value()).into()