diff options
-rw-r--r-- | src/tools/fuzzing.h | 1 | ||||
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 10 | ||||
-rw-r--r-- | test/passes/fuzz_metrics_noprint.bin.txt | 53 | ||||
-rw-r--r-- | test/passes/translate-to-fuzz_all-features_metrics_noprint.txt | 70 |
4 files changed, 68 insertions, 66 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index d761bc3bd..b8be67499 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -106,6 +106,7 @@ private: Name funcrefTableName; std::unordered_map<Type, std::vector<Name>> globalsByType; + std::unordered_map<Type, std::vector<Name>> mutableGlobalsByType; std::vector<Type> loggableTypes; diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 75eb3bd21..9beedc7fd 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -358,9 +358,13 @@ void TranslateToFuzzReader::setupGlobals() { type = getMVPType(); init = makeConst(type); } + auto mutability = oneIn(2) ? Builder::Mutable : Builder::Immutable; auto global = builder.makeGlobal( - Names::getValidGlobalName(wasm, "global$"), type, init, Builder::Mutable); + Names::getValidGlobalName(wasm, "global$"), type, init, mutability); globalsByType[type].push_back(global->name); + if (mutability == Builder::Mutable) { + mutableGlobalsByType[type].push_back(global->name); + } wasm.addGlobal(std::move(global)); } } @@ -1489,8 +1493,8 @@ Expression* TranslateToFuzzReader::makeGlobalGet(Type type) { Expression* TranslateToFuzzReader::makeGlobalSet(Type type) { assert(type == Type::none); type = getConcreteType(); - auto it = globalsByType.find(type); - if (it == globalsByType.end() || it->second.empty()) { + auto it = mutableGlobalsByType.find(type); + if (it == mutableGlobalsByType.end() || it->second.empty()) { return makeTrivial(Type::none); } auto name = pick(it->second); diff --git a/test/passes/fuzz_metrics_noprint.bin.txt b/test/passes/fuzz_metrics_noprint.bin.txt index 700359899..a7ed16447 100644 --- a/test/passes/fuzz_metrics_noprint.bin.txt +++ b/test/passes/fuzz_metrics_noprint.bin.txt @@ -1,34 +1,33 @@ total - [exports] : 59 - [funcs] : 86 + [exports] : 37 + [funcs] : 53 [globals] : 9 [imports] : 4 [memories] : 1 [memory-data] : 2 - [table-data] : 34 + [table-data] : 11 [tables] : 1 [tags] : 0 - [total] : 9333 - [vars] : 265 - Binary : 675 - Block : 1567 - Break : 310 - Call : 441 - CallIndirect : 68 - Const : 1667 - Drop : 68 - GlobalGet : 735 - GlobalSet : 594 - If : 514 - Load : 144 - LocalGet : 542 - LocalSet : 431 - Loop : 197 - Nop : 167 - RefFunc : 34 - Return : 84 - Select : 65 - Store : 80 - Switch : 2 - Unary : 660 - Unreachable : 288 + [total] : 3757 + [vars] : 140 + Binary : 290 + Block : 638 + Break : 92 + Call : 200 + CallIndirect : 22 + Const : 707 + Drop : 45 + GlobalGet : 300 + GlobalSet : 253 + If : 198 + Load : 57 + LocalGet : 176 + LocalSet : 149 + Loop : 69 + Nop : 81 + RefFunc : 11 + Return : 49 + Select : 27 + Store : 30 + Unary : 240 + Unreachable : 123 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 595dff648..491b273a3 100644 --- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt +++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt @@ -1,46 +1,44 @@ total - [exports] : 9 - [funcs] : 21 + [exports] : 12 + [funcs] : 22 [globals] : 5 [imports] : 5 [memories] : 1 [memory-data] : 20 - [table-data] : 5 + [table-data] : 9 [tables] : 1 - [tags] : 1 - [total] : 738 - [vars] : 16 - ArrayNew : 8 - ArrayNewFixed : 3 - Binary : 82 - Block : 89 - Break : 7 + [tags] : 0 + [total] : 781 + [vars] : 35 + ArrayNew : 4 + ArrayNewFixed : 1 + AtomicNotify : 1 + Binary : 90 + Block : 118 + Break : 8 Call : 25 CallIndirect : 1 - CallRef : 1 - Const : 168 - Drop : 10 - GlobalGet : 40 - GlobalSet : 40 - I31New : 2 - If : 29 - Load : 19 - LocalGet : 48 - LocalSet : 29 - Loop : 3 - MemoryCopy : 1 - MemoryInit : 2 + CallRef : 2 + Const : 171 + Drop : 8 + GlobalGet : 56 + GlobalSet : 56 + I31New : 3 + If : 36 + Load : 21 + LocalGet : 36 + LocalSet : 17 + Loop : 8 Nop : 11 - RefAs : 2 - RefFunc : 21 - RefIsNull : 1 - RefNull : 6 - Return : 8 + RefAs : 1 + RefFunc : 16 + RefNull : 4 + Return : 6 SIMDExtract : 2 - Select : 2 - Store : 1 - StructNew : 7 - TupleExtract : 5 - TupleMake : 10 - Unary : 31 - Unreachable : 24 + Select : 1 + Store : 6 + StructNew : 4 + Switch : 1 + TupleMake : 3 + Unary : 33 + Unreachable : 31 |