Skip to content

Commit 79dfd9d

Browse files
committed
Validate features for types used in element segments
1 parent fb347df commit 79dfd9d

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

scripts/fuzz_opt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ def is_git_repo():
364364
'shared-types-no-gc.wast',
365365
'shared-ref-i31.wast',
366366
'table-type.wast',
367+
'elem-type.wast',
367368
]
368369

369370

src/wasm/wasm-validator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,6 +3877,14 @@ static void validateTables(Module& module, ValidationInfo& info) {
38773877
segment->type.isNullable(),
38783878
"elem",
38793879
"Non-nullable reference types are not yet supported for tables");
3880+
auto typeFeats = segment->type.getFeatures();
3881+
if (!info.shouldBeTrue(
3882+
segment->type == funcref || typeFeats <= module.features,
3883+
"elem",
3884+
"element segment type requires additional features")) {
3885+
info.getStream(nullptr)
3886+
<< getMissingFeaturesList(module, typeFeats) << '\n';
3887+
}
38803888

38813889
bool isPassive = !segment->table.is();
38823890
if (isPassive) {

test/lit/validation/elem-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 element segment 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: element segment type requires additional features
7+
;; NO-SHARED: [--enable-shared-everything]
8+
;; SHARED: (elem $e (ref null (shared func)))
9+
10+
(module
11+
(elem $e (ref null (shared func)))
12+
)

0 commit comments

Comments
 (0)