Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tools/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class TranslateToFuzzReader {
std::unordered_map<Type, std::vector<Name>> immutableGlobalsByType;
std::unordered_map<Type, std::vector<Name>> importedImmutableGlobalsByType;

std::vector<Type> loggableTypes;
const std::vector<Type> loggableTypes;

// The heap types we can pick from to generate instructions.
std::vector<HeapType> interestingHeapTypes;
Expand Down Expand Up @@ -276,7 +276,7 @@ class TranslateToFuzzReader {
// overridden using another context in an RAII manner).
std::unique_ptr<FuzzParamsContext> globalParams;

std::vector<MemoryOrder> atomicMemoryOrders;
const std::vector<MemoryOrder> atomicMemoryOrders;

public:
int nesting = 0;
Expand Down
39 changes: 26 additions & 13 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,40 @@

namespace wasm {

namespace {
template<typename T>
std::vector<T> concat(const std::vector<T> a, const std::vector<T> b) {
auto added = a;
std::copy(b.begin(), b.end(), std::back_inserter(added));
return added;
}
} // namespace

TranslateToFuzzReader::TranslateToFuzzReader(Module& wasm,
std::vector<char>&& 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to do this that doesn't put as much logic into the initializer list is to call out to static methods that return the initialized members.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, that sounds like it might read better.

std::vector<Type>{
Type::i32,
Type::i64,
Type::f32,
Type::f64,
},
wasm.features.hasSIMD() ? std::vector<Type>{Type::v128}
: std::vector<Type>())),
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<FuzzParamsContext>(*this);
Expand Down
Loading