mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
fix alignment bug in list literals
This commit is contained in:
parent
44777c5cac
commit
3c8dbce72e
3 changed files with 24 additions and 7 deletions
|
@ -221,13 +221,14 @@ pub fn decrefDataPtrC(
|
|||
) callconv(.C) void {
|
||||
var bytes = bytes_or_null orelse return;
|
||||
|
||||
const ptr = @ptrToInt(bytes);
|
||||
const data_ptr = @ptrToInt(bytes);
|
||||
const tag_mask: usize = if (@sizeOf(usize) == 8) 0b111 else 0b11;
|
||||
const masked_ptr = ptr & ~tag_mask;
|
||||
const unmasked_ptr = data_ptr & ~tag_mask;
|
||||
|
||||
const isizes: [*]isize = @intToPtr([*]isize, masked_ptr);
|
||||
const isizes: [*]isize = @intToPtr([*]isize, unmasked_ptr);
|
||||
const rc_ptr = isizes - 1;
|
||||
|
||||
return decrefRcPtrC(isizes - 1, alignment);
|
||||
return decrefRcPtrC(rc_ptr, alignment);
|
||||
}
|
||||
|
||||
pub fn increfDataPtrC(
|
||||
|
@ -435,7 +436,7 @@ pub fn allocateWithRefcount(
|
|||
var new_bytes: [*]u8 = alloc(length, alignment) orelse unreachable;
|
||||
|
||||
if (DEBUG_ALLOC and builtin.target.cpu.arch != .wasm32) {
|
||||
std.debug.print("+ allocated {*}\n", .{new_bytes});
|
||||
std.debug.print("+ allocated {*} ({} bytes with alignment {})\n", .{ new_bytes, data_bytes, element_alignment });
|
||||
}
|
||||
|
||||
const data_ptr = new_bytes + alignment;
|
||||
|
|
|
@ -3104,7 +3104,7 @@ impl<
|
|||
|
||||
// Load allocation alignment (u32)
|
||||
let element_alignment_symbol = Symbol::DEV_TMP2;
|
||||
self.load_layout_alignment(Layout::U32, element_alignment_symbol);
|
||||
self.load_layout_alignment(*element_in_layout, element_alignment_symbol);
|
||||
|
||||
let allocation_symbol = self.debug_symbol("list_allocation");
|
||||
self.allocate_with_refcount(
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::helpers::with_larger_debug_stack;
|
|||
#[allow(unused_imports)]
|
||||
use indoc::indoc;
|
||||
#[allow(unused_imports)]
|
||||
use roc_std::{RocList, RocResult, RocStr};
|
||||
use roc_std::{RocDec, RocList, RocResult, RocStr};
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
|
@ -85,6 +85,16 @@ fn bool_list_literal() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn dec_list_literal() {
|
||||
assert_evals_to!(
|
||||
"[1.0, 2.0]",
|
||||
RocList::from_slice(&[RocDec::from(1), RocDec::from(2)]),
|
||||
RocList<RocDec>
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn bool_list_concat() {
|
||||
|
@ -2799,6 +2809,12 @@ fn list_sum() {
|
|||
assert_evals_to!("List.sum [1.1f64, 2.2, 3.3]", 6.6, f64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn list_sum_dec() {
|
||||
assert_evals_to!("List.sum [1.0dec, 2.0]", RocDec::from(3), RocDec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn list_product() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue