From a744bec7bc744182822c6b86aa3159d08dea0b3c Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 18 Jul 2024 16:39:15 -0400 Subject: Validate features for types used in tables (#6768) We previously special-cased things like GC types, but switch to a more general solution of detecting what features a table's type requires. --- src/wasm/wasm-validator.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 4e167df56..a191d2bdd 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -3845,8 +3845,7 @@ static void validateTables(Module& module, ValidationInfo& info) { } } - Type externref = Type(HeapType::ext, Nullable); - Type funcref = Type(HeapType::func, Nullable); + auto funcref = Type(HeapType::func, Nullable); for (auto& table : module.tables) { info.shouldBeTrue(table->initial <= table->max, "table", @@ -3855,17 +3854,13 @@ static void validateTables(Module& module, ValidationInfo& info) { table->type.isNullable(), "table", "Non-nullable reference types are not yet supported for tables"); - if (!module.features.hasGC()) { - info.shouldBeTrue(table->type.isFunction() || table->type == externref, - "table", - "Only function reference types or externref are valid " - "for table type (when GC is disabled)"); - } - if (!module.features.hasGC()) { - info.shouldBeTrue(table->type == funcref || table->type == externref, - "table", - "Only funcref and externref are valid for table type " - "(when gc is disabled)"); + auto typeFeats = table->type.getFeatures(); + if (!info.shouldBeTrue(table->type == funcref || + typeFeats <= module.features, + "table", + "table type requires additional features")) { + info.getStream(nullptr) + << getMissingFeaturesList(module, typeFeats) << '\n'; } if (table->is64()) { info.shouldBeTrue(module.features.hasMemory64(), -- cgit v1.2.3