diff options
author | Alon Zakai <azakai@google.com> | 2020-10-12 14:54:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 14:54:26 -0700 |
commit | d38ddda4c299a40ee48efb777ec69c823312c9dd (patch) | |
tree | 40426b25c3f97c01c0a6a0db2c29020a1c6dae51 /src/tools/fuzzing.h | |
parent | 9d6413cd2d504684d026bdec27e2d030d4c60598 (diff) | |
download | binaryen-d38ddda4c299a40ee48efb777ec69c823312c9dd.tar.gz binaryen-d38ddda4c299a40ee48efb777ec69c823312c9dd.tar.bz2 binaryen-d38ddda4c299a40ee48efb777ec69c823312c9dd.zip |
Fuzzer: Do not emit random global.get/sets of the hang limit global (#3229)
That global is for internal use. If we emit random sets to it, we could prevent
it from doing its job of preventing an infinite loop (normally it decreases each
time a loop runs or we recurse, until we reach 0 - if we set it to a nonzero
value in that code, that would be bad).
Random gets are less of a problem, but may be confusing when debugging
a testcase.
Diffstat (limited to 'src/tools/fuzzing.h')
-rw-r--r-- | src/tools/fuzzing.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 4fe356931..d2cdb7a7f 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -1261,12 +1261,21 @@ private: } } + // Some globals are for internal use, and should not be modified by random + // fuzz code. + bool isValidGlobal(Name name) { return name != HANG_LIMIT_GLOBAL; } + Expression* makeGlobalGet(Type type) { auto it = globalsByType.find(type); if (it == globalsByType.end() || it->second.empty()) { return makeConst(type); } - return builder.makeGlobalGet(pick(it->second), type); + auto name = pick(it->second); + if (isValidGlobal(name)) { + return builder.makeGlobalGet(name, type); + } else { + return makeTrivial(type); + } } Expression* makeGlobalSet(Type type) { @@ -1276,8 +1285,12 @@ private: if (it == globalsByType.end() || it->second.empty()) { return makeTrivial(Type::none); } - auto* value = make(type); - return builder.makeGlobalSet(pick(it->second), value); + auto name = pick(it->second); + if (isValidGlobal(name)) { + return builder.makeGlobalSet(name, make(type)); + } else { + return makeTrivial(Type::none); + } } Expression* makeTupleMake(Type type) { |