summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-12-05 09:59:33 -0800
committerGitHub <noreply@github.com>2024-12-05 09:59:33 -0800
commit06e06ec86f7d1e91d0fa9e53cf8bb13d0e3e0df4 (patch)
tree99dac80372ca1f0ede93e1677e12e77954eb3987
parent68963739e56258057a7f0618e0375dd60ae4e124 (diff)
downloadbinaryen-06e06ec86f7d1e91d0fa9e53cf8bb13d0e3e0df4.tar.gz
binaryen-06e06ec86f7d1e91d0fa9e53cf8bb13d0e3e0df4.tar.bz2
binaryen-06e06ec86f7d1e91d0fa9e53cf8bb13d0e3e0df4.zip
[NFC] Send the closed-world flag to TranslateToFuzzReader (#7136)
This sends --closed-world to wasm-opt from the fuzzer, when we use that flag (before we just used it on optimizations, but not fuzz generation). And TranslateToFuzzReader now stores a boolean about whether we are in closed- world mode or not. This has no effect so far, and is a refactoring for a later PR, where we must generate code differently based on whether we are in closed-world mode or not.
-rwxr-xr-xscripts/fuzz_opt.py10
-rw-r--r--src/tools/fuzzing.h10
-rw-r--r--src/tools/fuzzing/fuzzing.cpp19
-rw-r--r--src/tools/wasm-opt.cpp3
4 files changed, 29 insertions, 13 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 299403837..b60a3e29a 100755
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -225,10 +225,12 @@ def randomize_fuzz_settings():
# optimizations we use to create any other wasm file.
FUZZ_OPTS += ['--dce']
- # Enclose the world much of the time when fuzzing closed-world, so that many
- # types are private and hence optimizable.
- if CLOSED_WORLD and random.random() < 0.5:
- GEN_ARGS += ['--enclose-world']
+ if CLOSED_WORLD:
+ GEN_ARGS += [CLOSED_WORLD_FLAG]
+ # Enclose the world much of the time when fuzzing closed-world, so that
+ # many types are private and hence optimizable.
+ if random.random() < 0.5:
+ GEN_ARGS += ['--enclose-world']
print('randomized settings (NaNs, OOB, legalize):', NANS, OOB, LEGALIZE)
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);
}