1
0
forked from M-Labs/nac3

[meta] Remove all mentions of build_int_cast

build_int_cast performs signed extension or truncation depending on the
source and target int lengths. This is usually not what we want - We
want zero-extension instead.

Replace all instances of build_int_cast with
build_int_z_extend_or_bit_cast to fix this issue.
This commit is contained in:
David Mak 2024-11-29 17:19:43 +08:00
parent d484d44d95
commit 536ed2146c
2 changed files with 8 additions and 5 deletions

View File

@ -800,7 +800,8 @@ fn ndarray_from_ndlist_impl<'ctx, G: CodeGenerator + ?Sized>(
_ => { _ => {
let lst_len = src_lst.load_size(ctx, None); let lst_len = src_lst.load_size(ctx, None);
let sizeof_elem = dst_arr.get_type().element_type().size_of().unwrap(); let sizeof_elem = dst_arr.get_type().element_type().size_of().unwrap();
let sizeof_elem = ctx.builder.build_int_cast(sizeof_elem, llvm_usize, "").unwrap(); let sizeof_elem =
ctx.builder.build_int_z_extend_or_bit_cast(sizeof_elem, llvm_usize, "").unwrap();
let cpy_len = ctx let cpy_len = ctx
.builder .builder
@ -1207,7 +1208,7 @@ fn ndarray_sliced_copyto_impl<'ctx, G: CodeGenerator + ?Sized>(
.build_int_mul( .build_int_mul(
src_data_offset, src_data_offset,
ctx.builder ctx.builder
.build_int_cast(sizeof_elem, src_data_offset.get_type(), "") .build_int_z_extend_or_bit_cast(sizeof_elem, src_data_offset.get_type(), "")
.unwrap(), .unwrap(),
"", "",
) )
@ -1220,7 +1221,7 @@ fn ndarray_sliced_copyto_impl<'ctx, G: CodeGenerator + ?Sized>(
.build_int_mul( .build_int_mul(
dst_data_offset, dst_data_offset,
ctx.builder ctx.builder
.build_int_cast(sizeof_elem, dst_data_offset.get_type(), "") .build_int_z_extend_or_bit_cast(sizeof_elem, dst_data_offset.get_type(), "")
.unwrap(), .unwrap(),
"", "",
) )

View File

@ -131,8 +131,10 @@ impl<'ctx> NDArrayValue<'ctx> {
elem_ty: BasicTypeEnum<'ctx>, elem_ty: BasicTypeEnum<'ctx>,
size: IntValue<'ctx>, size: IntValue<'ctx>,
) { ) {
let itemsize = let itemsize = ctx
ctx.builder.build_int_cast(elem_ty.size_of().unwrap(), size.get_type(), "").unwrap(); .builder
.build_int_z_extend_or_bit_cast(elem_ty.size_of().unwrap(), size.get_type(), "")
.unwrap();
let nbytes = ctx.builder.build_int_mul(size, itemsize, "").unwrap(); let nbytes = ctx.builder.build_int_mul(size, itemsize, "").unwrap();
// TODO: What about alignment? // TODO: What about alignment?