authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-05-20 14:38:59+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-22 07:17:50-07:00
log95845ba2ac81625507e9cb0c060e1a5b3903e102
tree020b80c5d90175ed5f4b464a54e561d8849f7877
parent4a09703f6274f41c3408a8012b6d20cbfaf2f092

llvm: fix `@wasmMemory{Size,Grow}` for wasm64

Closes #19942

5 files changed, 12 insertions(+), 10 deletions(-)

doc/langref.html.in+2-2
......@@ -9040,7 +9040,7 @@ test "integer cast panic" {
90409040 {#header_close#}
90419041
90429042 {#header_open|@wasmMemorySize#}
9043 <pre>{#syntax#}@wasmMemorySize(index: u32) u32{#endsyntax#}</pre>
9043 <pre>{#syntax#}@wasmMemorySize(index: u32) usize{#endsyntax#}</pre>
90449044 <p>
90459045 This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as
90469046 an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size.
......@@ -9054,7 +9054,7 @@ test "integer cast panic" {
90549054 {#header_close#}
90559055
90569056 {#header_open|@wasmMemoryGrow#}
9057 <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: u32) i32{#endsyntax#}</pre>
9057 <pre>{#syntax#}@wasmMemoryGrow(index: u32, delta: usize) isize{#endsyntax#}</pre>
90589058 <p>
90599059 This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by
90609060 {#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page
lib/std/zig/AstGen.zig+1-1
......@@ -9461,7 +9461,7 @@ fn builtinCall(
94619461 },
94629462 .wasm_memory_grow => {
94639463 const index_arg = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
9464 const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[1]);
9464 const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, params[1]);
94659465 const result = try gz.addExtendedPayload(.wasm_memory_grow, Zir.Inst.BinNode{
94669466 .node = gz.nodeIndexToRelative(node),
94679467 .lhs = index_arg,
src/Air.zig+4-4
......@@ -782,13 +782,13 @@ pub const Inst = struct {
782782 field_parent_ptr,
783783
784784 /// Implements @wasmMemorySize builtin.
785 /// Result type is always `u32`,
785 /// Result type is always `usize`,
786786 /// Uses the `pl_op` field, payload represents the index of the target memory.
787787 /// The operand is unused and always set to `Ref.none`.
788788 wasm_memory_size,
789789
790790 /// Implements @wasmMemoryGrow builtin.
791 /// Result type is always `i32`,
791 /// Result type is always `isize`,
792792 /// Uses the `pl_op` field, payload represents the index of the target memory.
793793 wasm_memory_grow,
794794
......@@ -1471,8 +1471,8 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14711471 .save_err_return_trace_index,
14721472 => return Type.usize,
14731473
1474 .wasm_memory_grow => return Type.i32,
1475 .wasm_memory_size => return Type.u32,
1474 .wasm_memory_grow => return Type.isize,
1475 .wasm_memory_size => return Type.usize,
14761476
14771477 .int_from_bool => return Type.u1,
14781478
src/Sema.zig+1-1
......@@ -26238,7 +26238,7 @@ fn zirWasmMemoryGrow(
2623826238 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{
2623926239 .needed_comptime_reason = "wasm memory size index must be comptime-known",
2624026240 }));
26241 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);
26241 const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src);
2624226242
2624326243 try sema.requireRuntimeBlock(block, builtin_src, null);
2624426244 return block.addInst(.{
src/codegen/llvm.zig+4-2
......@@ -7499,7 +7499,8 @@ pub const FuncGen = struct {
74997499 const o = self.dg.object;
75007500 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
75017501 const index = pl_op.payload;
7502 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{
7502 const llvm_usize = try o.lowerType(Type.usize);
7503 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{
75037504 try o.builder.intValue(.i32, index),
75047505 }, "");
75057506 }
......@@ -7508,7 +7509,8 @@ pub const FuncGen = struct {
75087509 const o = self.dg.object;
75097510 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
75107511 const index = pl_op.payload;
7511 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{
7512 const llvm_isize = try o.lowerType(Type.isize);
7513 return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{
75127514 try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand),
75137515 }, "");
75147516 }