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

[wasm] Remove non-trivially dead or redundant code

After the FallThruTo in kExprEnd, the current block {c} is never
unreachable. Hence, the check for {c->unreachable} afterwards can be
removed.
In the loop case, the {TypeCheckFallThru} already adds entries for
non-existing values to the stack, so no need to {PushEndValues}.
Also, add more tests for the loop case.

R=titzer@chromium.org

Change-Id: I8737affaeed2ea663bd6ddafa36532ca9a7379bb
Reviewed-on: https://chromium-review.googlesource.com/645859Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47765}
parent 7c60eac7
......@@ -1315,7 +1315,6 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (c->is_loop()) {
// A loop just leaves the values on the stack.
TypeCheckFallThru(c);
if (c->unreachable) PushEndValues(c);
PopControl(c);
break;
}
......@@ -1343,16 +1342,13 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
}
last_end_found_ = true;
if (c->unreachable) {
TypeCheckFallThru(c);
} else {
// The result of the block is the return value.
TRACE(" @%-8d #xx:%-20s|", startrel(this->pc_),
"(implicit) return");
DoReturn();
TRACE("\n");
}
// The result of the block is the return value.
TRACE(" @%-8d #xx:%-20s|", startrel(this->pc_),
"(implicit) return");
DoReturn();
TRACE("\n");
}
PopControl(c);
break;
}
......
......@@ -3037,6 +3037,47 @@ WASM_EXEC_TEST(BranchOverUnreachableCode) {
CHECK_EQ(18, r.Call());
}
WASM_EXEC_TEST(BranchOverUnreachableCodeInLoop0) {
WasmRunner<int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(
// Start a loop which breaks in the middle (hence unreachable code
// afterwards) and continue execution after this loop.
// This should validate even though there is no value on the stack
// at the end of the loop.
WASM_LOOP_I(WASM_BRV(1, WASM_I32V_1(17)))),
// Add one to the 17 returned from the block.
WASM_ONE, kExprI32Add);
CHECK_EQ(18, r.Call());
}
WASM_EXEC_TEST(BranchOverUnreachableCodeInLoop1) {
WasmRunner<int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(
// Start a loop which breaks in the middle (hence unreachable code
// afterwards) and continue execution after this loop.
// Even though unreachable, the loop leaves one value on the stack.
WASM_LOOP_I(WASM_BRV(1, WASM_I32V_1(17)), WASM_ONE)),
// Add one to the 17 returned from the block.
WASM_ONE, kExprI32Add);
CHECK_EQ(18, r.Call());
}
WASM_EXEC_TEST(BranchOverUnreachableCodeInLoop2) {
WasmRunner<int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(
// Start a loop which breaks in the middle (hence unreachable code
// afterwards) and continue execution after this loop.
// The unreachable code is allowed to pop non-existing values off
// the stack and push back the result.
WASM_LOOP_I(WASM_BRV(1, WASM_I32V_1(17)), kExprI32Add)),
// Add one to the 17 returned from the block.
WASM_ONE, kExprI32Add);
CHECK_EQ(18, r.Call());
}
WASM_EXEC_TEST(BlockInsideUnreachable) {
WasmRunner<int32_t> r(execution_mode);
BUILD(r, WASM_RETURN1(WASM_I32V_1(17)), WASM_BLOCK(WASM_BR(0)));
......
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