From 192757772adce7568fc1f3f3e733a4263b6392c6 Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Fri, 11 Sep 2020 03:04:17 +0200 Subject: Add anyref feature and type (#3109) Adds `anyref` type, which is enabled by a new feature `--enable-anyref`. This type is primarily used for testing that passes correctly handle subtype relationships so that the codebase will continue to be prepared for future subtyping. Since `--enable-anyref` is meaningless without also using `--enable-reference-types`, this PR also makes it a validation error to pass only the former (and similarly makes it a validation error to enable exception handling without enabling reference types). --- src/wasm/wasm-validator.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index c6d679a24..80c54abed 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -1363,6 +1363,7 @@ void FunctionValidator::validateMemBytes(uint8_t bytes, case Type::funcref: case Type::externref: case Type::exnref: + case Type::anyref: case Type::none: WASM_UNREACHABLE("unexpected type"); } @@ -2176,6 +2177,7 @@ void FunctionValidator::validateAlignment( case Type::funcref: case Type::externref: case Type::exnref: + case Type::anyref: case Type::none: WASM_UNREACHABLE("invalid type"); } @@ -2475,6 +2477,20 @@ static void validateModule(Module& module, ValidationInfo& info) { } } +static void validateFeatures(Module& module, ValidationInfo& info) { + if (module.features.hasAnyref()) { + info.shouldBeTrue(module.features.hasReferenceTypes(), + module.features, + "--enable-anyref requires --enable-reference-types"); + } + if (module.features.hasExceptionHandling()) { // implies exnref + info.shouldBeTrue( + module.features.hasReferenceTypes(), + module.features, + "--enable-exception-handling requires --enable-reference-types"); + } +} + // TODO: If we want the validator to be part of libwasm rather than libpasses, // then Using PassRunner::getPassDebug causes a circular dependence. We should // fix that, perhaps by moving some of the pass infrastructure into libsupport. @@ -2495,6 +2511,7 @@ bool WasmValidator::validate(Module& module, Flags flags) { validateTable(module, info); validateEvents(module, info); validateModule(module, info); + validateFeatures(module, info); } // validate additional internal IR details when in pass-debug mode if (PassRunner::getPassDebug()) { -- cgit v1.2.3