summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/fuzzing.h4
-rw-r--r--src/tools/fuzzing/fuzzing.cpp12
-rw-r--r--test/passes/translate-to-fuzz_all-features_metrics_noprint.txt60
3 files changed, 47 insertions, 29 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index f055d7f44..c0f6ab335 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -271,6 +271,10 @@ private:
// Make something with no chance of infinite recursion.
Expression* makeTrivial(Type type);
+ // We must note when we are nested in a makeTrivial() call. When we are, all
+ // operations must try to be as trivial as possible.
+ int trivialNesting = 0;
+
// Specific expression creators
Expression* makeBlock(Type type);
Expression* makeLoop(Type type);
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index 1c2b818df..d062dd5c8 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -1060,6 +1060,10 @@ void TranslateToFuzzReader::addInvocations(Function* func) {
Expression* TranslateToFuzzReader::make(Type type) {
auto subtype = getSubType(type);
+ if (trivialNesting) {
+ // We are nested under a makeTrivial call, so only emit something trivial.
+ return makeTrivial(type);
+ }
// When we should stop, emit something small (but not necessarily trivial).
if (random.finished() || nesting >= 5 * NESTING_LIMIT || // hard limit
(nesting >= NESTING_LIMIT && !oneIn(3))) {
@@ -1226,6 +1230,14 @@ Expression* TranslateToFuzzReader::_makeunreachable() {
}
Expression* TranslateToFuzzReader::makeTrivial(Type type) {
+ struct TrivialNester {
+ TranslateToFuzzReader& parent;
+ TrivialNester(TranslateToFuzzReader& parent) : parent(parent) {
+ parent.trivialNesting++;
+ }
+ ~TrivialNester() { parent.trivialNesting--; }
+ } nester(*this);
+
if (type.isConcrete()) {
if (oneIn(2) && funcContext) {
return makeLocalGet(type);
diff --git a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
index 6d2aba469..92b1fc834 100644
--- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
+++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
@@ -1,43 +1,45 @@
total
- [exports] : 4
- [funcs] : 11
+ [exports] : 2
+ [funcs] : 10
[globals] : 16
[imports] : 5
[memories] : 1
[memory-data] : 20
- [table-data] : 2
+ [table-data] : 5
[tables] : 1
[tags] : 2
- [total] : 521
- [vars] : 21
- ArrayLen : 1
- ArrayNew : 6
- ArrayNewFixed : 1
- ArraySet : 1
+ [total] : 500
+ [vars] : 9
+ ArrayNew : 5
+ AtomicCmpxchg : 1
+ AtomicFence : 2
+ AtomicNotify : 2
Binary : 66
- Block : 58
- Break : 3
- Call : 7
- Const : 117
- Drop : 4
- GlobalGet : 32
- GlobalSet : 32
+ Block : 49
+ Break : 5
+ Call : 4
+ Const : 121
+ Drop : 1
+ GlobalGet : 25
+ GlobalSet : 24
I31New : 2
- If : 19
+ If : 16
Load : 17
- LocalGet : 41
- LocalSet : 23
- Loop : 6
- Nop : 3
- RefAs : 4
- RefEq : 1
+ LocalGet : 40
+ LocalSet : 28
+ Loop : 3
+ Nop : 9
+ RefAs : 2
+ RefEq : 2
RefFunc : 10
RefNull : 8
- Return : 1
- Select : 1
- StructNew : 5
+ RefTest : 1
+ Return : 2
+ SIMDExtract : 2
+ Select : 4
+ StructNew : 8
StructSet : 1
TupleExtract : 1
- TupleMake : 9
- Unary : 22
- Unreachable : 19
+ TupleMake : 8
+ Unary : 16
+ Unreachable : 15