diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index 626977c5b5..c7643b342a 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -2543,7 +2543,7 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args, Int32Constant(fixed_offset)), *effect_, *control_); int32_t canonical_sig_num = env_->module->signature_ids[sig_index]; - CHECK_GE(sig_index, 0); + CHECK_GE(canonical_sig_num, 0); Node* sig_match = graph()->NewNode(machine->WordEqual(), load_sig, jsgraph()->SmiConstant(canonical_sig_num)); TrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position); diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h index 04d918b0a4..75ae352b06 100644 --- a/src/wasm/function-body-decoder-impl.h +++ b/src/wasm/function-body-decoder-impl.h @@ -246,12 +246,12 @@ struct BreakDepthOperand { template struct CallIndirectOperand { uint32_t table_index; - uint32_t index; + uint32_t sig_index; FunctionSig* sig = nullptr; unsigned length = 0; inline CallIndirectOperand(Decoder* decoder, const byte* pc) { unsigned len = 0; - index = decoder->read_u32v(pc + 1, &len, "signature index"); + sig_index = decoder->read_u32v(pc + 1, &len, "signature index"); if (!VALIDATE(decoder->ok())) return; table_index = decoder->read_u8(pc + 1 + len, "table index"); if (!VALIDATE(table_index == 0)) { @@ -789,10 +789,10 @@ class WasmDecoder : public Decoder { inline bool Complete(const byte* pc, CallIndirectOperand& operand) { if (!VALIDATE(module_ != nullptr && - operand.index < module_->signatures.size())) { + operand.sig_index < module_->signatures.size())) { return false; } - operand.sig = module_->signatures[operand.index]; + operand.sig = module_->signatures[operand.sig_index]; return true; } @@ -802,7 +802,7 @@ class WasmDecoder : public Decoder { return false; } if (!Complete(pc, operand)) { - errorf(pc + 1, "invalid signature index: #%u", operand.index); + errorf(pc + 1, "invalid signature index: #%u", operand.sig_index); return false; } return true; diff --git a/src/wasm/function-body-decoder.cc b/src/wasm/function-body-decoder.cc index 57ee78f91c..217a5ff3b1 100644 --- a/src/wasm/function-body-decoder.cc +++ b/src/wasm/function-body-decoder.cc @@ -369,13 +369,13 @@ class WasmGraphBuildingInterface { void CallDirect(Decoder* decoder, const CallFunctionOperand& operand, const Value args[], Value returns[]) { - DoCall(decoder, nullptr, operand, args, returns, false); + DoCall(decoder, nullptr, operand.sig, operand.index, args, returns); } void CallIndirect(Decoder* decoder, const Value& index, const CallIndirectOperand& operand, const Value args[], Value returns[]) { - DoCall(decoder, index.node, operand, args, returns, true); + DoCall(decoder, index.node, operand.sig, operand.sig_index, args, returns); } void SimdOp(Decoder* decoder, WasmOpcode opcode, Vector args, @@ -782,30 +782,29 @@ class WasmGraphBuildingInterface { return result; } - template void DoCall(WasmFullDecoder* decoder, - TFNode* index_node, const Operand& operand, const Value args[], - Value returns[], bool is_indirect) { - int param_count = static_cast(operand.sig->parameter_count()); + TFNode* index_node, FunctionSig* sig, uint32_t index, + const Value args[], Value returns[]) { + int param_count = static_cast(sig->parameter_count()); TFNode** arg_nodes = builder_->Buffer(param_count + 1); TFNode** return_nodes = nullptr; arg_nodes[0] = index_node; for (int i = 0; i < param_count; ++i) { arg_nodes[i + 1] = args[i].node; } - if (is_indirect) { - builder_->CallIndirect(operand.index, arg_nodes, &return_nodes, + if (index_node) { + builder_->CallIndirect(index, arg_nodes, &return_nodes, decoder->position()); } else { - builder_->CallDirect(operand.index, arg_nodes, &return_nodes, + builder_->CallDirect(index, arg_nodes, &return_nodes, decoder->position()); } - int return_count = static_cast(operand.sig->return_count()); + int return_count = static_cast(sig->return_count()); for (int i = 0; i < return_count; ++i) { returns[i].node = return_nodes[i]; } // The invoked function could have used grow_memory, so we need to - // reload mem_size and mem_start + // reload mem_size and mem_start. LoadContextIntoSsa(ssa_env_); } }; @@ -1002,7 +1001,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, } case kExprCallIndirect: { CallIndirectOperand operand(&i, i.pc()); - os << " // sig #" << operand.index; + os << " // sig #" << operand.sig_index; if (decoder.Complete(i.pc(), operand)) { os << ": " << *operand.sig; } diff --git a/src/wasm/wasm-interpreter.cc b/src/wasm/wasm-interpreter.cc index 813785bcdf..ece16e225e 100644 --- a/src/wasm/wasm-interpreter.cc +++ b/src/wasm/wasm-interpreter.cc @@ -1934,7 +1934,7 @@ class ThreadImpl { // Assume only one table for now. DCHECK_LE(module()->function_tables.size(), 1u); ExternalCallResult result = - CallIndirectFunction(0, entry_index, operand.index); + CallIndirectFunction(0, entry_index, operand.sig_index); switch (result.type) { case ExternalCallResult::INTERNAL: // The import is a function of this instance. Call it directly. diff --git a/src/wasm/wasm-text.cc b/src/wasm/wasm-text.cc index 81c8e41813..f5dd229071 100644 --- a/src/wasm/wasm-text.cc +++ b/src/wasm/wasm-text.cc @@ -134,7 +134,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes, case kExprCallIndirect: { CallIndirectOperand operand(&i, i.pc()); DCHECK_EQ(0, operand.table_index); - os << "call_indirect " << operand.index; + os << "call_indirect " << operand.sig_index; break; } case kExprCallFunction: {