Skip to content

Commit

Permalink
wasm: address behavior test regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobly0 authored and andrewrk committed Jun 4, 2023
1 parent 0088667 commit 7c86b48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/arch/wasm/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2960,10 +2960,21 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value) InnerError!WValue {
const offset = index * elem_type.abiSize(mod);
const array_ptr = try func.lowerParentPtr(elem.base.toValue());

return WValue{ .memory_offset = .{
.pointer = array_ptr.memory,
.offset = @intCast(u32, offset),
} };
return switch (array_ptr) {
.memory => |ptr_| WValue{
.memory_offset = .{
.pointer = ptr_,
.offset = @intCast(u32, offset),
},
},
.memory_offset => |mem_off| WValue{
.memory_offset = .{
.pointer = mem_off.pointer,
.offset = @intCast(u32, offset) + mem_off.offset,
},
},
else => unreachable,
};
},
.field => |field| {
const parent_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
Expand Down Expand Up @@ -3253,7 +3264,12 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
},
else => unreachable,
},
.un => return func.fail("Wasm TODO: LowerConstant for {}", .{ty.fmt(mod)}),
.un => |union_obj| {
// in this case we have a packed union which will not be passed by reference.
const field_index = ty.unionTagFieldIndex(union_obj.tag.toValue(), func.bin_file.base.options.module.?).?;
const field_ty = ty.unionFields(mod).values()[field_index].ty;
return func.lowerConstant(union_obj.val.toValue(), field_ty);
},
.memoized_call => unreachable,
}
}
Expand Down Expand Up @@ -7173,7 +7189,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
break :val try WValue.toLocal(.stack, func, result_ty);
};

return func.finishAir(inst, result_ptr, &.{ extra.ptr, extra.new_value, extra.expected_value });
return func.finishAir(inst, result_ptr, &.{ extra.ptr, extra.expected_value, extra.new_value });
}

fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
Expand Down
1 change: 1 addition & 0 deletions test/behavior/bugs/1381.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test "union that needs padding bytes inside an array" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;

var as = [_]A{
A{ .B = B{ .D = 1 } },
Expand Down

0 comments on commit 7c86b48

Please sign in to comment.