authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-17 20:06:41+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-17 20:28:43+02:00
logfc066992d912186da08ac9250b3772103aafbbe8
tree3b48356f1ee0a2e43e59618eaa05abf9feb8cff9
parent3b2c4211027c235e3bc38043be99fc5be5e870e1

Sema: do not create slices with undefined pointers

The undef pointer ended up being zero on wasm32.

1 files changed, 6 insertions(+), 1 deletions(-)

src/Sema.zig+6-1
...@@ -24822,8 +24822,13 @@ fn coerceExtra(...@@ -24822,8 +24822,13 @@ fn coerceExtra(
24822 // empty tuple to zero-length slice24822 // empty tuple to zero-length slice
24823 // note that this allows coercing to a mutable slice.24823 // note that this allows coercing to a mutable slice.
24824 if (inst_child_ty.structFieldCount() == 0) {24824 if (inst_child_ty.structFieldCount() == 0) {
24825 // Optional slice is represented with a null pointer so
24826 // we use a dummy pointer value with the required alignment.
24825 const slice_val = try Value.Tag.slice.create(sema.arena, .{24827 const slice_val = try Value.Tag.slice.create(sema.arena, .{
24826 .ptr = Value.undef,24828 .ptr = if (dest_info.@"align" != 0)
24829 try Value.Tag.int_u64.create(sema.arena, dest_info.@"align")
24830 else
24831 try inst_child_ty.lazyAbiAlignment(target, sema.arena),
24827 .len = Value.zero,24832 .len = Value.zero,
24828 });24833 });
24829 return sema.addConstant(dest_ty, slice_val);24834 return sema.addConstant(dest_ty, slice_val);