diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/fuzzing.h | 10 | ||||
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 19 | ||||
-rw-r--r-- | src/tools/wasm-opt.cpp | 3 |
3 files changed, 23 insertions, 9 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 1afb4bf36..a3261ccbe 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -65,8 +65,12 @@ struct BinaryArgs { class TranslateToFuzzReader { public: - TranslateToFuzzReader(Module& wasm, std::vector<char>&& input); - TranslateToFuzzReader(Module& wasm, std::string& filename); + TranslateToFuzzReader(Module& wasm, + std::vector<char>&& input, + bool closedWorld = false); + TranslateToFuzzReader(Module& wasm, + std::string& filename, + bool closedWorld = false); void pickPasses(OptimizationOptions& options); void setAllowMemory(bool allowMemory_) { allowMemory = allowMemory_; } @@ -77,6 +81,8 @@ public: Module& wasm; private: + // Whether the module will be tested in a closed-world environment. + bool closedWorld; Builder builder; Random random; diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 7e87f4f58..ab200a126 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -32,8 +32,10 @@ namespace { } // anonymous namespace TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm, - std::vector<char>&& input) - : wasm(wasm), builder(wasm), random(std::move(input), wasm.features) { + std::vector<char>&& input, + bool closedWorld) + : wasm(wasm), closedWorld(closedWorld), builder(wasm), + random(std::move(input), wasm.features) { // Half the time add no unreachable code so that we'll execute the most code // as possible with no early exits. @@ -50,9 +52,11 @@ TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm, } TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm, - std::string& filename) - : TranslateToFuzzReader( - wasm, read_file<std::vector<char>>(filename, Flags::Binary)) {} + std::string& filename, + bool closedWorld) + : TranslateToFuzzReader(wasm, + read_file<std::vector<char>>(filename, Flags::Binary), + closedWorld) {} void TranslateToFuzzReader::pickPasses(OptimizationOptions& options) { // Pick random passes to further shape the wasm. This is similar to how we @@ -197,8 +201,11 @@ void TranslateToFuzzReader::pickPasses(OptimizationOptions& options) { case 41: // GC specific passes. if (wasm.features.hasGC()) { - // Most of these depend on closed world, so just set that. + // Most of these depend on closed world, so just set that. Set it both + // on the global pass options, and in the internal state of this + // TranslateToFuzzReader instance. options.passOptions.closedWorld = true; + closedWorld = true; switch (upTo(16)) { case 0: diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp index 3e429a976..2f8d22580 100644 --- a/src/tools/wasm-opt.cpp +++ b/src/tools/wasm-opt.cpp @@ -303,7 +303,8 @@ int main(int argc, const char* argv[]) { } } if (translateToFuzz) { - TranslateToFuzzReader reader(wasm, options.extra["infile"]); + TranslateToFuzzReader reader( + wasm, options.extra["infile"], options.passOptions.closedWorld); if (fuzzPasses) { reader.pickPasses(options); } |