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 src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void PassRunner::run() {
// validate, ignoring the time
std::cerr << "[PassRunner] (validating)\n";
if (!WasmValidator().validate(*wasm, options.features, validationFlags)) {
WasmPrinter::printModule(wasm);
if (passDebug >= 2) {
std::cerr << "Last pass (" << pass->name << ") broke validation. Here is the module before: \n" << moduleBefore.str() << "\n";
} else {
Expand All @@ -247,6 +248,7 @@ void PassRunner::run() {
// validate
std::cerr << "[PassRunner] (final validation)\n";
if (!WasmValidator().validate(*wasm, options.features, validationFlags)) {
WasmPrinter::printModule(wasm);
std::cerr << "final module does not validate\n";
abort();
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/asm2wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ int main(int argc, const char *argv[]) {
}

if (!WasmValidator().validate(wasm, options.passOptions.features)) {
WasmPrinter::printModule(&wasm);
Fatal() << "error in validating output";
}

Expand Down
4 changes: 3 additions & 1 deletion src/tools/s2wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ int main(int argc, const char *argv[]) {

if (options.extra["validate"] != "none") {
if (options.debug) std::cerr << "Validating..." << std::endl;
if (!wasm::WasmValidator().validate(linker.getOutput().wasm,
Module* output = &linker.getOutput().wasm;
if (!wasm::WasmValidator().validate(*output,
WasmValidator::Globally | (options.extra["validate"] == "web" ? WasmValidator::Web : 0))) {
WasmPrinter::printModule(output);
Fatal() << "Error: linked module is not valid.\n";
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/wasm-as.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "Validating..." << std::endl;
if (!wasm::WasmValidator().validate(wasm, Feature::All,
WasmValidator::Globally | (options.extra["validate"] == "web" ? WasmValidator::Web : 0))) {
WasmPrinter::printModule(&wasm);
Fatal() << "Error: input module is not valid.\n";
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/wasm-merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ int main(int argc, const char* argv[]) {
}

if (!WasmValidator().validate(output)) {
WasmPrinter::printModule(&output);
Fatal() << "error in validating output";
}

Expand Down
14 changes: 12 additions & 2 deletions src/tools/wasm-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ int main(int argc, const char* argv[]) {
}

if (!WasmValidator().validate(wasm, features)) {
WasmPrinter::printModule(&wasm);
Fatal() << "error in validating input";
}
} else {
// translate-to-fuzz
TranslateToFuzzReader reader(wasm);
reader.read(options.extra["infile"]);
if (!WasmValidator().validate(wasm, features)) {
WasmPrinter::printModule(&wasm);
std::cerr << "translate-to-fuzz must always generate a valid module";
abort();
}
Expand Down Expand Up @@ -176,7 +178,11 @@ int main(int argc, const char* argv[]) {
if (options.runningPasses()) {
if (options.debug) std::cerr << "running passes...\n";
options.runPasses(wasm);
assert(WasmValidator().validate(wasm, features));
bool valid = WasmValidator().validate(wasm, features);
if (!valid) {
WasmPrinter::printModule(&wasm);
}
assert(valid);
}

if (fuzzExec) {
Expand All @@ -192,7 +198,11 @@ int main(int argc, const char* argv[]) {
auto input = buffer.getAsChars();
WasmBinaryBuilder parser(second, input, false);
parser.read();
assert(WasmValidator().validate(second, features));
bool valid = WasmValidator().validate(second, features);
if (!valid) {
WasmPrinter::printModule(&second);
}
assert(valid);
}
results.check(*compare);
}
Expand Down
6 changes: 5 additions & 1 deletion src/tools/wasm-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ int main(int argc, const char* argv[]) {
builders[moduleName].swap(builder);
modules[moduleName].swap(module);
i++;
assert(WasmValidator().validate(*modules[moduleName]));
bool valid = WasmValidator().validate(*modules[moduleName]);
if (!valid) {
WasmPrinter::printModule(modules[moduleName].get());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this does change the semantics, before it would not even check if assertions are off. But I see no downside to making this change, probably better actually.

}
assert(valid);
run_asserts(moduleName, &i, &checked, modules[moduleName].get(), &root, builders[moduleName].get(), entry);
} else {
run_asserts(Name(), &i, &checked, nullptr, &root, nullptr, entry);
Expand Down
2 changes: 0 additions & 2 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,6 @@ bool WasmValidator::validate(Module& module, FeatureSet features, Flags flags) {
std::cerr << info.getStream(func.get()).str();
}
std::cerr << info.getStream(nullptr).str();
// also print the module
WasmPrinter::printModule(&module, std::cerr);
}
return info.valid.load();
}
Expand Down