summaryrefslogtreecommitdiff
path: root/src/tools/fuzzing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/fuzzing.h')
-rw-r--r--src/tools/fuzzing.h57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 66f175414..714e2c84b 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -423,10 +423,19 @@ private:
}
}
+ // TODO(reference-types): allow the fuzzer to create multiple tables
void setupTable() {
- wasm.table.exists = true;
- wasm.table.initial = wasm.table.max = 0;
- wasm.table.segments.emplace_back(builder.makeConst(int32_t(0)));
+ if (wasm.tables.size() > 0) {
+ auto& table = wasm.tables[0];
+ table->initial = table->max = 0;
+ table->segments.emplace_back(builder.makeConst(int32_t(0)));
+ } else {
+ auto table = builder.makeTable(
+ Names::getValidTableName(wasm, "fuzzing_table"), 0, 0);
+ table->hasExplicitName = true;
+ table->segments.emplace_back(builder.makeConst(int32_t(0)));
+ wasm.addTable(std::move(table));
+ }
}
std::map<Type, std::vector<Name>> globalsByType;
@@ -522,26 +531,27 @@ private:
}
void finalizeTable() {
- for (auto& segment : wasm.table.segments) {
- // If the offset is a global that was imported (which is ok) but no
- // longer is (not ok) we need to change that.
- if (auto* offset = segment.offset->dynCast<GlobalGet>()) {
- if (!wasm.getGlobal(offset->name)->imported()) {
- // TODO: the segments must not overlap...
- segment.offset =
- builder.makeConst(Literal::makeFromInt32(0, Type::i32));
+ for (auto& table : wasm.tables) {
+ for (auto& segment : table->segments) {
+ // If the offset is a global that was imported (which is ok) but no
+ // longer is (not ok) we need to change that.
+ if (auto* offset = segment.offset->dynCast<GlobalGet>()) {
+ if (!wasm.getGlobal(offset->name)->imported()) {
+ // TODO: the segments must not overlap...
+ segment.offset =
+ builder.makeConst(Literal::makeFromInt32(0, Type::i32));
+ }
}
+ Address maxOffset = segment.data.size();
+ if (auto* offset = segment.offset->dynCast<Const>()) {
+ maxOffset = maxOffset + offset->value.getInteger();
+ }
+ table->initial = std::max(table->initial, maxOffset);
}
- Address maxOffset = segment.data.size();
- if (auto* offset = segment.offset->dynCast<Const>()) {
- maxOffset = maxOffset + offset->value.getInteger();
- }
- wasm.table.initial = std::max(wasm.table.initial, maxOffset);
+ table->max = oneIn(2) ? Address(Table::kUnlimitedSize) : table->initial;
+ // Avoid an imported table (which the fuzz harness would need to handle).
+ table->module = table->base = Name();
}
- wasm.table.max =
- oneIn(2) ? Address(Table::kUnlimitedSize) : wasm.table.initial;
- // Avoid an imported table (which the fuzz harness would need to handle).
- wasm.table.module = wasm.table.base = Name();
}
Name HANG_LIMIT_GLOBAL;
@@ -705,7 +715,7 @@ private:
}
// add some to the table
while (oneIn(3) && !finishedInput) {
- wasm.table.segments[0].data.push_back(func->name);
+ wasm.tables[0]->segments[0].data.push_back(func->name);
}
numAddedFunctions++;
return func;
@@ -1425,7 +1435,7 @@ private:
}
Expression* makeCallIndirect(Type type) {
- auto& data = wasm.table.segments[0].data;
+ auto& data = wasm.tables[0]->segments[0].data;
if (data.empty()) {
return make(type);
}
@@ -1462,7 +1472,8 @@ private:
for (const auto& type : targetFn->sig.params) {
args.push_back(make(type));
}
- return builder.makeCallIndirect(target, args, targetFn->sig, isReturn);
+ return builder.makeCallIndirect(
+ wasm.tables[0]->name, target, args, targetFn->sig, isReturn);
}
Expression* makeCallRef(Type type) {