| ... | @@ -188,8 +188,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -188,8 +188,8 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 188 | .fromInterned(fn_info.return_type), | 188 | .fromInterned(fn_info.return_type), |
| 189 | target, | 189 | target, |
| 190 | ).?; | 190 | ).?; |
| 191 | code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.call_indirect)); | | |
| 192 | if (is_obj) { | 191 | if (is_obj) { |
| | 192 | code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.call_indirect)); |
| 193 | try wasm.out_relocs.append(gpa, .{ | 193 | try wasm.out_relocs.append(gpa, .{ |
| 194 | .offset = @intCast(code.items.len), | 194 | .offset = @intCast(code.items.len), |
| 195 | .pointee = .{ .type_index = func_ty_index }, | 195 | .pointee = .{ .type_index = func_ty_index }, |
| ... | @@ -198,7 +198,19 @@ pub fn lowerToCode(emit: *Emit) Error!void { | ... | @@ -198,7 +198,19 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 198 | }); | 198 | }); |
| 199 | code.appendNTimesAssumeCapacity(0, 5); | 199 | code.appendNTimesAssumeCapacity(0, 5); |
| 200 | } else { | 200 | } else { |
| 201 | const index: Wasm.Flush.FuncTypeIndex = .fromTypeIndex(func_ty_index, &wasm.flush_buffer); | 201 | const index: Wasm.Flush.FuncTypeIndex = @enumFromInt(wasm.flush_buffer.func_types.getIndex(func_ty_index) orelse { |
| | 202 | // In this case we tried to call a function pointer for |
| | 203 | // which the type signature does not match any function |
| | 204 | // body or function import in the entire wasm executable. |
| | 205 | // |
| | 206 | // Since there is no way to create a reference to a |
| | 207 | // function without it being in the function table or |
| | 208 | // import table, this instruction is unreachable. |
| | 209 | code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.@"unreachable")); |
| | 210 | inst += 1; |
| | 211 | continue :loop tags[inst]; |
| | 212 | }); |
| | 213 | code.appendAssumeCapacity(@intFromEnum(std.wasm.Opcode.call_indirect)); |
| 202 | writeUleb128(code, @intFromEnum(index)); | 214 | writeUleb128(code, @intFromEnum(index)); |
| 203 | } | 215 | } |
| 204 | writeUleb128(code, @as(u32, 0)); // table index | 216 | writeUleb128(code, @as(u32, 0)); // table index |