Skip to content

wasm - fix bitcasting between arrays and scalar types #17819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/test_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ var cmdline_buffer: [4096]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);

pub fn main() void {
if (builtin.zig_backend == .stage2_aarch64 or
builtin.zig_backend == .stage2_wasm)
{
if (builtin.zig_backend == .stage2_aarch64) {
return mainSimple() catch @panic("test failure");
}

Expand Down
10 changes: 10 additions & 0 deletions src/arch/wasm/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3814,6 +3814,16 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const bitcast_result = try func.bitcast(wanted_ty, given_ty, operand);
break :result try bitcast_result.toLocal(func, wanted_ty);
}
const mod = func.bin_file.base.options.module.?;
if (isByRef(given_ty, mod) and !isByRef(wanted_ty, mod)) {
const loaded_memory = try func.load(operand, wanted_ty, 0);
break :result try loaded_memory.toLocal(func, wanted_ty);
}
if (!isByRef(given_ty, mod) and isByRef(wanted_ty, mod)) {
const stack_memory = try func.allocStack(wanted_ty);
try func.store(stack_memory, operand, given_ty, 0);
break :result stack_memory;
}
break :result func.reuseOperand(ty_op.operand, operand);
};
func.finishAir(inst, result, &.{ty_op.operand});
Expand Down
1 change: 0 additions & 1 deletion test/behavior/bugs/1851.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ test "allocation and looping over 3-byte integer" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;

if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
return error.SkipZigTest; // TODO
Expand Down
1 change: 0 additions & 1 deletion test/behavior/struct.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,6 @@ test "under-aligned struct field" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;

const U = extern union {
fd: i32,
Expand Down