Commit d672ee30 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Fix empty asm.js function in ASM->WASM.

R=ahaas@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1574263002

Cr-Commit-Position: refs/heads/master@{#33238}
parent d00c4666
......@@ -157,8 +157,10 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
WasmModuleBuilder* mb) const {
WasmFunctionEncoder* e =
new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_);
auto var_index = new uint16_t[locals_.size()];
uint16_t* var_index = zone->NewArray<uint16_t>(locals_.size());
IndexVars(e, var_index);
if (body_.size() > 0) {
// TODO(titzer): iterate over local indexes, not the bytes.
const byte* start = &body_[0];
const byte* end = start + body_.size();
size_t local_index = 0;
......@@ -180,6 +182,7 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
i++;
}
}
}
FunctionSig::Builder sig(zone, return_type_ == kAstStmt ? 0 : 1,
e->params_.size());
if (return_type_ != kAstStmt) {
......@@ -189,7 +192,6 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
sig.AddParam(static_cast<LocalType>(e->params_[i]));
}
e->signature_index_ = mb->AddSignature(sig.Build());
delete[] var_index;
e->name_.insert(e->name_.begin(), name_.begin(), name_.end());
return e;
}
......@@ -295,9 +297,11 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
if (!external_) {
EmitUint16(header, static_cast<uint16_t>(body_.size()));
if (body_.size() > 0) {
std::memcpy(*header, &body_[0], body_.size());
(*header) += body_.size();
}
}
}
......
......@@ -4,6 +4,19 @@
// Flags: --expose-wasm
function EmptyTest() {
"use asm";
function caller() {
empty();
return 11;
}
function empty() {
}
return {caller: caller};
}
assertEquals(11, WASM.asmCompileRun(EmptyTest.toString()));
function IntTest() {
"use asm";
function sum(a, b) {
......
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