diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index c69965d74a..6dbc9f64cf 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -1067,7 +1067,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>( let value_type = basic_type_from_layout(env.arena, ctx, layout, env.ptr_bytes); let len_type = env.ptr_int(); - let extra_bytes = layout.alignment_bytes(env.ptr_bytes); + let extra_bytes = layout.alignment_bytes(env.ptr_bytes).max(env.ptr_bytes); let ptr = { // number of bytes we will allocated @@ -1097,7 +1097,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>( let index = match extra_bytes { n if n == env.ptr_bytes => 1, n if n == 2 * env.ptr_bytes => 2, - _ => unreachable!("invalid extra_bytes"), + _ => unreachable!("invalid extra_bytes, {}", extra_bytes), }; let index_intvalue = int_type.const_int(index, false); diff --git a/compiler/gen/src/llvm/refcounting.rs b/compiler/gen/src/llvm/refcounting.rs index a8652d41cb..2859c315f3 100644 --- a/compiler/gen/src/llvm/refcounting.rs +++ b/compiler/gen/src/llvm/refcounting.rs @@ -133,7 +133,7 @@ impl<'ctx> PointerToRefcount<'ctx> { let block = env.builder.get_insert_block().expect("to be in a function"); let di_location = env.builder.get_current_debug_location().unwrap(); - let alignment = layout.alignment_bytes(env.ptr_bytes); + let alignment = layout.alignment_bytes(env.ptr_bytes).max(env.ptr_bytes); let fn_name = &format!("decrement_refcounted_ptr_{}", alignment);