authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2021-12-26 20:52:39+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-01-01 12:58:12+01:00
log726ce85c109a3a17bb6e82caee49e1199570ad5c
tree367b6867cbb4f2067f0e18ce1bdee0e90871e0d5
parentb100e2ec2a06268623b119baf584e059440cb8f0
signaturelock-open Commit is signed but in an unrecognized format.

wasm: Fix storing error. Pass bool.zig behavior tests


2 files changed, 21 insertions(+), 3 deletions(-)

src/arch/wasm/CodeGen.zig+20-3
......@@ -1152,6 +1152,7 @@ fn genInst(self: *Self, inst: Air.Inst.Index) !WValue {
11521152 .block => self.airBlock(inst),
11531153 .breakpoint => self.airBreakpoint(inst),
11541154 .br => self.airBr(inst),
1155 .bool_to_int => self.airBoolToInt(inst),
11551156 .call => self.airCall(inst),
11561157 .cond_br => self.airCondBr(inst),
11571158 .constant => unreachable,
......@@ -1277,6 +1278,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
12771278 const arg_val = self.resolveInst(arg_ref);
12781279
12791280 const arg_ty = self.air.typeOf(arg_ref);
1281 if (!arg_ty.hasCodeGenBits()) continue;
12801282 switch (arg_ty.zigTypeTag()) {
12811283 .Struct, .Pointer, .Optional, .ErrorUnion => {
12821284 // single pointer can be passed directly
......@@ -1396,6 +1398,11 @@ fn store(self: *Self, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErro
13961398 return try self.store(lhs, tag_local, tag_ty, 0);
13971399 },
13981400 .local_with_offset => |with_offset| {
1401 // check if we're storing the payload, or the error
1402 if (with_offset.offset == 0) {
1403 try self.store(lhs, .{ .local = with_offset.local }, tag_ty, 0);
1404 return;
1405 }
13991406 const tag_local = try self.allocLocal(tag_ty);
14001407 try self.addImm32(0);
14011408 try self.addLabel(.local_set, tag_local.local);
......@@ -1449,7 +1456,7 @@ fn store(self: *Self, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErro
14491456 // that is portable across the backend, rather than copying logic.
14501457 const abi_size = if ((ty.isInt() or ty.isAnyFloat()) and ty.abiSize(self.target) <= 8)
14511458 @intCast(u8, ty.abiSize(self.target))
1452 else if (ty.zigTypeTag() == .ErrorSet or ty.zigTypeTag() == .Enum)
1459 else if (ty.zigTypeTag() == .ErrorSet or ty.zigTypeTag() == .Enum or ty.zigTypeTag() == .Bool)
14531460 @intCast(u8, ty.abiSize(self.target))
14541461 else
14551462 @as(u8, 4);
......@@ -1499,7 +1506,7 @@ fn load(self: *Self, operand: WValue, ty: Type, offset: u32) InnerError!WValue {
14991506 // that is portable across the backend, rather than copying logic.
15001507 const abi_size = if ((ty.isInt() or ty.isAnyFloat()) and ty.abiSize(self.target) <= 8)
15011508 @intCast(u8, ty.abiSize(self.target))
1502 else if (ty.zigTypeTag() == .ErrorSet or ty.zigTypeTag() == .Enum)
1509 else if (ty.zigTypeTag() == .ErrorSet or ty.zigTypeTag() == .Enum or ty.zigTypeTag() == .Bool)
15031510 @intCast(u8, ty.abiSize(self.target))
15041511 else
15051512 @as(u8, 4);
......@@ -2168,6 +2175,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!W
21682175}
21692176
21702177fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
2178 if (self.liveness.isUnused(inst)) return WValue.none;
21712179 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
21722180 const operand = self.resolveInst(ty_op.operand);
21732181 const err_ty = self.air.typeOf(ty_op.operand);
......@@ -2205,7 +2213,11 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
22052213fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
22062214 if (self.liveness.isUnused(inst)) return WValue.none;
22072215 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
2208 return self.resolveInst(ty_op.operand);
2216 const operand = self.resolveInst(ty_op.operand);
2217 return WValue{ .local_with_offset = .{
2218 .local = operand.local,
2219 .offset = 0,
2220 } };
22092221}
22102222
22112223fn airIntcast(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
......@@ -2407,3 +2419,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
24072419 try self.addLabel(.local_set, result.local);
24082420 return result;
24092421}
2422
2423fn airBoolToInt(self: *Self, inst: Air.Inst.Index) InnerError!WValue {
2424 const un_op = self.air.instructions.items(.data)[inst].un_op;
2425 return self.resolveInst(un_op);
2426}
test/behavior.zig+1
......@@ -4,6 +4,7 @@ test {
44 // Tests that pass for stage1, stage2, the C -and wasm backend.
55 _ = @import("behavior/basic.zig");
66 _ = @import("behavior/bitcast.zig");
7 _ = @import("behavior/bool.zig");
78 _ = @import("behavior/bugs/624.zig");
89 _ = @import("behavior/bugs/655.zig");
910 _ = @import("behavior/bugs/679.zig");