authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-10 17:04:55+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-05-19 20:19:00+02:00
log6c06944b5958e2b624004e986deee8e52c765e6e
treee5fe5776ad1cacb85125f82c7d07973688a58fb4
parent43e89026ac90ee6e8c2cb066068eb8ff10352ac1
signaturelock-open Commit is signed but in an unrecognized format.

wasm: fix return `ret_load` with zero-size type

When we have a `ret_load` instruction with a zero-sized type which was not an error, we would not emit any instruction. This resulted in no `return` instruction and also not correctly resetting the global stack_pointer. This commit also enables the regular test runner for the WebAssembly backend.

2 files changed, 4 insertions(+), 9 deletions(-)

lib/test_runner.zig+1-3
...@@ -12,9 +12,7 @@ var cmdline_buffer: [4096]u8 = undefined;...@@ -12,9 +12,7 @@ var cmdline_buffer: [4096]u8 = undefined;
12var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);12var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);
1313
14pub fn main() void {14pub fn main() void {
15 if (builtin.zig_backend == .stage2_wasm or15 if (builtin.zig_backend == .stage2_aarch64) {
16 builtin.zig_backend == .stage2_aarch64)
17 {
18 return mainSimple() catch @panic("test failure");16 return mainSimple() catch @panic("test failure");
19 }17 }
2018
src/arch/wasm/CodeGen.zig+3-6
...@@ -2122,16 +2122,13 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2122,16 +2122,13 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2122 const un_op = func.air.instructions.items(.data)[inst].un_op;2122 const un_op = func.air.instructions.items(.data)[inst].un_op;
2123 const operand = try func.resolveInst(un_op);2123 const operand = try func.resolveInst(un_op);
2124 const ret_ty = func.air.typeOf(un_op).childType();2124 const ret_ty = func.air.typeOf(un_op).childType();
2125
2126 const fn_info = func.decl.ty.fnInfo();
2125 if (!ret_ty.hasRuntimeBitsIgnoreComptime()) {2127 if (!ret_ty.hasRuntimeBitsIgnoreComptime()) {
2126 if (ret_ty.isError()) {2128 if (ret_ty.isError()) {
2127 try func.addImm32(0);2129 try func.addImm32(0);
2128 } else {
2129 return func.finishAir(inst, .none, &.{});
2130 }2130 }
2131 }2131 } else if (!firstParamSRet(fn_info.cc, fn_info.return_type, func.target)) {
2132
2133 const fn_info = func.decl.ty.fnInfo();
2134 if (!firstParamSRet(fn_info.cc, fn_info.return_type, func.target)) {
2135 // leave on the stack2132 // leave on the stack
2136 _ = try func.load(operand, ret_ty, 0);2133 _ = try func.load(operand, ret_ty, 0);
2137 }2134 }