Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Unified Diff: src/wasm/encoder.cc

Issue 1574263002: [wasm] Fix empty asm.js function in ASM->WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/encoder.cc
diff --git a/src/wasm/encoder.cc b/src/wasm/encoder.cc
index a1dd24ac16114a636873d643c4405497a06be4ed..cba3e38fddd5ce8499360b46eb9eaa2ca88e6581 100644
--- a/src/wasm/encoder.cc
+++ b/src/wasm/encoder.cc
@@ -157,27 +157,30 @@ 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);
- const byte* start = &body_[0];
- const byte* end = start + body_.size();
- size_t local_index = 0;
- for (size_t i = 0; i < body_.size();) {
- if (local_index < local_indices_.size() &&
- i == local_indices_[local_index]) {
- int length = 0;
- uint32_t index;
- ReadUnsignedLEB128Operand(start + i, end, &length, &index);
- uint16_t new_index = var_index[index];
- const std::vector<uint8_t>& index_vec = UnsignedLEB128From(new_index);
- for (size_t j = 0; j < index_vec.size(); j++) {
- e->body_.push_back(index_vec.at(j));
+ 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;
+ for (size_t i = 0; i < body_.size();) {
+ if (local_index < local_indices_.size() &&
+ i == local_indices_[local_index]) {
+ int length = 0;
+ uint32_t index;
+ ReadUnsignedLEB128Operand(start + i, end, &length, &index);
+ uint16_t new_index = var_index[index];
+ const std::vector<uint8_t>& index_vec = UnsignedLEB128From(new_index);
+ for (size_t j = 0; j < index_vec.size(); j++) {
+ e->body_.push_back(index_vec.at(j));
+ }
+ i += length;
+ local_index++;
+ } else {
+ e->body_.push_back(*(start + i));
+ i++;
}
- i += length;
- local_index++;
- } else {
- e->body_.push_back(*(start + i));
- i++;
}
}
FunctionSig::Builder sig(zone, return_type_ == kAstStmt ? 0 : 1,
@@ -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,8 +297,10 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
if (!external_) {
EmitUint16(header, static_cast<uint16_t>(body_.size()));
- std::memcpy(*header, &body_[0], body_.size());
- (*header) += body_.size();
+ if (body_.size() > 0) {
+ std::memcpy(*header, &body_[0], body_.size());
+ (*header) += body_.size();
+ }
}
}
« no previous file with comments | « no previous file | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698