Commit 0cb5ba0e authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Fix function table call position tracking.

This adds test coverage for the source position tracking of function
table calls in asm.js and fixes the discovered issues. It also fixes
function start positions (used by errors thrown at stack checks).

R=clemensh@chromium.org
TEST=mjsunit/wasm/asm-wasm-stack
BUG=v8:6127,v8:6166

Change-Id: Id6ab6dc72bcedb0d838eed315e2a05fbc59039f4
Reviewed-on: https://chromium-review.googlesource.com/465949
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44348}
parent 8c2af037
......@@ -712,7 +712,6 @@ void AsmJsParser::ValidateFunctionTable() {
// 6.4 ValidateFunction
void AsmJsParser::ValidateFunction() {
int start_position = scanner_.GetPosition();
EXPECT_TOKEN(TOK(function));
if (!scanner_.IsGlobal()) {
FAIL("Expected function name");
......@@ -741,6 +740,7 @@ void AsmJsParser::ValidateFunction() {
return_type_ = nullptr;
// Record start of the function, used as position for the stack check.
int start_position = static_cast<int>(scanner_.Position());
current_function_builder_->SetAsmFunctionStartPosition(start_position);
std::vector<AsmType*> params;
......@@ -2037,6 +2037,8 @@ AsmType* AsmJsParser::ValidateCall() {
current_function_builder_->Emit(kExprI32Add);
// We have to use a temporary for the correct order of evaluation.
current_function_builder_->EmitSetLocal(tmp);
// The position of function table calls is after the table lookup.
pos = static_cast<int>(scanner_.Position());
}
std::vector<AsmType*> param_types;
ZoneVector<AsmType*> param_specific_types(zone());
......@@ -2122,10 +2124,8 @@ AsmType* AsmJsParser::ValidateCall() {
function_info->type = function_type;
if (function_info->kind == VarKind::kTable) {
current_function_builder_->EmitGetLocal(tmp);
// TODO(bradnelson): Figure out the right debug scanner offset and
// re-enable.
// current_function_builder_->AddAsmWasmOffset(scanner_.GetPosition(),
// scanner_.GetPosition());
// TODO(mstarzinger): Fix the {to_number_position} and test it.
current_function_builder_->AddAsmWasmOffset(pos, pos);
current_function_builder_->Emit(kExprCallIndirect);
current_function_builder_->EmitVarUint(signature_index);
current_function_builder_->EmitVarUint(0); // table index
......@@ -2272,10 +2272,7 @@ AsmType* AsmJsParser::ValidateCall() {
current_function_builder_->EmitVarUint(signature_index);
current_function_builder_->EmitVarUint(0); // table index
} else {
// TODO(bradnelson): Figure out the right debug scanner offset and
// re-enable.
// current_function_builder_->AddAsmWasmOffset(scanner_.GetPosition(),
// scanner_.GetPosition());
current_function_builder_->AddAsmWasmOffset(pos, pos);
current_function_builder_->Emit(kExprCallFunction);
current_function_builder_->EmitDirectCallIndex(function_info->index);
}
......
......@@ -8,7 +8,6 @@
['variant != default', {
# Issue 6166.
'debugger/asm-js-breakpoint-during-exec': [PASS, FAIL],
'debugger/asm-js-stack': [PASS, FAIL],
# Issue 6167.
'debugger/eval-scopes': [PASS, FAIL],
'debugger/scope-skip-variables-with-empty-name': [PASS, FAIL],
......
......@@ -661,7 +661,9 @@
# need to re-enable these for the "new" validator.
'regress/regress-618608': [SKIP],
'wasm/asm-wasm-exception-in-tonumber': [SKIP],
'wasm/asm-wasm-stack': [SKIP],
# Issue 6127: Currently {StashCode} breaks the source position table.
'wasm/asm-wasm-expr': [SKIP],
}], # variant == asm_wasm
['variant == wasm_traps', {
......
......@@ -68,8 +68,10 @@ function generateWasmFromAsmJs(stdlib, foreign) {
case 0: callThrow(); break;
case 1: redirectFun(0); break;
case 2: redirectFun(1); break;
case 3: funTable[i & 0](2); break;
}
}
var funTable = [ redirectFun ];
return redirectFun;
}
......@@ -88,8 +90,8 @@ function generateWasmFromAsmJs(stdlib, foreign) {
'^ *at throwException \\(' + filename + ':56:9\\)$',
'^ *at callThrow \\(' + filename + ':63:5\\)$',
'^ *at redirectFun \\(' + filename + ':68:15\\)$',
'^ *at PreformattedStackTraceFromJS \\(' + filename + ':81:5\\)$',
'^ *at ' + filename + ':94:3$'
'^ *at PreformattedStackTraceFromJS \\(' + filename + ':83:5\\)$',
'^ *at ' + filename + ':96:3$'
]);
})();
......@@ -103,7 +105,7 @@ Error.prepareStackTrace = function(error, frames) {
assertTrue(%IsWasmCode(fun));
var e = null;
try {
fun(2);
fun(3);
} catch (ex) {
e = ex;
}
......@@ -114,8 +116,9 @@ Error.prepareStackTrace = function(error, frames) {
['redirectFun', 68, 15], // --
['redirectFun', 69, 15], // --
['redirectFun', 70, 15], // --
['CallsiteObjectsFromJS', 106, 5], // --
[null, 120, 3]
['redirectFun', 71, 30], // --
['CallsiteObjectsFromJS', 108, 5], // --
[null, 123, 3]
]);
})();
......@@ -133,15 +136,15 @@ function generateOverflowWasmFromAsmJs() {
assertTrue(%IsWasmCode(fun));
var e = null;
try {
fun(2);
fun(23);
} catch (ex) {
e = ex;
}
assertInstanceof(e, RangeError, 'RangeError should have been thrown');
checkTopFunctionsOnCallsites(e, [
['f', 124, 13], // --
['f', 126, 12], // --
['f', 126, 12], // --
['f', 126, 12] // --
['f', 127, 13], // --
['f', 129, 12], // --
['f', 129, 12], // --
['f', 129, 12] // --
]);
})();
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