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

[asm.js] Fix and test stdlib annotation omission.

This fixes cases where the omission of return type annotation of calls
to stdlib function was rejected, because a surrounding {fround} call
used to be misinterpreted as an annotation instead of a rounding.

R=clemensh@chromium.org
TEST=mjsunit/asm/call-stdlib
BUG=v8:6127

Change-Id: Idec0ef1740ebf8eda969ff05dd1c90252de87a6b
Reviewed-on: https://chromium-review.googlesource.com/493349
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45057}
parent 668246a1
......@@ -2167,16 +2167,13 @@ AsmType* AsmJsParser::ValidateCall() {
// TODO(bradnelson): Refactor AsmType to not need this.
if (callable->CanBeInvokedWith(return_type, param_specific_types)) {
// Return type ok.
} else if (return_type->IsA(AsmType::Void()) &&
callable->CanBeInvokedWith(AsmType::Float(),
} else if (callable->CanBeInvokedWith(AsmType::Float(),
param_specific_types)) {
return_type = AsmType::Float();
} else if (return_type->IsA(AsmType::Void()) &&
callable->CanBeInvokedWith(AsmType::Double(),
} else if (callable->CanBeInvokedWith(AsmType::Double(),
param_specific_types)) {
return_type = AsmType::Double();
} else if (return_type->IsA(AsmType::Void()) &&
callable->CanBeInvokedWith(AsmType::Signed(),
} else if (callable->CanBeInvokedWith(AsmType::Signed(),
param_specific_types)) {
return_type = AsmType::Signed();
} else {
......
// 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 --validate-asm --fast-validate-asm
// This file contains test cases that are particularly interesting because they
// omit the usual call-site coercion of function calls that target well-known
// stdlib functions.
(function SuccessStdlibWithoutAnnotation() {
function Module(stdlib, imports, heap) {
"use asm";
var imul = stdlib.Math.imul;
function f(a, b) {
a = a | 0;
b = b | 0;
var r = 0;
r = imul(a, b);
return r | 0;
}
return { f:f };
}
var m = Module(this);
assertTrue(%IsAsmWasmCode(Module));
assertEquals(966, m.f(23, 42));
assertEquals(-0x0fffffff, m.f(0x7ffffff, 0x7ffffff));
})();
(function SuccessStdlibWithoutAnnotationThenRound() {
function Module(stdlib, imports, heap) {
"use asm";
var fround = stdlib.Math.fround;
var imul = stdlib.Math.imul;
function f(a, b) {
a = a | 0;
b = b | 0;
var r = fround(0);
r = fround(imul(a, b));
return fround(r);
}
return { f:f };
}
var m = Module(this);
assertTrue(%IsAsmWasmCode(Module));
assertEquals(966, m.f(23, 42));
assertEquals(-0x0fffffff - 1, m.f(0x7ffffff, 0x7ffffff));
})();
(function FailureStdlibWithoutAnnotationMismatch() {
function Module(stdlib, imports, heap) {
"use asm";
var fround = stdlib.Math.fround;
var imul = stdlib.Math.imul;
function f(a, b) {
a = a | 0;
b = b | 0;
var r = fround(0);
r = imul(a, b);
return r | 0;
}
return { f:f };
}
var m = Module(this);
assertFalse(%IsAsmWasmCode(Module));
assertEquals(966, m.f(23, 42));
assertEquals(-0x0fffffff, m.f(0x7ffffff, 0x7ffffff));
})();
(function SuccessStdlibWithoutAnnotationUsedInReturn() {
function Module(stdlib, imports, heap) {
"use asm";
var imul = stdlib.Math.imul;
function f(a, b) {
a = a | 0;
b = b | 0;
return imul(a, b);
}
return { f:f };
}
var m = Module(this);
assertTrue(%IsAsmWasmCode(Module));
assertEquals(966, m.f(23, 42));
assertEquals(-0x0fffffff, m.f(0x7ffffff, 0x7ffffff));
})();
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