diff options
author | Alon Zakai <azakai@google.com> | 2023-07-10 15:23:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-10 15:23:36 -0700 |
commit | f1f3f4a504ac1ec1bcd85c86622786a90b3fd9b3 (patch) | |
tree | 46a5bdd1e034e7bd2136b09b05b187ba720ffdb7 /src/tools/fuzzing | |
parent | 0d3bb31a37e151a7d4dcf32575f5789f0a3818ce (diff) | |
download | binaryen-f1f3f4a504ac1ec1bcd85c86622786a90b3fd9b3.tar.gz binaryen-f1f3f4a504ac1ec1bcd85c86622786a90b3fd9b3.tar.bz2 binaryen-f1f3f4a504ac1ec1bcd85c86622786a90b3fd9b3.zip |
Fuzzer: Emit more variations of If (#5806)
Before we always created if-elses. Now we also create an If with one arm some of
the time, when we can.
Also, sometimes make one if arm unreachable, if we have two arms.
Diffstat (limited to 'src/tools/fuzzing')
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 7bfd07854..8df9b9afc 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -1363,8 +1363,30 @@ Expression* TranslateToFuzzReader::buildIf(const struct ThreeArgs& args, Expression* TranslateToFuzzReader::makeIf(Type type) { auto* condition = makeCondition(); funcContext->hangStack.push_back(nullptr); - auto* ret = - buildIf({condition, makeMaybeBlock(type), makeMaybeBlock(type)}, type); + + Expression* ret; + if (type == Type::none && oneIn(2)) { + // Just an ifTrue arm. + ret = buildIf({condition, makeMaybeBlock(type), nullptr}, type); + } else { + // Also an ifFalse arm. + + // Some of the time make one arm unreachable (but not both, as then the if + // as a whole would be unreachable). + auto trueType = type; + auto falseType = type; + switch (upTo(20)) { + case 0: + trueType = Type::unreachable; + break; + case 1: + falseType = Type::unreachable; + break; + } + ret = buildIf( + {condition, makeMaybeBlock(trueType), makeMaybeBlock(falseType)}, type); + } + funcContext->hangStack.pop_back(); return ret; } |