mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Make sure casting to unsigned types performs zero-extension
Closes #2696
This commit is contained in:
parent
a412cddec2
commit
a90bba3d1d
9 changed files with 67 additions and 16 deletions
|
@ -240,8 +240,12 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
|
|||
tag_value.into(),
|
||||
);
|
||||
|
||||
env.builder
|
||||
.build_int_cast(tag_id_i64, env.context.i16_type(), "to_i16")
|
||||
env.builder.build_int_cast_sign_flag(
|
||||
tag_id_i64,
|
||||
env.context.i16_type(),
|
||||
true,
|
||||
"to_i16",
|
||||
)
|
||||
};
|
||||
|
||||
let answer = env.builder.build_int_compare(
|
||||
|
|
|
@ -1824,7 +1824,7 @@ pub fn tag_pointer_read_tag_id<'a, 'ctx, 'env>(
|
|||
let masked = env.builder.build_and(as_int, mask_intval, "mask");
|
||||
|
||||
env.builder
|
||||
.build_int_cast(masked, env.context.i8_type(), "to_u8")
|
||||
.build_int_cast_sign_flag(masked, env.context.i8_type(), false, "to_u8")
|
||||
}
|
||||
|
||||
pub fn tag_pointer_clear_tag_id<'a, 'ctx, 'env>(
|
||||
|
@ -5916,8 +5916,11 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
let arg = load_symbol(scope, &args[0]).into_int_value();
|
||||
|
||||
let to = basic_type_from_layout(env, layout).into_int_type();
|
||||
let to_signed = intwidth_from_layout(*layout).is_signed();
|
||||
|
||||
env.builder.build_int_cast(arg, to, "inc_cast").into()
|
||||
env.builder
|
||||
.build_int_cast_sign_flag(arg, to, to_signed, "inc_cast")
|
||||
.into()
|
||||
}
|
||||
Eq => {
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
@ -7021,7 +7024,12 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
|
|||
let target_int_type = convert::int_type_from_int_width(env, target_int_width);
|
||||
let target_int_val: BasicValueEnum<'ctx> = env
|
||||
.builder
|
||||
.build_int_cast(arg, target_int_type, "int_cast")
|
||||
.build_int_cast_sign_flag(
|
||||
arg,
|
||||
target_int_type,
|
||||
target_int_width.is_signed(),
|
||||
"int_cast",
|
||||
)
|
||||
.into();
|
||||
|
||||
let return_type =
|
||||
|
|
|
@ -65,7 +65,12 @@ pub fn dict_len<'a, 'ctx, 'env>(
|
|||
);
|
||||
|
||||
env.builder
|
||||
.build_int_cast(length_i64.into_int_value(), env.ptr_int(), "to_usize")
|
||||
.build_int_cast_sign_flag(
|
||||
length_i64.into_int_value(),
|
||||
env.ptr_int(),
|
||||
false,
|
||||
"to_usize",
|
||||
)
|
||||
.into()
|
||||
}
|
||||
_ => unreachable!("Invalid layout given to Dict.len : {:?}", dict_layout),
|
||||
|
|
|
@ -179,7 +179,7 @@ pub fn str_number_of_bytes<'a, 'ctx, 'env>(
|
|||
|
||||
// cast to the appropriate usize of the current build
|
||||
env.builder
|
||||
.build_int_cast(length, env.ptr_int(), "len_as_usize")
|
||||
.build_int_cast_sign_flag(length, env.ptr_int(), false, "len_as_usize")
|
||||
}
|
||||
|
||||
/// Str.startsWith : Str, Str -> Bool
|
||||
|
|
|
@ -1101,8 +1101,10 @@ fn build_tag_eq_help<'a, 'ctx, 'env>(
|
|||
let i8_type = env.context.i8_type();
|
||||
|
||||
let sum = env.builder.build_int_add(
|
||||
env.builder.build_int_cast(is_null_1, i8_type, "to_u8"),
|
||||
env.builder.build_int_cast(is_null_2, i8_type, "to_u8"),
|
||||
env.builder
|
||||
.build_int_cast_sign_flag(is_null_1, i8_type, false, "to_u8"),
|
||||
env.builder
|
||||
.build_int_cast_sign_flag(is_null_2, i8_type, false, "to_u8"),
|
||||
"sum_is_null",
|
||||
);
|
||||
|
||||
|
|
|
@ -1699,9 +1699,9 @@ fn modify_refcount_union_help<'a, 'ctx, 'env>(
|
|||
.build_load(tag_id_ptr, "load_tag_id")
|
||||
.into_int_value();
|
||||
|
||||
let tag_id_u8 = env
|
||||
.builder
|
||||
.build_int_cast(tag_id, env.context.i8_type(), "tag_id_u8");
|
||||
let tag_id_u8 =
|
||||
env.builder
|
||||
.build_int_cast_sign_flag(tag_id, env.context.i8_type(), false, "tag_id_u8");
|
||||
|
||||
// next, make a jump table for all possible values of the tag_id
|
||||
let mut cases = Vec::with_capacity_in(tags.len(), env.arena);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue