Merge pull request #17819 from Luukdegram/wasm-bitcast-fix

wasm - fix bitcasting between arrays and scalar types
This commit is contained in:
Andrew Kelley 2023-11-01 20:20:11 -04:00 committed by GitHub
commit d892665694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View File

@ -13,9 +13,7 @@ var cmdline_buffer: [4096]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);
pub fn main() void {
if (builtin.zig_backend == .stage2_aarch64 or
builtin.zig_backend == .stage2_wasm)
{
if (builtin.zig_backend == .stage2_aarch64) {
return mainSimple() catch @panic("test failure");
}

View File

@ -3814,6 +3814,16 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
const bitcast_result = try func.bitcast(wanted_ty, given_ty, operand);
break :result try bitcast_result.toLocal(func, wanted_ty);
}
const mod = func.bin_file.base.options.module.?;
if (isByRef(given_ty, mod) and !isByRef(wanted_ty, mod)) {
const loaded_memory = try func.load(operand, wanted_ty, 0);
break :result try loaded_memory.toLocal(func, wanted_ty);
}
if (!isByRef(given_ty, mod) and isByRef(wanted_ty, mod)) {
const stack_memory = try func.allocStack(wanted_ty);
try func.store(stack_memory, operand, given_ty, 0);
break :result stack_memory;
}
break :result func.reuseOperand(ty_op.operand, operand);
};
func.finishAir(inst, result, &.{ty_op.operand});

View File

@ -7,7 +7,6 @@ test "allocation and looping over 3-byte integer" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
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;
if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
return error.SkipZigTest; // TODO

View File

@ -1351,7 +1351,6 @@ test "under-aligned struct field" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
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;
const U = extern union {
fd: i32,