Skip to content

Commit

Permalink
Fix more leaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
azteca1998 committed Oct 1, 2024
1 parent 5b0e380 commit 8c8a40f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/libfuncs/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ pub fn build_get<'ctx, 'this>(
// TODO: Support clone-only types (those that are not copy).
valid_block.memcpy(context, location, elem_ptr, target_ptr, elem_size);

// TODO: Drop array values.
valid_block.append_operation(ReallocBindingsMeta::free(context, ptr, location));

valid_block.append_operation(helper.br(0, &[range_check, target_ptr], location));
}

Expand Down
2 changes: 2 additions & 0 deletions src/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ pub(crate) fn build_drop<'ctx, 'this>(
payload_value,
)?;

block.append_operation(scf::r#yield(&[], location));

region
},
location,
Expand Down
11 changes: 7 additions & 4 deletions src/types/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ fn snapshot_take<'ctx, 'this>(
layout.align(),
)?;

entry.store(context, location, ptr, src_value)?;
for (idx, (variant_ty, _)) in variant_tys.iter().copied().enumerate() {
// This unwrap is unreachable because of the first check in this function.
if let Some(snapshot_take) = metadata
Expand All @@ -568,7 +569,6 @@ fn snapshot_take<'ctx, 'this>(
let block = helper.append_block(Block::new(&[]));
variant_blocks.insert(idx, block);

block.store(context, location, ptr, src_value)?;
let value = block.load(
context,
location,
Expand All @@ -582,13 +582,16 @@ fn snapshot_take<'ctx, 'this>(
)?;

let value = block.insert_value(context, location, value, payload, 1)?;
block.store(context, location, ptr, value)?;
let value = block.load(context, location, ptr, src_value.r#type())?;

block.append_operation(cf::br(final_block, &[value], location));
}
}

let default_block = helper.append_block(Block::new(&[]));

let tag_value = entry.extract_value(context, location, src_value, tag_ty, 0)?;
let tag_value = entry.load(context, location, ptr, tag_ty)?;
entry.append_operation(cf::switch(
context,
&variant_blocks.keys().map(|&x| x as i64).collect::<Vec<_>>(),
Expand Down Expand Up @@ -656,11 +659,11 @@ pub(crate) fn build_drop<'ctx, 'this>(
layout.align(),
)?;

block.store(context, location, ptr, value)?;
for (idx, (variant_ty, _)) in variant_tys.iter().copied().enumerate() {
let block = region.append_block(Block::new(&[]));
variant_blocks.push(block);

block.store(context, location, ptr, value)?;
let value = block.load(
context,
location,
Expand Down Expand Up @@ -696,7 +699,7 @@ pub(crate) fn build_drop<'ctx, 'this>(

let default_block = helper.append_block(Block::new(&[]));

let tag_value = entry.extract_value(context, location, value, tag_ty, 0)?;
let tag_value = entry.load(context, location, ptr, tag_ty)?;
block.append_operation(cf::switch(
context,
&(0..info.variants.len())
Expand Down

0 comments on commit 8c8a40f

Please sign in to comment.