From 6c06944b5958e2b624004e986deee8e52c765e6e Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Wed, 10 May 2023 17:04:55 +0200 Subject: [PATCH] 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. --- lib/test_runner.zig | 4 +--- src/arch/wasm/CodeGen.zig | 9 +++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/test_runner.zig b/lib/test_runner.zig index 8e29d90433..33fe547b57 100644 --- a/lib/test_runner.zig +++ b/lib/test_runner.zig @@ -12,9 +12,7 @@ var cmdline_buffer: [4096]u8 = undefined; var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer); pub fn main() void { - if (builtin.zig_backend == .stage2_wasm or - builtin.zig_backend == .stage2_aarch64) - { + if (builtin.zig_backend == .stage2_aarch64) { return mainSimple() catch @panic("test failure"); } diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 6ad22de43c..73db9221fa 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2122,16 +2122,13 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const un_op = func.air.instructions.items(.data)[inst].un_op; const operand = try func.resolveInst(un_op); const ret_ty = func.air.typeOf(un_op).childType(); + + const fn_info = func.decl.ty.fnInfo(); if (!ret_ty.hasRuntimeBitsIgnoreComptime()) { if (ret_ty.isError()) { try func.addImm32(0); - } else { - return func.finishAir(inst, .none, &.{}); } - } - - const fn_info = func.decl.ty.fnInfo(); - if (!firstParamSRet(fn_info.cc, fn_info.return_type, func.target)) { + } else if (!firstParamSRet(fn_info.cc, fn_info.return_type, func.target)) { // leave on the stack _ = try func.load(operand, ret_ty, 0); }