Skip to content

Validate features for types used in tables #6768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def is_git_repo():
'shared-ref_eq.wast',
'shared-types-no-gc.wast',
'shared-ref-i31.wast',
'table-type.wast',
]


Expand Down
21 changes: 8 additions & 13 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(),
Expand Down
12 changes: 12 additions & 0 deletions test/lit/validation/table-type.wast
Original file line number Diff line number Diff line change
@@ -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)))
)
Loading