[wasm] fix loops and if-else to take int type instead of signed

BUG=617526
R=bradnelson@chromium.org
TEST=regress-617526.js

Review-Url: https://codereview.chromium.org/2101923003
Cr-Commit-Position: refs/heads/master@{#37354}
This commit is contained in:
aseemgarg 2016-06-28 17:39:49 -07:00 committed by Commit bot
parent e42983d147
commit fa5cb207a1
3 changed files with 90 additions and 4 deletions

View File

@ -340,8 +340,11 @@ void AsmTyper::VisitIfStatement(IfStatement* stmt) {
if (!in_function_) {
FAIL(stmt, "if statement inside module body");
}
RECURSE(VisitWithExpectation(stmt->condition(), cache_.kAsmSigned,
RECURSE(VisitWithExpectation(stmt->condition(), cache_.kAsmInt,
"if condition expected to be integer"));
if (intish_ != 0) {
FAIL(stmt, "if condition expected to be signed or unsigned");
}
RECURSE(Visit(stmt->then_statement()));
RECURSE(Visit(stmt->else_statement()));
}
@ -434,8 +437,11 @@ void AsmTyper::VisitDoWhileStatement(DoWhileStatement* stmt) {
FAIL(stmt, "do statement inside module body");
}
RECURSE(Visit(stmt->body()));
RECURSE(VisitWithExpectation(stmt->cond(), cache_.kAsmSigned,
RECURSE(VisitWithExpectation(stmt->cond(), cache_.kAsmInt,
"do condition expected to be integer"));
if (intish_ != 0) {
FAIL(stmt, "do condition expected to be signed or unsigned");
}
}
@ -443,8 +449,11 @@ void AsmTyper::VisitWhileStatement(WhileStatement* stmt) {
if (!in_function_) {
FAIL(stmt, "while statement inside module body");
}
RECURSE(VisitWithExpectation(stmt->cond(), cache_.kAsmSigned,
RECURSE(VisitWithExpectation(stmt->cond(), cache_.kAsmInt,
"while condition expected to be integer"));
if (intish_ != 0) {
FAIL(stmt, "while condition expected to be signed or unsigned");
}
RECURSE(Visit(stmt->body()));
}
@ -457,9 +466,12 @@ void AsmTyper::VisitForStatement(ForStatement* stmt) {
RECURSE(Visit(stmt->init()));
}
if (stmt->cond() != nullptr) {
RECURSE(VisitWithExpectation(stmt->cond(), cache_.kAsmSigned,
RECURSE(VisitWithExpectation(stmt->cond(), cache_.kAsmInt,
"for condition expected to be integer"));
}
if (intish_ != 0) {
FAIL(stmt, "for condition expected to be signed or unsigned");
}
if (stmt->next() != nullptr) {
RECURSE(Visit(stmt->next()));
}

View File

@ -0,0 +1,23 @@
// Copyright 2016 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: --expose-wasm
// Changing the code a little to avoid infinite loop
function __f_109() {
"use asm";
function __f_18() {
var a = 0;
while(2147483648) {
a = 1;
break;
}
return a|0;
}
return {__f_18: __f_18};
}
var wasm = Wasm.instantiateModuleFromAsm( __f_109.toString());
assertEquals(1, wasm.__f_18());

View File

@ -1542,3 +1542,54 @@ assertWasm(1, TestXor);
Wasm.instantiateModuleFromAsm('var x = 3;');
});
})();
(function TestIfWithUnsigned() {
function asmModule() {
"use asm";
function main() {
if (2147483658) { // 2^31 + 10
return 231;
}
return 0;
}
return {main:main};
}
var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString());
assertEquals(231, wasm.main());
})();
(function TestLoopsWithUnsigned() {
function asmModule() {
"use asm";
function main() {
var val = 1;
var count = 0;
for (val = 2147483648; 2147483648;) {
val = 2147483649;
break;
}
while (val>>>0) {
val = (val + 1) | 0;
count = (count + 1)|0;
if ((count|0) == 9) {
break;
}
}
count = 0;
do {
val = (val + 2) | 0;
count = (count + 1)|0;
if ((count|0) == 5) {
break;
}
} while (0xffffffff);
if ((val>>>0) == 2147483668) {
return 323;
}
return 0;
}
return {main:main};
}
var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString());
assertEquals(323, wasm.main());
})();