From 860285224176b0d300541acb471ea06bb202b279 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sun, 6 Mar 2022 04:49:02 +0800 Subject: [PATCH] nac3core: use signed extension to convert i32 to i64 --- nac3core/src/toplevel/builtins.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index f4a99ae3..0007286c 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -255,9 +255,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { let arg_ty = fun.0.args[0].ty; let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?; Ok( - if ctx.unifier.unioned(arg_ty, boolean) - || ctx.unifier.unioned(arg_ty, int32) - { + if ctx.unifier.unioned(arg_ty, boolean) { Some( ctx.builder .build_int_z_extend( @@ -267,6 +265,16 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { ) .into(), ) + } else if ctx.unifier.unioned(arg_ty, int32) { + Some( + ctx.builder + .build_int_s_extend( + arg.into_int_value(), + ctx.ctx.i64_type(), + "sext", + ) + .into(), + ) } else if ctx.unifier.unioned(arg_ty, int64) { Some(arg) } else if ctx.unifier.unioned(arg_ty, float) {