From 75a120af238ccf0404c4e1e2d9a7474ec734b9dd Mon Sep 17 00:00:00 2001 From: stevenfontanella Date: Fri, 30 Jan 2026 18:28:08 +0000 Subject: [PATCH] Use member initializer --- src/tools/fuzzing.h | 4 ++-- src/tools/fuzzing/fuzzing.cpp | 39 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-) 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 6c21d939d1f..d7d4c305b60 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -29,27 +29,40 @@ namespace wasm { +namespace { +template +std::vector concat(const std::vector a, const std::vector b) { + auto added = a; + std::copy(b.begin(), b.end(), std::back_inserter(added)); + return added; +} +} // namespace + TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm, std::vector&& input, bool closedWorld) : wasm(wasm), closedWorld(closedWorld), builder(wasm), random(std::move(input), wasm.features), - publicTypeValidator(wasm.features) { - - atomicMemoryOrders = wasm.features.hasRelaxedAtomics() + // - funcref cannot be logged because referenced functions can be inlined or + // removed during optimization + // - there's no point in logging anyref because it is opaque + // - don't bother logging tuples + loggableTypes(concat( + std::vector{ + Type::i32, + Type::i64, + Type::f32, + Type::f64, + }, + wasm.features.hasSIMD() ? std::vector{Type::v128} + : std::vector())), + atomicMemoryOrders(wasm.features.hasRelaxedAtomics() ? std::vector{MemoryOrder::AcqRel, MemoryOrder::SeqCst} - : std::vector{MemoryOrder::SeqCst}; + : std::vector{MemoryOrder::SeqCst}), - haveInitialFunctions = !wasm.functions.empty(); + publicTypeValidator(wasm.features) { - // - funcref cannot be logged because referenced functions can be inlined or - // removed during optimization - // - there's no point in logging anyref because it is opaque - // - don't bother logging tuples - loggableTypes = {Type::i32, Type::i64, Type::f32, Type::f64}; - if (wasm.features.hasSIMD()) { - loggableTypes.push_back(Type::v128); - } + haveInitialFunctions = !wasm.functions.empty(); // Setup params. Start with the defaults. globalParams = std::make_unique(*this);