Skip to content

Commit d892665

Browse files
authored
Merge pull request #17819 from Luukdegram/wasm-bitcast-fix
wasm - fix bitcasting between arrays and scalar types
2 parents 3ead829 + db1825e commit d892665

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

lib/test_runner.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ var cmdline_buffer: [4096]u8 = undefined;
1313
var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);
1414

1515
pub fn main() void {
16-
if (builtin.zig_backend == .stage2_aarch64 or
17-
builtin.zig_backend == .stage2_wasm)
18-
{
16+
if (builtin.zig_backend == .stage2_aarch64) {
1917
return mainSimple() catch @panic("test failure");
2018
}
2119

src/arch/wasm/CodeGen.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,6 +3814,16 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38143814
const bitcast_result = try func.bitcast(wanted_ty, given_ty, operand);
38153815
break :result try bitcast_result.toLocal(func, wanted_ty);
38163816
}
3817+
const mod = func.bin_file.base.options.module.?;
3818+
if (isByRef(given_ty, mod) and !isByRef(wanted_ty, mod)) {
3819+
const loaded_memory = try func.load(operand, wanted_ty, 0);
3820+
break :result try loaded_memory.toLocal(func, wanted_ty);
3821+
}
3822+
if (!isByRef(given_ty, mod) and isByRef(wanted_ty, mod)) {
3823+
const stack_memory = try func.allocStack(wanted_ty);
3824+
try func.store(stack_memory, operand, given_ty, 0);
3825+
break :result stack_memory;
3826+
}
38173827
break :result func.reuseOperand(ty_op.operand, operand);
38183828
};
38193829
func.finishAir(inst, result, &.{ty_op.operand});

test/behavior/bugs/1851.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ test "allocation and looping over 3-byte integer" {
77
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
88
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
99
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10-
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
1110

1211
if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
1312
return error.SkipZigTest; // TODO

test/behavior/struct.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,6 @@ test "under-aligned struct field" {
13511351
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
13521352
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
13531353
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1354-
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
13551354

13561355
const U = extern union {
13571356
fd: i32,

0 commit comments

Comments
 (0)