Commit 89e10055 authored by bradnelson's avatar bradnelson Committed by Commit bot

[wasm][asm.js] Allow true/false in int binary ops.

Because the parser optimizes !123 -> false,
we allow booleans in expressions (but not parameter annotations).
Allow this in asm-wasm-builder.
Turn on an early out case in asm-typer that is fine.

BUG=672784
R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2561193003
Cr-Commit-Position: refs/heads/master@{#41622}
parent 768acf68
......@@ -2254,12 +2254,12 @@ AsmType* AsmTyper::ValidateBitwiseORExpression(BinaryOperation* binop) {
RECURSE(type = ValidateCall(AsmType::Signed(), left_as_call));
return type;
}
// TODO(jpp): at this point we know that binop is expr|0. We could sinply
//
// RECURSE(t = ValidateExpression(left));
// FAIL_IF(t->IsNotA(Intish));
// return Signed;
AsmType* left_type;
RECURSE(left_type = ValidateExpression(left));
if (!left_type->IsA(AsmType::Intish())) {
FAIL(left, "Left side of |0 annotation must be intish.");
}
return AsmType::Signed();
}
auto* right = binop->right();
......
......@@ -1513,8 +1513,8 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
if (expr->op() == op && expr->right()->IsLiteral() &&
TypeOf(expr) == kAstI32) {
Literal* right = expr->right()->AsLiteral();
DCHECK(right->raw_value()->IsNumber());
if (static_cast<int32_t>(right->raw_value()->AsNumber()) == val) {
if (right->raw_value()->IsNumber() &&
static_cast<int32_t>(right->raw_value()->AsNumber()) == val) {
return true;
}
}
......
......@@ -302,7 +302,7 @@ function assertValidAsm(func) {
assertEquals(0xffffffff, m.foo());
})();
(function TestBadBooleanAnnotation() {
(function TestBadBooleanParamAnnotation() {
function Module() {
"use asm";
function foo(x) {
......@@ -316,6 +316,23 @@ function assertValidAsm(func) {
assertEquals(3, m.foo(3));
})();
(function TestBadishBooleanExprAnnotation() {
function Module() {
"use asm";
function foo(x) {
x = x | 0;
x = (x + 1) | false;
return x | 0;
}
return { foo: foo };
}
var m = Module();
// We all false here because the parser optimizes expressons like:
// !123 to false.
assertTrue(%IsAsmWasmCode(Module));
assertEquals(4, m.foo(3));
})();
(function TestBadCase() {
function Module() {
"use asm";
......
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