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

[wasm] [decoder] Handle degenerate br_table correctly

The degenerate br_table case should be handled specially only in the
graph building consumer. There it is necessary for avoiding the
construction of a degenerate Switch node, which would cause a DCHECK
error in instruction selection.
For other backends, like the baseline compiler, we should handle it as
a br_table, because the signature is different to a br.

Drive-by: Fix redundant validation.

R=titzer@chromium.org

Bug: v8:6600
Change-Id: Ia430b6d251eb1323848977388ed95a112f8c76f7
Reviewed-on: https://chromium-review.googlesource.com/715616Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48494}
parent 93f855cc
......@@ -1474,19 +1474,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
if (!VALIDATE(this->ok())) break;
if (operand.table_count > 0) {
interface_.BrTable(this, operand, key);
} else {
// Only a default target. Do the equivalent of br.
BranchTableIterator<validate> iterator(this, operand);
const byte* pos = iterator.pc();
uint32_t target = iterator.next();
if (!VALIDATE(target < control_.size())) {
this->error(pos, "improper branch in br_table");
break;
}
interface_.BreakTo(this, target);
}
interface_.BrTable(this, operand, key);
len = 1 + iterator.length();
EndControl();
break;
......
......@@ -314,6 +314,13 @@ class WasmGraphBuildingInterface {
void BrTable(Decoder* decoder, const BranchTableOperand<true>& operand,
const Value& key) {
if (operand.table_count == 0) {
// Only a default target. Do the equivalent of br.
uint32_t target = BranchTableIterator<true>(decoder, operand).next();
BreakTo(decoder, target);
return;
}
SsaEnv* break_env = ssa_env_;
// Build branches to the various blocks based on the table.
TFNode* sw = BUILD(Switch, operand.table_count + 1, key.node);
......
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