Skip to content
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
2 changes: 2 additions & 0 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ def is_git_repo():
'shared-struct.wast',
'shared-array.wast',
'shared-i31.wast',
'shared-null.wast',
'shared-absheaptype.wast',
'type-ssa-shared.wast',
]

Expand Down
40 changes: 25 additions & 15 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ struct ValidationInfo {
}
};

std::string getMissingFeaturesList(Module& wasm, FeatureSet feats) {
std::stringstream ss;
bool first = true;
ss << '[';
(feats - wasm.features).iterFeatures([&](FeatureSet feat) {
if (first) {
first = false;
} else {
ss << " ";
}
ss << "--enable-" << feat.toString();
});
ss << ']';
return ss.str();
}

struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
bool isFunctionParallel() override { return true; }

Expand Down Expand Up @@ -2188,9 +2204,12 @@ void FunctionValidator::visitRefNull(RefNull* curr) {
// If we are not in a function, this is a global location like a table. We
// allow RefNull there as we represent tables that way regardless of what
// features are enabled.
shouldBeTrue(!getFunction() || getModule()->features.hasReferenceTypes(),
curr,
"ref.null requires reference-types [--enable-reference-types]");
auto feats = curr->type.getFeatures();
if (!shouldBeTrue(!getFunction() || feats <= getModule()->features,
curr,
"ref.null requires additional features")) {
getStream() << getMissingFeaturesList(*getModule(), feats) << '\n';
}
if (!shouldBeTrue(
curr->type.isNullable(), curr, "ref.null types must be nullable")) {
return;
Expand Down Expand Up @@ -3711,18 +3730,9 @@ static void validateGlobals(Module& module, ValidationInfo& info) {
for (auto& g : module.globals) {
auto globalFeats = g->type.getFeatures();
if (!info.shouldBeTrue(globalFeats <= module.features, g->name, "")) {
auto& stream = info.getStream(nullptr);
stream << "global type requires additional features [";
bool first = true;
(globalFeats - module.features).iterFeatures([&](FeatureSet feat) {
if (first) {
first = false;
} else {
stream << " ";
}
stream << "--enable-" << feat.toString();
});
stream << "]\n";
info.getStream(nullptr)
<< "global type requires additional features "
<< getMissingFeaturesList(module, globalFeats) << '\n';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/lit/validation/shared-absheaptype.wast
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; Test that shared structs require shared-everything threads
;; Test that shared basic heap types require shared-everything threads

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-SHARED
;; RUN: wasm-opt %s --enable-reference-types --enable-gc --enable-shared-everything -o - -S | filecheck %s --check-prefix SHARED
Expand Down
12 changes: 12 additions & 0 deletions test/lit/validation/shared-null.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; Test that shared nulls require shared-everything threads

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-SHARED
;; RUN: wasm-opt %s --enable-reference-types --enable-gc --enable-shared-everything -o - -S | filecheck %s --check-prefix SHARED

;; NO-SHARED: ref.null requires additional features
;; NO-SHARED: [--enable-reference-types --enable-shared-everything]
;; SHARED: (ref.null (shared none))

(module
(func (drop (ref.null (shared none))))
)