Commit e5984c64 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Simplify error detection at end of functions

The {last_end_found_} field is redundant. If it's false, there will be
a control struct left on the stack.
Thus remove that field, and simplify the error detection condition.

R=titzer@chromium.org

Bug: v8:8423
Change-Id: I16ac4597f229c5e3abd923f8eb504f93afb82eb4
Reviewed-on: https://chromium-review.googlesource.com/c/1373788Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58198}
parent 8afce15a
...@@ -1421,8 +1421,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1421,8 +1421,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
local_type_vec_(zone), local_type_vec_(zone),
stack_(zone), stack_(zone),
control_(zone), control_(zone),
args_(zone), args_(zone) {
last_end_found_(false) {
this->local_types_ = &local_type_vec_; this->local_types_ = &local_type_vec_;
} }
...@@ -1449,24 +1448,16 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1449,24 +1448,16 @@ class WasmFullDecoder : public WasmDecoder<validate> {
DecodeFunctionBody(); DecodeFunctionBody();
if (!this->failed()) CALL_INTERFACE(FinishFunction); if (!this->failed()) CALL_INTERFACE(FinishFunction);
if (this->failed()) return this->TraceFailed(); // Generate a better error message whether the unterminated control
// structure is the function body block or an innner structure.
if (!control_.empty()) { if (control_.size() > 1) {
// Generate a better error message whether the unterminated control this->error(control_.back().pc, "unterminated control structure");
// structure is the function body block or an innner structure. } else if (control_.size() == 1) {
if (control_.size() > 1) {
this->error(control_.back().pc, "unterminated control structure");
} else {
this->error("function body must end with \"end\" opcode");
}
return TraceFailed();
}
if (!last_end_found_) {
this->error("function body must end with \"end\" opcode"); this->error("function body must end with \"end\" opcode");
return false;
} }
if (this->failed()) return this->TraceFailed();
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
double ms = decode_timer.Elapsed().InMillisecondsF(); double ms = decode_timer.Elapsed().InMillisecondsF();
PrintF("wasm-decode %s (%0.3f ms)\n\n", PrintF("wasm-decode %s (%0.3f ms)\n\n",
...@@ -1535,7 +1526,6 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1535,7 +1526,6 @@ class WasmFullDecoder : public WasmDecoder<validate> {
ZoneVector<Value> stack_; // stack of values. ZoneVector<Value> stack_; // stack of values.
ZoneVector<Control> control_; // stack of blocks, loops, and ifs. ZoneVector<Control> control_; // stack of blocks, loops, and ifs.
ZoneVector<Value> args_; // parameters of current block or call ZoneVector<Value> args_; // parameters of current block or call
bool last_end_found_;
bool CheckHasMemory() { bool CheckHasMemory() {
if (!VALIDATE(this->module_->has_memory)) { if (!VALIDATE(this->module_->has_memory)) {
...@@ -1805,7 +1795,6 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1805,7 +1795,6 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->error(this->pc_ + 1, "trailing code after function end"); this->error(this->pc_ + 1, "trailing code after function end");
break; break;
} }
last_end_found_ = true;
// The result of the block is the return value. // The result of the block is the return value.
TRACE_PART("\n" TRACE_INST_FORMAT, startrel(this->pc_), TRACE_PART("\n" TRACE_INST_FORMAT, startrel(this->pc_),
"(implicit) return"); "(implicit) return");
......
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