From dbd44658ff2d392451ea4f3a38ca4bd26da34314 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 26 May 2023 13:16:33 -0700 Subject: [PATCH] wasm backend: emit a TODO error rather than miscompile --- src/arch/wasm/CodeGen.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 11b7f65946..5b5c8b7b09 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -3090,9 +3090,14 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue { }, .ErrorUnion => { const error_type = ty.errorUnionSet(); - const is_pl = val.errorUnionIsPayload(); - const err_val = if (!is_pl) val else Value.initTag(.zero); - return func.lowerConstant(err_val, error_type); + const payload_type = ty.errorUnionPayload(); + if (!payload_type.hasRuntimeBitsIgnoreComptime()) { + // We use the error type directly as the type. + const is_pl = val.errorUnionIsPayload(); + const err_val = if (!is_pl) val else Value.initTag(.zero); + return func.lowerConstant(err_val, error_type); + } + return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{}); }, .Optional => if (ty.optionalReprIsPayload()) { var buf: Type.Payload.ElemType = undefined;