summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-07-18 16:39:15 -0400
committerGitHub <noreply@github.com>2024-07-18 13:39:15 -0700
commita744bec7bc744182822c6b86aa3159d08dea0b3c (patch)
tree508e624342d4c52bbbeb7e377509c66408c9b303
parentfd867a3865d079b7f9c8ec1c7fc6d02a4de28b4c (diff)
downloadbinaryen-a744bec7bc744182822c6b86aa3159d08dea0b3c.tar.gz
binaryen-a744bec7bc744182822c6b86aa3159d08dea0b3c.tar.bz2
binaryen-a744bec7bc744182822c6b86aa3159d08dea0b3c.zip
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.
-rwxr-xr-xscripts/fuzz_opt.py1
-rw-r--r--src/wasm/wasm-validator.cpp21
-rw-r--r--test/lit/validation/table-type.wast12
3 files changed, 21 insertions, 13 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 0f3bc3f3f..9036c338f 100755
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -363,6 +363,7 @@ INITIAL_CONTENTS_IGNORE = [
'shared-ref_eq.wast',
'shared-types-no-gc.wast',
'shared-ref-i31.wast',
+ 'table-type.wast',
]
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(),
diff --git a/test/lit/validation/table-type.wast b/test/lit/validation/table-type.wast
new file mode 100644
index 000000000..e00e8f533
--- /dev/null
+++ b/test/lit/validation/table-type.wast
@@ -0,0 +1,12 @@
+;; Test that the features required by table types are checked
+
+;; RUN: not wasm-opt %s -all --disable-shared-everything 2>&1 | filecheck %s --check-prefix NO-SHARED
+;; RUN: wasm-opt %s -all -S -o - | filecheck %s --check-prefix SHARED
+
+;; NO-SHARED: table type requires additional features
+;; NO-SHARED: [--enable-shared-everything]
+;; SHARED: (table $t 0 0 (ref null (shared func)))
+
+(module
+ (table $t 0 0 (ref null (shared func)))
+)