summaryrefslogtreecommitdiff
path: root/src/tools/fuzzing/fuzzing.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-02-16 14:36:02 -0800
committerGitHub <noreply@github.com>2023-02-16 14:36:02 -0800
commite3c923554ce6f586b5fa9fe4fc76cf8780e287b0 (patch)
tree22390de26d2623ba3194810ff92144ea23e46692 /src/tools/fuzzing/fuzzing.cpp
parent70f51822318231214c435567edfbd54158097261 (diff)
downloadbinaryen-e3c923554ce6f586b5fa9fe4fc76cf8780e287b0.tar.gz
binaryen-e3c923554ce6f586b5fa9fe4fc76cf8780e287b0.tar.bz2
binaryen-e3c923554ce6f586b5fa9fe4fc76cf8780e287b0.zip
Fuzzer: Be more careful with unreachable code (#5498)
Half the time, never add any unreachable code. This ensures we run the most code we possibly can half the time, at least.
Diffstat (limited to 'src/tools/fuzzing/fuzzing.cpp')
-rw-r--r--src/tools/fuzzing/fuzzing.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index af2a34078..37de3d1da 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -31,6 +31,11 @@ namespace {
TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm,
std::vector<char>&& input)
: wasm(wasm), 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.
+ allowAddingUnreachableCode = oneIn(2);
+
// - funcref cannot be logged because referenced functions can be inlined or
// removed during optimization
// - there's no point in logging anyref because it is opaque
@@ -724,9 +729,10 @@ void TranslateToFuzzReader::mutate(Function* func) {
Modder(Module& wasm, TranslateToFuzzReader& parent)
: wasm(wasm), parent(parent) {
- // Half the time, never replace with an unreachable. The other half, do it
- // sometimes (but even so, only rarely, see below).
- allowUnreachable = parent.oneIn(2);
+ // If the parent allows it then sometimes replace with an unreachable, and
+ // sometimes not. Even if we allow it, only do it in certain functions
+ // (half the time) and only do it rarely (see below).
+ allowUnreachable = parent.allowAddingUnreachableCode && parent.oneIn(2);
}
void visitExpression(Expression* curr) {