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;
1212var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);
1313
1414pub fn main() void {
15 if (builtin.zig_backend == .stage2_wasm or
16 builtin.zig_backend == .stage2_aarch64)
17 {
15 if (builtin.zig_backend == .stage2_aarch64) {
1816 return mainSimple() catch @panic("test failure");
1917 }
2018
src/arch/wasm/CodeGen.zig+3-6
......@@ -2122,16 +2122,13 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21222122 const un_op = func.air.instructions.items(.data)[inst].un_op;
21232123 const operand = try func.resolveInst(un_op);
21242124 const ret_ty = func.air.typeOf(un_op).childType();
2125
2126 const fn_info = func.decl.ty.fnInfo();
21252127 if (!ret_ty.hasRuntimeBitsIgnoreComptime()) {
21262128 if (ret_ty.isError()) {
21272129 try func.addImm32(0);
2128 } else {
2129 return func.finishAir(inst, .none, &.{});
21302130 }
2131 }
2132
2133 const fn_info = func.decl.ty.fnInfo();
2134 if (!firstParamSRet(fn_info.cc, fn_info.return_type, func.target)) {
2131 } else if (!firstParamSRet(fn_info.cc, fn_info.return_type, func.target)) {
21352132 // leave on the stack
21362133 _ = try func.load(operand, ret_ty, 0);
21372134 }