Bug 1533744 - Properly gate anyref. r=luke
authorLars T Hansen <lhansen@mozilla.com>
Mon, 11 Mar 2019 16:29:11 +0000
changeset 521429 abac6267ab6281e4002d23563253994128f57bc9
parent 521428 ad21d7147c009f0bf0ddedb4f7e1713ff167a5b9
child 521430 ce4157f3f9673dc0b82f38c94b32a8c27adadbe8
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1533744
milestone67.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 1533744 - Properly gate anyref. r=luke When I removed the guard on anyref for gcTypesEnabled I should have added a couple more ifdefs so that anyref is only accepted when the reftypes are enabled. This patch adds those guards, and expands test cases that check that the feature is properly disabled to include more possible error messages. Differential Revision: https://phabricator.services.mozilla.com/D22893
js/src/jit-test/tests/wasm/gc/disabled-ref.js
js/src/jit-test/tests/wasm/gc/disabled.js
js/src/wasm/WasmValidate.h
--- a/js/src/jit-test/tests/wasm/gc/disabled-ref.js
+++ b/js/src/jit-test/tests/wasm/gc/disabled-ref.js
@@ -1,5 +1,5 @@
 // |jit-test| skip-if: wasmGcEnabled()
 
 wasmCompilationShouldFail(
     wasmTextToBinary(`(module (func (param (ref 0)) (unreachable)))`),
-    /\(ref T\) types not enabled/);
+    /\(ref T\) types not enabled|bad type/);
--- a/js/src/jit-test/tests/wasm/gc/disabled.js
+++ b/js/src/jit-test/tests/wasm/gc/disabled.js
@@ -1,13 +1,13 @@
 // |jit-test| skip-if: wasmReftypesEnabled()
 
 const { CompileError, validate } = WebAssembly;
 
-const UNRECOGNIZED_OPCODE_OR_BAD_TYPE = /unrecognized opcode|(Structure|reference) types not enabled|invalid inline block type/;
+const UNRECOGNIZED_OPCODE_OR_BAD_TYPE = /unrecognized opcode|(Structure|reference) types not enabled|invalid inline block type|bad type/;
 
 let simpleTests = [
     "(module (func (drop (ref.null))))",
     "(module (func $test (local anyref)))",
     "(module (func $test (param anyref)))",
     "(module (func $test (result anyref) (ref.null)))",
     "(module (func $test (block anyref (unreachable)) unreachable))",
     "(module (func $test (local anyref) (result i32) (ref.is_null (get_local 0))))",
--- a/js/src/wasm/WasmValidate.h
+++ b/js/src/wasm/WasmValidate.h
@@ -202,19 +202,27 @@ struct ModuleEnvironment {
     return compilerEnv->debug() == DebugEnabled::True;
   }
   bool funcIsImport(uint32_t funcIndex) const {
     return funcIndex < funcImportGlobalDataOffsets.length();
   }
   bool isRefSubtypeOf(ValType one, ValType two) const {
     MOZ_ASSERT(one.isReference());
     MOZ_ASSERT(two.isReference());
+#if defined(ENABLE_WASM_REFTYPES)
+#  if defined(ENABLE_WASM_GC)
     return one == two || two == ValType::AnyRef || one == ValType::NullRef ||
            (one.isRef() && two.isRef() && gcTypesEnabled() &&
             isStructPrefixOf(two, one));
+#  else
+    return one == two || two == ValType::AnyRef || one == ValType::NullRef;
+#  endif
+#else
+    return one == two;
+#endif
   }
 
  private:
   bool isStructPrefixOf(ValType a, ValType b) const {
     const StructType& other = types[a.refTypeIndex()].structType();
     return types[b.refTypeIndex()].structType().hasPrefix(other);
   }
 };
@@ -597,33 +605,37 @@ class Decoder {
     }
     switch (code) {
       case uint8_t(ValType::I32):
       case uint8_t(ValType::F32):
       case uint8_t(ValType::F64):
       case uint8_t(ValType::I64):
         *type = ValType::Code(code);
         return true;
+#ifdef ENABLE_WASM_REFTYPES
       case uint8_t(ValType::AnyRef):
         *type = ValType::Code(code);
         return true;
+#  ifdef ENABLE_WASM_GC
       case uint8_t(ValType::Ref): {
         if (!gcTypesEnabled) {
           return fail("(ref T) types not enabled");
         }
         uint32_t typeIndex;
         if (!readVarU32(&typeIndex)) {
           return false;
         }
         if (typeIndex >= numTypes) {
           return fail("ref index out of range");
         }
         *type = ValType(ValType::Code(code), typeIndex);
         return true;
       }
+#  endif
+#endif
       default:
         return fail("bad type");
     }
   }
   MOZ_MUST_USE bool readValType(const TypeDefVector& types, bool gcTypesEnabled,
                                 ValType* type) {
     if (!readValType(types.length(), gcTypesEnabled, type)) {
       return false;