From c6b9aefe00bbb2d1a2aff3d27c0e59c3fc621d3f Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 3 Nov 2023 15:55:16 +0800 Subject: [PATCH] core: Fix int32-to-uint64 conversion This conversion should be sign-extended. --- nac3core/src/toplevel/builtins.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index 8f6e32df..3f7040be 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -712,13 +712,16 @@ 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, arg_ty)?; - let res = if ctx.unifier.unioned(arg_ty, int32) - || ctx.unifier.unioned(arg_ty, uint32) + let res = if ctx.unifier.unioned(arg_ty, uint32) || ctx.unifier.unioned(arg_ty, boolean) { ctx.builder .build_int_z_extend(arg.into_int_value(), ctx.ctx.i64_type(), "zext") .into() + } else if ctx.unifier.unioned(arg_ty, int32) { + ctx.builder + .build_int_s_extend(arg.into_int_value(), ctx.ctx.i64_type(), "sext") + .into() } else if ctx.unifier.unioned(arg_ty, int64) || ctx.unifier.unioned(arg_ty, uint64) {