aboutsummaryrefslogtreecommitdiff
path: root/src/arch/wasm/CodeGen.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-06-04 10:26:01 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:51:10 -0700
commit44d8cf9331218653c283a930bbc74e6871fe1701 (patch)
treebef2d41cc7eb71e0c05e02f3833d4801b37be48d /src/arch/wasm/CodeGen.zig
parentdce80f67d4ab9a9387be595c0275853369ffb7e4 (diff)
downloadzig-44d8cf9331218653c283a930bbc74e6871fe1701.tar.gz
zig-44d8cf9331218653c283a930bbc74e6871fe1701.zip
wasm: address behavior test regressions
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
-rw-r--r--src/arch/wasm/CodeGen.zig28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
index 9b7ba19c13..4c1d5b4081 100644
--- a/src/arch/wasm/CodeGen.zig
+++ b/src/arch/wasm/CodeGen.zig
@@ -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);
@@ -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,
}
}
@@ -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 {