Bug 1250556: Require Store value expression to have the opcode's type; r?sunfish
MozReview-Commit-ID: 3O5O0t1M5SN
--- a/js/src/asmjs/Wasm.cpp
+++ b/js/src/asmjs/Wasm.cpp
@@ -376,17 +376,17 @@ DecodeLoad(FunctionDecoder& f, ExprType
return DecodeLoadStoreAddress(f) &&
CheckType(f, type, expected);
}
static bool
DecodeStore(FunctionDecoder& f, ExprType expected, ExprType type)
{
return DecodeLoadStoreAddress(f) &&
- DecodeExpr(f, expected) &&
+ DecodeExpr(f, type) &&
CheckType(f, type, expected);
}
static bool
DecodeReturn(FunctionDecoder& f)
{
return f.ret() == ExprType::Void ||
DecodeExpr(f, f.ret());
--- a/js/src/jit-test/tests/wasm/basic-const.js
+++ b/js/src/jit-test/tests/wasm/basic-const.js
@@ -1,18 +1,13 @@
load(libdir + "wasm.js");
if (!wasmIsSupported())
quit();
-function mismatchError(actual, expect) {
- var str = "type mismatch: expression has type " + actual + " but expected " + expect;
- return RegExp(str);
-}
-
function testConst(type, str, expect) {
assertEq(wasmEvalText('(module (func (result ' + type + ') (' + type + '.const ' + str + ')) (export "" 0))')(), expect);
}
function testConstError(type, str) {
// For now at least, we don't distinguish between parse errors and OOMs.
assertErrorMessage(() => wasmEvalText('(module (func (result ' + type + ') (' + type + '.const ' + str + ')) (export "" 0))')(), Error, /parsing wasm text/);
}
--- a/js/src/jit-test/tests/wasm/basic-conversion.js
+++ b/js/src/jit-test/tests/wasm/basic-conversion.js
@@ -1,18 +1,13 @@
load(libdir + "wasm.js");
if (!wasmIsSupported())
quit();
-function mismatchError(actual, expect) {
- var str = "type mismatch: expression has type " + actual + " but expected " + expect;
- return RegExp(str);
-}
-
function testConversion(resultType, opcode, paramType, op, expect) {
assertEq(wasmEvalText('(module (func (param ' + paramType + ') (result ' + resultType + ') (' + resultType + '.' + opcode + '/' + paramType + ' (get_local 0))) (export "" 0))')(op), expect);
// TODO: i64 NYI
for (var bad of ['i32', 'f32', 'f64']) {
if (bad != resultType)
assertErrorMessage(() => wasmEvalText('(module (func (param ' + paramType + ') (result ' + bad + ') (' + resultType + '.' + opcode + '/' + paramType + ' (get_local 0))))'),
TypeError,
--- a/js/src/jit-test/tests/wasm/basic-memory.js
+++ b/js/src/jit-test/tests/wasm/basic-memory.js
@@ -1,18 +1,13 @@
load(libdir + "wasm.js");
if (!wasmIsSupported())
quit();
-function mismatchError(actual, expect) {
- var str = "type mismatch: expression has type " + actual + " but expected " + expect;
- return RegExp(str);
-}
-
function testLoad(type, ext, base, offset, align, expect) {
assertEq(wasmEvalText(
'(module' +
' (memory 0x10000' +
' (segment 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")' +
' (segment 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")' +
' )' +
' (func (param i32) (result ' + type + ')' +
@@ -126,8 +121,17 @@ testStore('f64', '', 0, 0, 0, 0.89012345
testStore('i32', '8', 0, 0, 0, 0x23);
testStore('i32', '16', 0, 0, 0, 0x2345);
//testStore('i64', '8', 0, 0, 0, 0x23); // TODO: i64 NYI
//testStore('i64', '16', 0, 0, 0, 0x23); // TODO: i64 NYI
//testStore('i64', '32', 0, 0, 0, 0x23); // TODO: i64 NYI
testLoadError('i32', '', 0, 0, 3, /memory access alignment must be a power of two/);
testStoreError('i32', '', 0, 0, 3, /memory access alignment must be a power of two/);
+
+assertErrorMessage(() => wasmEvalText('(module (memory 0x10000) (func (f64.store offset=0 (i32.const 0) (i32.const 0))))'), TypeError, mismatchError("i32", "f64"));
+assertErrorMessage(() => wasmEvalText('(module (memory 0x10000) (func (f64.store offset=0 (i32.const 0) (f32.const 0))))'), TypeError, mismatchError("f32", "f64"));
+
+assertErrorMessage(() => wasmEvalText('(module (memory 0x10000) (func (f32.store offset=0 (i32.const 0) (i32.const 0))))'), TypeError, mismatchError("i32", "f32"));
+assertErrorMessage(() => wasmEvalText('(module (memory 0x10000) (func (f32.store offset=0 (i32.const 0) (f64.const 0))))'), TypeError, mismatchError("f64", "f32"));
+
+assertErrorMessage(() => wasmEvalText('(module (memory 0x10000) (func (i32.store offset=0 (i32.const 0) (f32.const 0))))'), TypeError, mismatchError("f32", "i32"));
+assertErrorMessage(() => wasmEvalText('(module (memory 0x10000) (func (i32.store offset=0 (i32.const 0) (f64.const 0))))'), TypeError, mismatchError("f64", "i32"));