Skip to content

Commit 06e06ec

Browse files
authored
[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.
1 parent 6896373 commit 06e06ec

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

scripts/fuzz_opt.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ def randomize_fuzz_settings():
225225
# optimizations we use to create any other wasm file.
226226
FUZZ_OPTS += ['--dce']
227227

228-
# Enclose the world much of the time when fuzzing closed-world, so that many
229-
# types are private and hence optimizable.
230-
if CLOSED_WORLD and random.random() < 0.5:
231-
GEN_ARGS += ['--enclose-world']
228+
if CLOSED_WORLD:
229+
GEN_ARGS += [CLOSED_WORLD_FLAG]
230+
# Enclose the world much of the time when fuzzing closed-world, so that
231+
# many types are private and hence optimizable.
232+
if random.random() < 0.5:
233+
GEN_ARGS += ['--enclose-world']
232234

233235
print('randomized settings (NaNs, OOB, legalize):', NANS, OOB, LEGALIZE)
234236

src/tools/fuzzing.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ struct BinaryArgs {
6565

6666
class TranslateToFuzzReader {
6767
public:
68-
TranslateToFuzzReader(Module& wasm, std::vector<char>&& input);
69-
TranslateToFuzzReader(Module& wasm, std::string& filename);
68+
TranslateToFuzzReader(Module& wasm,
69+
std::vector<char>&& input,
70+
bool closedWorld = false);
71+
TranslateToFuzzReader(Module& wasm,
72+
std::string& filename,
73+
bool closedWorld = false);
7074

7175
void pickPasses(OptimizationOptions& options);
7276
void setAllowMemory(bool allowMemory_) { allowMemory = allowMemory_; }
@@ -77,6 +81,8 @@ class TranslateToFuzzReader {
7781
Module& wasm;
7882

7983
private:
84+
// Whether the module will be tested in a closed-world environment.
85+
bool closedWorld;
8086
Builder builder;
8187
Random random;
8288

src/tools/fuzzing/fuzzing.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ namespace {
3232
} // anonymous namespace
3333

3434
TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm,
35-
std::vector<char>&& input)
36-
: wasm(wasm), builder(wasm), random(std::move(input), wasm.features) {
35+
std::vector<char>&& input,
36+
bool closedWorld)
37+
: wasm(wasm), closedWorld(closedWorld), builder(wasm),
38+
random(std::move(input), wasm.features) {
3739

3840
// Half the time add no unreachable code so that we'll execute the most code
3941
// as possible with no early exits.
@@ -50,9 +52,11 @@ TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm,
5052
}
5153

5254
TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm,
53-
std::string& filename)
54-
: TranslateToFuzzReader(
55-
wasm, read_file<std::vector<char>>(filename, Flags::Binary)) {}
55+
std::string& filename,
56+
bool closedWorld)
57+
: TranslateToFuzzReader(wasm,
58+
read_file<std::vector<char>>(filename, Flags::Binary),
59+
closedWorld) {}
5660

5761
void TranslateToFuzzReader::pickPasses(OptimizationOptions& options) {
5862
// Pick random passes to further shape the wasm. This is similar to how we
@@ -197,8 +201,11 @@ void TranslateToFuzzReader::pickPasses(OptimizationOptions& options) {
197201
case 41:
198202
// GC specific passes.
199203
if (wasm.features.hasGC()) {
200-
// Most of these depend on closed world, so just set that.
204+
// Most of these depend on closed world, so just set that. Set it both
205+
// on the global pass options, and in the internal state of this
206+
// TranslateToFuzzReader instance.
201207
options.passOptions.closedWorld = true;
208+
closedWorld = true;
202209

203210
switch (upTo(16)) {
204211
case 0:

src/tools/wasm-opt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ int main(int argc, const char* argv[]) {
303303
}
304304
}
305305
if (translateToFuzz) {
306-
TranslateToFuzzReader reader(wasm, options.extra["infile"]);
306+
TranslateToFuzzReader reader(
307+
wasm, options.extra["infile"], options.passOptions.closedWorld);
307308
if (fuzzPasses) {
308309
reader.pickPasses(options);
309310
}

0 commit comments

Comments
 (0)