Commit 6607bac5 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm-streaming] Fix function index calculation

The index of a function in the WasmModule data structure is offset by
the number of imported functions in the module. The {DecodeFunctionBody}
function of the module decoder, however, requires the function index
without this offset. The streaming processor mixed up these two ranges
of function indices. This is fixed in this CL.

R=clemensh@chromium.org

Bug: chromium:781507
Change-Id: Ie3e0c4703b06ecb923c98ffb961844915323197c
Reviewed-on: https://chromium-review.googlesource.com/776680
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49523}
parent b34e2d3a
......@@ -3413,8 +3413,6 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(size_t functions_count,
// Set outstanding_finishers_ to 2, because both the AsyncCompileJob and the
// AsyncStreamingProcessor have to finish.
job_->outstanding_finishers_.SetValue(2);
next_function_ = decoder_.module()->num_imported_functions +
FLAG_skip_compiling_wasm_funcs;
compilation_unit_builder_.reset(
new ModuleCompiler::CompilationUnitBuilder(job_->compiler_.get()));
return true;
......@@ -3425,11 +3423,12 @@ bool AsyncStreamingProcessor::ProcessFunctionBody(Vector<const uint8_t> bytes,
uint32_t offset) {
TRACE_STREAMING("Process function body %d ...\n", next_function_);
decoder_.DecodeFunctionBody(
next_function_, static_cast<uint32_t>(bytes.length()), offset, false);
if (next_function_ >= decoder_.module()->num_imported_functions +
FLAG_skip_compiling_wasm_funcs) {
const WasmFunction* func = &decoder_.module()->functions[next_function_];
if (next_function_ >= FLAG_skip_compiling_wasm_funcs) {
decoder_.DecodeFunctionBody(
next_function_, static_cast<uint32_t>(bytes.length()), offset, false);
uint32_t index = next_function_ + decoder_.module()->num_imported_functions;
const WasmFunction* func = &decoder_.module()->functions[index];
WasmName name = {nullptr, 0};
compilation_unit_builder_->AddUnit(job_->module_env_.get(), func, offset,
bytes, name);
......
......@@ -871,6 +871,28 @@ STREAM_TEST(TestModuleWithZeroFunctions) {
CHECK(tester.IsPromiseFulfilled());
}
// Test that all bytes arrive before doing any compilation. FinishStream is
// called immediately.
STREAM_TEST(TestModuleWithImportedFunction) {
StreamTester tester;
ZoneBuffer buffer(tester.zone());
TestSignatures sigs;
WasmModuleBuilder builder(tester.zone());
builder.AddImport(ArrayVector("Test"), sigs.i_iii());
{
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
uint8_t code[] = {kExprGetLocal, 0, kExprEnd};
f->EmitCode(code, arraysize(code));
}
builder.WriteTo(buffer);
tester.OnBytesReceived(buffer.begin(), buffer.end() - buffer.begin());
tester.FinishStream();
tester.RunCompilerTasks();
CHECK(tester.IsPromiseFulfilled());
}
#undef STREAM_TEST
} // namespace wasm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment