Index: src/compiler/wasm-compiler.cc |
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
index 619e639e1509a2a73e2e0908bd397869838c08f4..e0c2cd23239ff4952c91d77e597d63df0c3cc533 100644 |
--- a/src/compiler/wasm-compiler.cc |
+++ b/src/compiler/wasm-compiler.cc |
@@ -1926,10 +1926,28 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, |
// Bounds check the index. |
int table_size = static_cast<int>(module_->FunctionTableSize()); |
if (table_size > 0) { |
- // Bounds check against the table size. |
- Node* size = Int32Constant(static_cast<int>(table_size)); |
- Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size); |
- trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position); |
+ if (FLAG_wasm_jit_prototype) { |
+ int indirect_table_size = |
+ static_cast<int>(module_->instance->function_table->length()); |
+ |
+ Node* upper_bound = Int32Constant(indirect_table_size / 2); |
+ Node* less_than_upper_bound = |
+ graph()->NewNode(machine->Uint32LessThan(), key, upper_bound); |
+ trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, less_than_upper_bound, |
+ position); |
+ |
+ Node* lower_bound = Int32Constant(indirect_table_size / 2 - |
+ module_->instance->padded_entries); |
bradn
2016/06/14 02:02:46
Hey Ritesh.
Actually this isn't quite right.
We do
titzer
2016/06/14 20:58:05
Agree.
bradn
2016/06/14 21:00:25
Actually since it can't run (since we don't know t
|
+ Node* more_than_lower_bound = |
+ graph()->NewNode(machine->Uint32LessThanOrEqual(), lower_bound, key); |
+ trap_->AddTrapIfTrue(wasm::kTrapDefaultFuncCall, more_than_lower_bound, |
+ position); |
+ } else { |
+ // Bounds check against the table size. |
+ Node* size = Int32Constant(static_cast<int>(table_size)); |
+ Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size); |
+ trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position); |
+ } |
} else { |
// No function table. Generate a trap and return a constant. |
trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, Int32Constant(0), position); |