forked from M-Labs/nac3
1
0
Fork 0

core/model: fix Ptr::copy_from int types

This commit is contained in:
lyken 2024-08-23 16:23:16 +08:00
parent 7e45c104be
commit 9e005e9b07
No known key found for this signature in database
GPG Key ID: 3BD5FC6AC8325DD8
1 changed files with 9 additions and 1 deletions

View File

@ -175,8 +175,16 @@ impl<'ctx, Item: Model<'ctx>> Instance<'ctx, Ptr<Item>> {
source: Self,
num_items: IntValue<'ctx>,
) {
let llvm_usize = generator.get_size_type(ctx.ctx);
// Force extend `num_items` and `itemsize` so their types would match.
let itemsize = self.model.sizeof(generator, ctx.ctx);
let totalsize = ctx.builder.build_int_mul(itemsize, num_items, "totalsize").unwrap(); // TODO: Int types may not match.
let itemsize =
ctx.builder.build_int_z_extend_or_bit_cast(itemsize, llvm_usize, "").unwrap();
let num_items =
ctx.builder.build_int_z_extend_or_bit_cast(num_items, llvm_usize, "").unwrap();
let totalsize = ctx.builder.build_int_mul(itemsize, num_items, "totalsize").unwrap();
let is_volatile = ctx.ctx.bool_type().const_zero(); // is_volatile = false
call_memcpy_generic(ctx, self.value, source.value, totalsize, is_volatile);