diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 4e9a6f3dd18..f12735636a2 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -194,7 +194,7 @@ class TranslateToFuzzReader { std::unordered_map> immutableGlobalsByType; std::unordered_map> importedImmutableGlobalsByType; - std::vector loggableTypes; + const std::vector loggableTypes; // The heap types we can pick from to generate instructions. std::vector interestingHeapTypes; @@ -276,7 +276,7 @@ class TranslateToFuzzReader { // overridden using another context in an RAII manner). std::unique_ptr globalParams; - std::vector atomicMemoryOrders; + const std::vector atomicMemoryOrders; public: int nesting = 0; diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index aa16e2b7833..07f8fdb8d80 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -29,35 +29,45 @@ namespace wasm { -TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm, - std::vector&& input, - bool closedWorld) - : wasm(wasm), closedWorld(closedWorld), builder(wasm), - random(std::move(input), wasm.features), - publicTypeValidator(wasm.features) { +namespace { - atomicMemoryOrders = wasm.features.hasRelaxedAtomics() - ? std::vector{MemoryOrder::AcqRel, MemoryOrder::SeqCst} - : std::vector{MemoryOrder::SeqCst}; - - haveInitialFunctions = !wasm.functions.empty(); - - loggableTypes = {Type::i32, Type::i64, Type::f32, Type::f64}; - if (wasm.features.hasSIMD()) { +std::vector getLoggableTypes(const FeatureSet& features) { + std::vector loggableTypes = { + Type::i32, Type::i64, Type::f32, Type::f64}; + if (features.hasSIMD()) { loggableTypes.push_back(Type::v128); } - if (wasm.features.hasReferenceTypes()) { - if (wasm.features.hasGC()) { + if (features.hasReferenceTypes()) { + if (features.hasGC()) { loggableTypes.push_back(Type(HeapType::any, Nullable)); loggableTypes.push_back(Type(HeapType::func, Nullable)); loggableTypes.push_back(Type(HeapType::ext, Nullable)); } - if (wasm.features.hasStackSwitching()) { + if (features.hasStackSwitching()) { loggableTypes.push_back(Type(HeapType::cont, Nullable)); } // Note: exnref traps on the JS boundary, so we cannot try to log it. } + return loggableTypes; +} + +} // namespace + +TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm, + std::vector&& input, + bool closedWorld) + : wasm(wasm), closedWorld(closedWorld), builder(wasm), + random(std::move(input), wasm.features), + loggableTypes(getLoggableTypes(wasm.features)), + atomicMemoryOrders(wasm.features.hasRelaxedAtomics() + ? std::vector{MemoryOrder::AcqRel, MemoryOrder::SeqCst} + : std::vector{MemoryOrder::SeqCst}), + + publicTypeValidator(wasm.features) { + + haveInitialFunctions = !wasm.functions.empty(); + // Setup params. Start with the defaults. globalParams = std::make_unique(*this);