Commit 6c06944b59

Luuk de Gram <luuk@degram.dev>
2023-05-10 17:04:55
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.
1 parent 43e8902
Changed files (2)
lib
src
arch
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");
     }
 
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);
     }