From ffe4152320b4d72fbfc9c350abda922067ebec01 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 15 Mar 2023 13:57:01 -0700 Subject: Fuzzer: Generate both immutable and mutable globals (#5575) --- src/tools/fuzzing/fuzzing.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/tools/fuzzing/fuzzing.cpp') 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); -- cgit v1.2.3