Commit 1cd6efe7 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][fuzzer] Generate correct tests with locals

The tests generated by --wasm-fuzzer-gen-test did not encode the locals
of functions yet. This CL fixes that.
A bit of care has to be taken to ensure that the locals are generated
in exactly the same order as in the module generated by the fuzzer.
This requires calling {addLocals} several times.

R=ahaas@chromium.org

Change-Id: I95237b0baef0731b6c164fddc8f12fa6f478e220
Reviewed-on: https://chromium-review.googlesource.com/848832
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50402}
parent 0b92e95b
......@@ -165,8 +165,26 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
<< PrintParameters(func.sig) << ", " << PrintReturns(func.sig) << ");\n";
// Add function.
os << " builder.addFunction(undefined, sig" << func.func_index << ")\n"
<< " .addBodyWithEnd([\n";
os << " builder.addFunction(undefined, sig" << func.func_index << ")\n";
// Add locals.
BodyLocalDecls decls(&tmp_zone);
DecodeLocalDecls(&decls, func_code.start(), func_code.end());
if (!decls.type_list.empty()) {
os << " ";
for (size_t pos = 0, count = 1, locals = decls.type_list.size();
pos < locals; pos += count, count = 1) {
ValueType type = decls.type_list[pos];
while (pos + count < locals && decls.type_list[pos + count] == type)
++count;
os << ".addLocals({" << WasmOpcodes::TypeName(type)
<< "_count: " << count << "})";
}
os << "\n";
}
// Add body.
os << " .addBodyWithEnd([\n";
FunctionBody func_body(func.sig, func.code.offset(), func_code.start(),
func_code.end());
......
......@@ -121,9 +121,25 @@ class WasmFunctionBuilder {
return this;
}
getNumLocals() {
let total_locals = 0;
for (let l of this.locals || []) {
for (let type of ["i32", "i64", "f32", "f64", "s128"]) {
total_locals += l[type + "_count"] || 0;
}
}
return total_locals;
}
addLocals(locals, names) {
this.locals = locals;
this.local_names = names;
const old_num_locals = this.getNumLocals();
if (!this.locals) this.locals = []
this.locals.push(locals);
if (names) {
if (!this.local_names) this.local_names = [];
const missing_names = old_num_locals - this.local_names.length;
this.local_names.push(...new Array(missing_names), ...names);
}
return this;
}
......@@ -537,9 +553,7 @@ class WasmModuleBuilder {
for (let func of wasm.functions) {
// Function body length will be patched later.
let local_decls = [];
let l = func.locals;
if (l !== undefined) {
let local_decls_count = 0;
for (let l of func.locals || []) {
if (l.i32_count > 0) {
local_decls.push({count: l.i32_count, type: kWasmI32});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment