Commit a5296768 authored by bradnelson's avatar bradnelson Committed by Commit bot

Allow bitwise operators to convert from intish to int in heap ops.

We previously supported use of bitwise operations to convert
from intish to int, but use of kAsmInt in some places and kAsmIntQ
in others prevents this from working with heap accesses.
Switch to use kAsmIntQ where appropriate (even though intish_ != 0
in principle captures the superset of these cases),
as it's more conservative (and uses types.h better).

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=mjsunit/asm-wasm
R=aseemgarg@chromium.org,titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1731603002

Cr-Commit-Position: refs/heads/master@{#34233}
parent 5c21fa8e
......@@ -1113,7 +1113,7 @@ void AsmTyper::VisitIntegerBitwiseOperator(BinaryOperation* expr,
right_type = left_type;
}
if (!conversion) {
if (!left_type->Is(cache_.kAsmInt) || !right_type->Is(cache_.kAsmInt)) {
if (!left_type->Is(cache_.kAsmIntQ) || !right_type->Is(cache_.kAsmIntQ)) {
FAIL(expr, "ill-typed bitwise operation");
}
}
......@@ -1157,7 +1157,7 @@ void AsmTyper::VisitBinaryOperation(BinaryOperation* expr) {
FAIL(expr, "illegal logical operator");
case Token::BIT_OR: {
// BIT_OR allows Any since it is used as a type coercion.
VisitIntegerBitwiseOperator(expr, Type::Any(), cache_.kAsmInt,
VisitIntegerBitwiseOperator(expr, Type::Any(), cache_.kAsmIntQ,
cache_.kAsmSigned, true);
if (expr->left()->IsCall() && expr->op() == Token::BIT_OR) {
expr->left()->set_bounds(Bounds(cache_.kAsmSigned));
......@@ -1170,7 +1170,7 @@ void AsmTyper::VisitBinaryOperation(BinaryOperation* expr) {
if (left && left->value()->IsBoolean()) {
if (left->ToBooleanIsTrue()) {
left->set_bounds(Bounds(cache_.kSingletonOne));
RECURSE(VisitWithExpectation(expr->right(), cache_.kAsmInt,
RECURSE(VisitWithExpectation(expr->right(), cache_.kAsmIntQ,
"not operator expects an integer"));
IntersectResult(expr, cache_.kAsmSigned);
return;
......@@ -1178,20 +1178,20 @@ void AsmTyper::VisitBinaryOperation(BinaryOperation* expr) {
FAIL(left, "unexpected false");
}
}
// BIT_XOR allows Number since it is used as a type coercion (via ~~).
VisitIntegerBitwiseOperator(expr, Type::Number(), cache_.kAsmInt,
// BIT_XOR allows Any since it is used as a type coercion (via ~~).
VisitIntegerBitwiseOperator(expr, Type::Any(), cache_.kAsmIntQ,
cache_.kAsmSigned, true);
return;
}
case Token::SHR: {
VisitIntegerBitwiseOperator(expr, cache_.kAsmInt, cache_.kAsmInt,
VisitIntegerBitwiseOperator(expr, cache_.kAsmIntQ, cache_.kAsmIntQ,
cache_.kAsmUnsigned, false);
return;
}
case Token::SHL:
case Token::SAR:
case Token::BIT_AND: {
VisitIntegerBitwiseOperator(expr, cache_.kAsmInt, cache_.kAsmInt,
VisitIntegerBitwiseOperator(expr, cache_.kAsmIntQ, cache_.kAsmIntQ,
cache_.kAsmSigned, false);
return;
}
......
......@@ -1523,3 +1523,20 @@ TestForeignVariables();
_WASMEXP_.instantiateModuleFromAsm(Module.toString());
});
})();
(function TestAndIntAndHeapValue() {
function Module(stdlib, foreign, buffer) {
"use asm";
var HEAP32 = new stdlib.Int32Array(buffer);
function func() {
var x = 0;
x = HEAP32[0] & -1;
return x | 0;
}
return {func: func};
}
var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString());
assertEquals(0, m.func());
})();
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