Skip to content

Commit

Permalink
fix bug in use of alignment in free for tag unions
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev authored and bhansconnect committed Sep 28, 2023
1 parent b6218a1 commit 35e56c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crates/compiler/builtins/bitcode/src/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ pub fn freeDataPtrC(
const masked_ptr = ptr & ~tag_mask;

const isizes: [*]isize = @as([*]isize, @ptrFromInt(masked_ptr));
const offset = @max(1, @divFloor(alignment, @sizeOf(usize)));

return freeRcPtrC(isizes - 1, alignment);
return freeRcPtrC(isizes - offset, alignment);
}

pub fn freeRcPtrC(
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/gen_llvm/src/llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ pub(crate) fn build_exp_stmt<'a, 'ctx>(
Free(symbol) => {
// unconditionally deallocate the symbol
let (value, layout) = scope.load_symbol_and_layout(symbol);
let alignment = layout_interner.alignment_bytes(layout);
let alignment = layout_interner.allocation_alignment_bytes(layout);

debug_assert!(value.is_pointer_value());
let value = value.into_pointer_value();
Expand Down

0 comments on commit 35e56c3

Please sign in to comment.