authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-26 13:21:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:55-07:00
log63dc0447fc4654324ef8efcfa65849f7ef682531
tree1e2045c4d4a25174a48baf8c71fb57f55aae8d54
parentabded5cbb0b8c0b383b2362a2b89447528fe536c

wasm: fix error union constant lowering


1 files changed, 16 insertions(+), 5 deletions(-)

src/arch/wasm/CodeGen.zig+16-5
...@@ -3183,15 +3183,26 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {...@@ -3183,15 +3183,26 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
3183 const kv = try mod.getErrorValue(name);3183 const kv = try mod.getErrorValue(name);
3184 return WValue{ .imm32 = kv.value };3184 return WValue{ .imm32 = kv.value };
3185 },3185 },
3186 .error_union => {3186 .error_union => |error_union| {
3187 const error_type = ty.errorUnionSet(mod);3187 const err_tv: TypedValue = switch (error_union.val) {
3188 .err_name => |err_name| .{
3189 .ty = ty.errorUnionSet(mod),
3190 .val = (try mod.intern(.{ .err = .{
3191 .ty = ty.errorUnionSet(mod).toIntern(),
3192 .name = err_name,
3193 } })).toValue(),
3194 },
3195 .payload => .{
3196 .ty = Type.err_int,
3197 .val = try mod.intValue(Type.err_int, 0),
3198 },
3199 };
3188 const payload_type = ty.errorUnionPayload(mod);3200 const payload_type = ty.errorUnionPayload(mod);
3189 if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {3201 if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
3190 // We use the error type directly as the type.3202 // We use the error type directly as the type.
3191 const is_pl = val.errorUnionIsPayload(mod);3203 return func.lowerConstant(err_tv.val, err_tv.ty);
3192 const err_val = if (!is_pl) val else try mod.intValue(error_type, 0);
3193 return func.lowerConstant(err_val, error_type);
3194 }3204 }
3205
3195 return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});3206 return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
3196 },3207 },
3197 .enum_tag => |enum_tag| {3208 .enum_tag => |enum_tag| {