Bug 1624490 - Allow ref.null in declared segments. r=lth
authorRyan Hunt <rhunt@eqrion.net>
Fri, 27 Mar 2020 03:08:06 +0000
changeset 520693 f8086519b2089d2809822374c089d94a88b75769
parent 520692 02f562ee1c814c89fb235a5b0a20a2927e057e31
child 520694 0e08a1d7fb078cc36882b737f00da2f48f9349a6
push id111255
push userrhunt@eqrion.net
push dateFri, 27 Mar 2020 03:15:18 +0000
treeherderautoland@f8086519b208 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1624490
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1624490 - Allow ref.null in declared segments. r=lth Differential Revision: https://phabricator.services.mozilla.com/D68129
js/src/jit-test/tests/wasm/declared-segs.js
js/src/jit-test/tests/wasm/gc/ref-func.js
js/src/wasm/WasmValidate.cpp
--- a/js/src/jit-test/tests/wasm/declared-segs.js
+++ b/js/src/jit-test/tests/wasm/declared-segs.js
@@ -1,29 +1,21 @@
 // |jit-test| skip-if: !wasmBulkMemSupported() || !wasmReftypesEnabled()
 
 // Declared segments parse and validate
 wasmFullPass(`
 	(module
 		(func $f1)
 		(elem declare $f1)
+		(elem declare funcref (ref.null))
 		(func $run)
 		(export "run" (func $run))
 	)
 `);
 
-// Declared segments cannot use ref.null
-assertThrowsInstanceOf(() => {
-	new WebAssembly.Module(wasmTextToBinary(`
-		(module
-			(elem declare (ref.null))
-		)
-	`))
-}, WebAssembly.CompileError);
-
 // Declared segments cannot be used by bulk-memory operations
 function test(ins) {
 	assertErrorMessage(
 		() => wasmEvalText(`
 			(module
 				(func $f1)
 				(table 1 1 funcref)
 				(elem declare $f1)
--- a/js/src/jit-test/tests/wasm/gc/ref-func.js
+++ b/js/src/jit-test/tests/wasm/gc/ref-func.js
@@ -123,26 +123,16 @@ assertErrorMessage(() => new WebAssembly
 
 assertErrorMessage(() => new WebAssembly.Module(
     moduleWithSections([generalElemSection([{ flag: DeclaredElemExpr,
                                               typeCode: AnyrefCode,
                                               elems: [] }])])),
                    WebAssembly.CompileError,
                    /declared segment's element type must be subtype of funcref/);
 
-// declared element segment of type funcref with elemexpr can carry a null
-// value, but the null value must be rejected.
-
-assertErrorMessage(() => new WebAssembly.Module(
-    moduleWithSections([generalElemSection([{ flag: DeclaredElemExpr,
-                                              typeCode: AnyFuncCode,
-                                              elems: [[RefNullCode]] }])])),
-                   WebAssembly.CompileError,
-                   /declared element segments cannot contain ref.null/);
-
 // Test case for bug 1596026: when taking the ref.func of an imported function,
 // the value obtained should not be the JS function.  This would assert (even in
 // a release build), so the test is merely that the code runs.
 
 var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(`
   (module
     (import "m" "f" (func $f (param i32) (result i32)))
     (elem declare $f)
--- a/js/src/wasm/WasmValidate.cpp
+++ b/js/src/wasm/WasmValidate.cpp
@@ -2510,20 +2510,16 @@ static bool DecodeElemSection(Decoder& d
         }
 
         RefType initType = RefType::any();
         switch (op.b0) {
           case uint16_t(Op::RefFunc):
             initType = RefType::func();
             break;
           case uint16_t(Op::RefNull):
-            if (kind == ElemSegmentKind::Declared) {
-              return d.fail(
-                  "declared element segments cannot contain ref.null");
-            }
             initType = RefType::null();
             needIndex = false;
             break;
           default:
             return d.fail("failed to read initializer operation");
         }
         if (!env->isRefSubtypeOf(ValType(initType), ValType(elemType))) {
           return d.fail("initializer type must be subtype of element type");