Commit d813f46e authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Properly handle unused function imports.

This makes sure that function imports without a single call site within
the asm.js module are still preserved in the WebAssembly module, hence
preserving intended JavaScript semantics during module instantiation.

R=clemensh@chromium.org
TEST=mjsunit/regress/regress-crbug-722348
BUG=chromium:722348

Change-Id: I624d0e52b32b864c1e3002187a99a0a63834a4b0
Reviewed-on: https://chromium-review.googlesource.com/509450Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45452}
parent eb5f8549
......@@ -348,9 +348,15 @@ void AsmJsParser::ValidateModule() {
if (info.kind == VarKind::kTable && !info.function_defined) {
FAIL("Undefined function table");
}
if (info.kind == VarKind::kImportedFunction && !info.function_defined) {
// For imported functions without a single call site, we insert a dummy
// import here to preserve the fact that there actually was an import.
FunctionSig* void_void_sig = FunctionSig::Builder(zone(), 0, 0).Build();
module_builder_->AddImport(info.import->function_name, void_void_sig);
}
}
// Add start function to init things.
// Add start function to initialize things.
WasmFunctionBuilder* start = module_builder_->AddFunction();
module_builder_->MarkStartFunction(start);
for (auto& global_import : global_imports_) {
......@@ -2149,10 +2155,12 @@ AsmType* AsmJsParser::ValidateCall() {
auto it = function_info->import->cache.find(sig);
if (it != function_info->import->cache.end()) {
index = it->second;
DCHECK(function_info->function_defined);
} else {
index =
module_builder_->AddImport(function_info->import->function_name, sig);
function_info->import->cache[sig] = index;
function_info->function_defined = true;
}
current_function_builder_->AddAsmWasmOffset(call_pos, to_number_pos);
current_function_builder_->EmitWithU32V(kExprCallFunction, index);
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
function Module(global, env) {
"use asm";
var unused_fun = env.fun;
function f() {}
return { f:f }
}
assertThrows(() => Module(), TypeError);
assertFalse(%IsAsmWasmCode(Module));
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