summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/fuzz_opt.py1
-rw-r--r--src/wasm/wasm-validator.cpp8
-rw-r--r--test/lit/validation/elem-type.wast12
3 files changed, 21 insertions, 0 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 9036c338f..f49234035 100755
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -364,6 +364,7 @@ INITIAL_CONTENTS_IGNORE = [
'shared-types-no-gc.wast',
'shared-ref-i31.wast',
'table-type.wast',
+ 'elem-type.wast',
]
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index a191d2bdd..9994adf1e 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -3877,6 +3877,14 @@ static void validateTables(Module& module, ValidationInfo& info) {
segment->type.isNullable(),
"elem",
"Non-nullable reference types are not yet supported for tables");
+ auto typeFeats = segment->type.getFeatures();
+ if (!info.shouldBeTrue(
+ segment->type == funcref || typeFeats <= module.features,
+ "elem",
+ "element segment type requires additional features")) {
+ info.getStream(nullptr)
+ << getMissingFeaturesList(module, typeFeats) << '\n';
+ }
bool isPassive = !segment->table.is();
if (isPassive) {
diff --git a/test/lit/validation/elem-type.wast b/test/lit/validation/elem-type.wast
new file mode 100644
index 000000000..c98593aba
--- /dev/null
+++ b/test/lit/validation/elem-type.wast
@@ -0,0 +1,12 @@
+;; Test that the features required by element segment 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: element segment type requires additional features
+;; NO-SHARED: [--enable-shared-everything]
+;; SHARED: (elem $e (ref null (shared func)))
+
+(module
+ (elem $e (ref null (shared func)))
+)