Skip to content

Commit 695b6dd

Browse files
committed
Validate features for types used in tables
We previously special-cased things like GC types, but switch to a more general solution of detecting what features a table's type requires.
1 parent 67df62a commit 695b6dd

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

scripts/fuzz_opt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def is_git_repo():
363363
'shared-ref_eq.wast',
364364
'shared-types-no-gc.wast',
365365
'shared-ref-i31.wast',
366+
'table-type.wast',
366367
]
367368

368369

src/wasm/wasm-validator.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,8 +3845,7 @@ static void validateTables(Module& module, ValidationInfo& info) {
38453845
}
38463846
}
38473847

3848-
Type externref = Type(HeapType::ext, Nullable);
3849-
Type funcref = Type(HeapType::func, Nullable);
3848+
auto funcref = Type(HeapType::func, Nullable);
38503849
for (auto& table : module.tables) {
38513850
info.shouldBeTrue(table->initial <= table->max,
38523851
"table",
@@ -3855,17 +3854,13 @@ static void validateTables(Module& module, ValidationInfo& info) {
38553854
table->type.isNullable(),
38563855
"table",
38573856
"Non-nullable reference types are not yet supported for tables");
3858-
if (!module.features.hasGC()) {
3859-
info.shouldBeTrue(table->type.isFunction() || table->type == externref,
3860-
"table",
3861-
"Only function reference types or externref are valid "
3862-
"for table type (when GC is disabled)");
3863-
}
3864-
if (!module.features.hasGC()) {
3865-
info.shouldBeTrue(table->type == funcref || table->type == externref,
3866-
"table",
3867-
"Only funcref and externref are valid for table type "
3868-
"(when gc is disabled)");
3857+
auto typeFeats = table->type.getFeatures();
3858+
if (!info.shouldBeTrue(table->type == funcref ||
3859+
typeFeats <= module.features,
3860+
"table",
3861+
"table type requires additional features")) {
3862+
info.getStream(nullptr)
3863+
<< getMissingFeaturesList(module, typeFeats) << '\n';
38693864
}
38703865
if (table->is64()) {
38713866
info.shouldBeTrue(module.features.hasMemory64(),

test/lit/validation/table-type.wast

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;; Test that the features required by table types are checked
2+
3+
;; RUN: not wasm-opt %s -all --disable-shared-everything 2>&1 | filecheck %s --check-prefix NO-SHARED
4+
;; RUN: wasm-opt %s -all -S -o - | filecheck %s --check-prefix SHARED
5+
6+
;; NO-SHARED: table type requires additional features
7+
;; NO-SHARED: [--enable-shared-everything]
8+
;; SHARED: (table $t 0 0 (ref null (shared func)))
9+
10+
(module
11+
(table $t 0 0 (ref null (shared func)))
12+
)

0 commit comments

Comments
 (0)