Commit fb4a190c authored by jpp's avatar jpp Committed by Commit bot

Revert "[v8][wasm] Handles finally in try/finally blocks."

This reverts commit cf5180c3. It turns
out finally blocks aren't useful in the current incarnation of Wasm. We
might reintroduce it later.

BUG=

Review-Url: https://codereview.chromium.org/2330073002
Cr-Commit-Position: refs/heads/master@{#39390}
parent 5d5efc66
......@@ -68,40 +68,14 @@ struct Value {
LocalType type;
};
struct Control;
// IncomingBranch is used by exception handling code for managing finally's.
struct IncomingBranch {
int32_t token_value;
Control* target;
Value val;
};
// Auxiliary data for exception handling. Most scopes don't need any of this so
// we group everything into a separate struct.
struct TryInfo : public ZoneObject {
SsaEnv* catch_env; // catch environment (only for try with catch).
SsaEnv* finish_try_env; // the environment where a try with finally lives.
ZoneVector<IncomingBranch> incoming_branches;
TFNode* token;
bool has_handled_finally;
TryInfo(Zone* zone, SsaEnv* c, SsaEnv* f)
: catch_env(c),
finish_try_env(f),
incoming_branches(zone),
token(nullptr),
has_handled_finally(false) {}
};
// An entry on the control stack (i.e. if, block, loop).
struct Control {
const byte* pc;
int stack_depth; // stack height at the beginning of the construct.
SsaEnv* end_env; // end environment for the construct.
SsaEnv* false_env; // false environment (only for if).
TryInfo* try_info; // exception handling stuff. See TryInfo above.
int32_t prev_finally; // previous control (on stack) that has a finally.
SsaEnv* catch_env; // catch environment (only for try with catch).
SsaEnv* finish_try_env; // the environment where a try with finally lives.
TFNode* node; // result node for the construct.
LocalType type; // result type for the construct.
bool is_loop; // true if this is the inner label of a loop.
......@@ -122,40 +96,26 @@ struct Control {
}
// Named constructors.
static Control Block(const byte* pc, int stack_depth,
int32_t most_recent_finally, SsaEnv* end_env) {
return {pc, stack_depth, end_env,
nullptr, nullptr, most_recent_finally,
nullptr, kAstEnd, false};
static Control Block(const byte* pc, int stack_depth, SsaEnv* end_env) {
return {pc, stack_depth, end_env, nullptr, nullptr,
nullptr, nullptr, kAstEnd, false};
}
static Control If(const byte* pc, int stack_depth,
int32_t most_recent_finally, SsaEnv* end_env,
static Control If(const byte* pc, int stack_depth, SsaEnv* end_env,
SsaEnv* false_env) {
return {pc, stack_depth, end_env,
false_env, nullptr, most_recent_finally,
nullptr, kAstStmt, false};
return {pc, stack_depth, end_env, false_env, nullptr,
nullptr, nullptr, kAstStmt, false};
}
static Control Loop(const byte* pc, int stack_depth,
int32_t most_recent_finally, SsaEnv* end_env) {
return {pc, stack_depth, end_env,
nullptr, nullptr, most_recent_finally,
nullptr, kAstEnd, true};
static Control Loop(const byte* pc, int stack_depth, SsaEnv* end_env) {
return {pc, stack_depth, end_env, nullptr, nullptr,
nullptr, nullptr, kAstEnd, true};
}
static Control Try(const byte* pc, int stack_depth,
int32_t most_recent_finally, Zone* zone, SsaEnv* end_env,
static Control Try(const byte* pc, int stack_depth, SsaEnv* end_env,
SsaEnv* catch_env, SsaEnv* finish_try_env) {
return {pc,
stack_depth,
end_env,
nullptr,
new (zone) TryInfo(zone, catch_env, finish_try_env),
most_recent_finally,
nullptr,
kAstEnd,
false};
return {pc, stack_depth, end_env, nullptr, catch_env, finish_try_env,
nullptr, kAstEnd, false};
}
};
......@@ -470,10 +430,6 @@ class WasmDecoder : public Decoder {
}
};
static const int32_t kFirstFinallyToken = 1;
static const int32_t kFallthroughToken = 0;
static const int32_t kNullFinallyToken = -1;
// The full WASM decoder for bytecode. Both verifies bytecode and generates
// a TurboFan IR graph.
class WasmFullDecoder : public WasmDecoder {
......@@ -485,9 +441,7 @@ class WasmFullDecoder : public WasmDecoder {
base_(body.base),
local_type_vec_(zone),
stack_(zone),
control_(zone),
most_recent_finally_(-1),
finally_token_val_(kFirstFinallyToken) {
control_(zone) {
local_types_ = &local_type_vec_;
}
......@@ -580,16 +534,6 @@ class WasmFullDecoder : public WasmDecoder {
ZoneVector<Value> stack_; // stack of values.
ZoneVector<Control> control_; // stack of blocks, loops, and ifs.
int32_t most_recent_finally_;
int32_t finally_token_val_;
int32_t FallthroughTokenForFinally() {
// Any number < kFirstFinallyToken would work.
return kFallthroughToken;
}
int32_t NewTokenForFinally() { return finally_token_val_++; }
inline bool build() { return builder_ && ssa_env_->go(); }
void InitSsaEnv() {
......@@ -786,15 +730,15 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
if (c->try_info->catch_env == nullptr) {
if (c->catch_env == nullptr) {
error(pc_, "catch already present for try with catch");
break;
}
Goto(ssa_env_, c->end_env);
SsaEnv* catch_env = c->try_info->catch_env;
c->try_info->catch_env = nullptr;
SsaEnv* catch_env = c->catch_env;
c->catch_env = nullptr;
SetEnv("catch:begin", catch_env);
if (Validate(pc_, operand)) {
......@@ -817,7 +761,7 @@ class WasmFullDecoder : public WasmDecoder {
}
Control* c = &control_.back();
if (c->has_catch() && c->try_info->catch_env != nullptr) {
if (c->has_catch() && c->catch_env != nullptr) {
error(pc_, "missing catch for try with catch and finally");
break;
}
......@@ -827,7 +771,7 @@ class WasmFullDecoder : public WasmDecoder {
break;
}
if (c->try_info->finish_try_env == nullptr) {
if (c->finish_try_env == nullptr) {
error(pc_, "finally already present for try with finally");
break;
}
......@@ -835,14 +779,10 @@ class WasmFullDecoder : public WasmDecoder {
// ssa_env_ is either the env for either the try or the catch, but
// it does not matter: either way we need to direct the control flow
// to the end_env, which is the env for the finally.
// c->try_info->finish_try_env is the the environment enclosing the
// try block.
const bool has_fallthrough = ssa_env_->go();
Value val = PopUpTo(c->stack_depth);
if (has_fallthrough) {
MergeInto(c->end_env, &c->node, &c->type, val);
MergeFinallyToken(ssa_env_, c, FallthroughTokenForFinally());
}
// c->finish_try_env is the the environment enclosing the try block.
Goto(ssa_env_, c->end_env);
PopUpTo(c->stack_depth);
// The current environment becomes end_env, and finish_try_env
// becomes the new end_env. This ensures that any control flow
......@@ -851,22 +791,10 @@ class WasmFullDecoder : public WasmDecoder {
// that kExprEnd below can handle the try block as it would any
// other block construct.
SsaEnv* finally_env = c->end_env;
c->end_env = c->try_info->finish_try_env;
c->end_env = c->finish_try_env;
SetEnv("finally:begin", finally_env);
c->try_info->finish_try_env = nullptr;
if (has_fallthrough) {
LocalType c_type = c->type;
if (c->node == nullptr) {
c_type = kAstStmt;
}
Push(c_type, c->node);
}
c->finish_try_env = nullptr;
c->try_info->has_handled_finally = true;
// There's no more need to keep the current control scope in the
// finally chain as no more predecessors will be added to c.
most_recent_finally_ = c->prev_finally;
break;
}
case kExprLoop: {
......@@ -919,7 +847,7 @@ class WasmFullDecoder : public WasmDecoder {
}
case kExprEnd: {
if (control_.empty()) {
error(pc_, "end does not match any if, try, or block");
error(pc_, "end does not match any if or block");
break;
}
const char* name = "block:end";
......@@ -927,7 +855,7 @@ class WasmFullDecoder : public WasmDecoder {
Value val = PopUpTo(c->stack_depth);
if (c->is_loop) {
// Loops always push control in pairs.
PopControl();
control_.pop_back();
c = &control_.back();
name = "loop:end";
} else if (c->is_if()) {
......@@ -943,30 +871,28 @@ class WasmFullDecoder : public WasmDecoder {
} else if (c->is_try()) {
name = "try:end";
// try blocks do not yield a value.
val = {val.pc, nullptr, kAstStmt};
// validate that catch/finally were seen.
if (c->try_info->catch_env != nullptr) {
if (c->catch_env != nullptr) {
error(pc_, "missing catch in try with catch");
break;
}
if (c->try_info->finish_try_env != nullptr) {
if (c->finish_try_env != nullptr) {
error(pc_, "missing finally in try with finally");
break;
}
if (c->has_finally() && ssa_env_->go()) {
DispatchToTargets(c, val);
}
}
if (ssa_env_->go()) {
// Adds a fallthrough edge to the next control block.
MergeInto(c->end_env, &c->node, &c->type, val);
}
SetEnv(name, c->end_env);
stack_.resize(c->stack_depth);
Push(c->type, c->node);
PopControl();
control_.pop_back();
break;
}
case kExprSelect: {
......@@ -1000,7 +926,7 @@ class WasmFullDecoder : public WasmDecoder {
Value val = {pc_, nullptr, kAstStmt};
if (operand.arity) val = Pop();
if (Validate(pc_, operand, control_)) {
BreakTo(operand, val);
BreakTo(operand.target, val);
}
len = 1 + operand.length;
Push(kAstEnd, nullptr);
......@@ -1017,7 +943,7 @@ class WasmFullDecoder : public WasmDecoder {
fenv->SetNotMerged();
BUILD(Branch, cond.node, &tenv->control, &fenv->control);
ssa_env_ = tenv;
BreakTo(operand, val);
BreakTo(operand.target, val);
ssa_env_ = fenv;
}
len = 1 + operand.length;
......@@ -1354,37 +1280,23 @@ class WasmFullDecoder : public WasmDecoder {
void PushBlock(SsaEnv* end_env) {
const int stack_depth = static_cast<int>(stack_.size());
control_.emplace_back(
Control::Block(pc_, stack_depth, most_recent_finally_, end_env));
control_.emplace_back(Control::Block(pc_, stack_depth, end_env));
}
void PushLoop(SsaEnv* end_env) {
const int stack_depth = static_cast<int>(stack_.size());
control_.emplace_back(
Control::Loop(pc_, stack_depth, most_recent_finally_, end_env));
control_.emplace_back(Control::Loop(pc_, stack_depth, end_env));
}
void PushIf(SsaEnv* end_env, SsaEnv* false_env) {
const int stack_depth = static_cast<int>(stack_.size());
control_.emplace_back(Control::If(pc_, stack_depth, most_recent_finally_,
end_env, false_env));
control_.emplace_back(Control::If(pc_, stack_depth, end_env, false_env));
}
void PushTry(SsaEnv* end_env, SsaEnv* catch_env, SsaEnv* finish_try_env) {
const int stack_depth = static_cast<int>(stack_.size());
control_.emplace_back(Control::Try(pc_, stack_depth, most_recent_finally_,
zone_, end_env, catch_env,
finish_try_env));
if (control_.back().has_finally()) {
most_recent_finally_ = static_cast<uint32_t>(control_.size() - 1);
}
}
void PopControl() {
const Control& c = control_.back();
most_recent_finally_ = c.prev_finally;
control_.pop_back();
// No more accesses to (danging pointer) c
control_.emplace_back(
Control::Try(pc_, stack_depth, end_env, catch_env, finish_try_env));
}
int DecodeLoadMem(LocalType type, MachineType mem_type) {
......@@ -1441,50 +1353,6 @@ class WasmFullDecoder : public WasmDecoder {
return len;
}
void DispatchToTargets(Control* next_block, const Value& val) {
const ZoneVector<IncomingBranch>& incoming_branches =
next_block->try_info->incoming_branches;
// Counts how many successors are not current control block.
uint32_t targets = 0;
for (const auto& path_token : incoming_branches) {
if (path_token.target != next_block) ++targets;
}
if (targets == 0) {
// Nothing to do here: the control flow should just fall
// through to the next control block.
return;
}
TFNode* sw = BUILD(Switch, static_cast<uint32_t>(targets + 1),
next_block->try_info->token);
SsaEnv* break_env = ssa_env_;
SsaEnv* copy = Steal(break_env);
for (uint32_t ii = 0; ii < incoming_branches.size(); ++ii) {
Control* t = incoming_branches[ii].target;
if (t != next_block) {
const int32_t token_value = incoming_branches[ii].token_value;
ssa_env_ = Split(copy);
ssa_env_->control = BUILD(IfValue, token_value, sw);
MergeInto(t->end_env, &t->node, &t->type, incoming_branches[ii].val);
// We only need to merge the finally token if t is both a
// try-with-finally and its finally hasn't yet been found
// in the instruction stream. Otherwise we just need to
// branch to t.
if (t->has_finally() && !t->try_info->has_handled_finally) {
MergeFinallyToken(ssa_env_, t, token_value);
}
}
}
ssa_env_ = Split(copy);
ssa_env_->control = BUILD(IfDefault, sw);
MergeInto(next_block->end_env, &next_block->node, &next_block->type, val);
// Not a finally env; no fallthrough token.
ssa_env_ = break_env;
}
void DoReturn() {
int count = static_cast<int>(sig_->return_count());
TFNode** buffer = nullptr;
......@@ -1551,46 +1419,7 @@ class WasmFullDecoder : public WasmDecoder {
int startrel(const byte* ptr) { return static_cast<int>(ptr - start_); }
Control* BuildFinallyChain(const BreakDepthOperand& operand, const Value& val,
int32_t* token) {
DCHECK_LE(operand.depth, control_.size());
const int32_t target_index =
static_cast<uint32_t>(control_.size() - operand.depth - 1);
if (most_recent_finally_ == kNullFinallyToken || // No finallies.
most_recent_finally_ < target_index) { // Does not cross any finally.
*token = kNullFinallyToken;
return operand.target;
}
Control* previous_control = &control_[most_recent_finally_];
*token = NewTokenForFinally();
for (int32_t ii = previous_control->prev_finally; ii >= target_index;
ii = previous_control->prev_finally) {
Control* current_finally = &control_[ii];
DCHECK(!current_finally->try_info->has_handled_finally);
previous_control->try_info->incoming_branches.push_back(
{*token, current_finally, val});
previous_control = current_finally;
}
if (operand.target != previous_control) {
DCHECK_NOT_NULL(previous_control);
DCHECK(previous_control->has_finally());
DCHECK_NE(*token, kNullFinallyToken);
previous_control->try_info->incoming_branches.push_back(
{*token, operand.target, val});
}
return &control_[most_recent_finally_];
}
void BreakTo(const BreakDepthOperand& operand, const Value& val) {
int32_t finally_token;
Control* block = BuildFinallyChain(operand, val, &finally_token);
void BreakTo(Control* block, Value& val) {
if (block->is_loop) {
// This is the inner loop block, which does not have a value.
Goto(ssa_env_, block->end_env);
......@@ -1598,14 +1427,9 @@ class WasmFullDecoder : public WasmDecoder {
// Merge the value into the production for the block.
MergeInto(block->end_env, &block->node, &block->type, val);
}
if (finally_token != kNullFinallyToken) {
MergeFinallyToken(ssa_env_, block, finally_token);
}
}
void MergeInto(SsaEnv* target, TFNode** node, LocalType* type,
const Value& val) {
void MergeInto(SsaEnv* target, TFNode** node, LocalType* type, Value& val) {
if (!ssa_env_->go()) return;
DCHECK_NE(kAstEnd, val.type);
......@@ -1662,32 +1486,6 @@ class WasmFullDecoder : public WasmDecoder {
}
}
void MergeFinallyToken(SsaEnv*, Control* to, int32_t new_token) {
DCHECK(to->has_finally());
DCHECK(!to->try_info->has_handled_finally);
if (builder_ == nullptr) {
return;
}
switch (to->end_env->state) {
case SsaEnv::kReached:
DCHECK(to->try_info->token == nullptr);
to->try_info->token = builder_->Int32Constant(new_token);
break;
case SsaEnv::kMerged:
DCHECK_NOT_NULL(to->try_info->token);
to->try_info->token = CreateOrMergeIntoPhi(
kAstI32, to->end_env->control, to->try_info->token,
builder_->Int32Constant(new_token));
break;
case SsaEnv::kUnreachable:
UNREACHABLE();
// fallthrough intended.
default:
break;
}
}
void Goto(SsaEnv* from, SsaEnv* to) {
DCHECK_NOT_NULL(to);
if (!from->go()) return;
......
......@@ -193,7 +193,6 @@
'wasm/test-run-wasm-js.cc',
'wasm/test-run-wasm-module.cc',
'wasm/test-run-wasm-relocation.cc',
'wasm/test-run-wasm-try-catch.cc',
'wasm/test-signatures.h',
'wasm/test-wasm-function-name-table.cc',
'wasm/test-wasm-stack.cc',
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "src/base/platform/elapsed-timer.h"
#include "src/wasm/wasm-macro-gen.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/value-helper.h"
#include "test/cctest/wasm/test-signatures.h"
#include "test/cctest/wasm/wasm-run-utils.h"
using namespace v8::base;
using namespace v8::internal;
using namespace v8::internal::compiler;
using namespace v8::internal::wasm;
// TODO(jpp): WASM_EXEC_TEST(TryCatch)
// TODO(jpp): Move these macros to src/wasm/wasm-macro-gen.h once zero cost
// exceptions are added to the spec.
#define WASM_TRY_FINALLY(...) kExprTryFinally, __VA_ARGS__, kExprEnd
#define WASM_FINALLY(...) kExprFinally, __VA_ARGS__
WASM_EXEC_TEST(TryFinally_single) {
if (execution_mode == kExecuteInterpreted) {
// TODO(jpp): implement eh support in the interpreter.
return;
}
FLAG_wasm_eh_prototype = true;
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
// r(i32 p, i32 q) -> i32 {
// try {
// if (q) {
// break;
// }
// p += 0x0f0;
// } finally {
// p += 0x00f;
// }
// p += 0xf00
// return p;
// }
BUILD(r, WASM_TRY_FINALLY(
WASM_IF(WASM_GET_LOCAL(1), WASM_BREAK(0)),
WASM_SET_LOCAL(
0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_2(0xf0))),
WASM_FINALLY(WASM_SET_LOCAL(
0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(0x0f))))),
WASM_SET_LOCAL(0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0xf00))),
WASM_GET_LOCAL(0));
CHECK_EQ(0xFFFF, r.Call(0xF000, 0));
CHECK_EQ(0xFF0F, r.Call(0xF000, 1));
}
WASM_EXEC_TEST(TryFinally_double) {
if (execution_mode == kExecuteInterpreted) {
// TODO(jpp): implement eh support in the interpreter.
return;
}
FLAG_wasm_eh_prototype = true;
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
// r(i32 p, i32 q) -> i32 {
// a: try {
// b: try {
// if (q == 40) {
// break a;
// } else {
// if (q == 1) {
// break b;
// }
// }
// p += 0x00000f;
// } finally {
// p += 0x0000f0;
// }
// p += 0x000f00;
// } finally {
// p += 0x00f000;
// }
// return p;
// }
BUILD(
r,
WASM_TRY_FINALLY(
WASM_TRY_FINALLY(
WASM_IF_ELSE(WASM_I32_EQ(WASM_GET_LOCAL(1), WASM_I32V(40)),
WASM_BREAK(1),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(1), WASM_I32V(1)),
WASM_BREAK(1))),
WASM_SET_LOCAL(
0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x00000f))),
WASM_FINALLY(WASM_SET_LOCAL(
0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x0000f0))))),
WASM_SET_LOCAL(0,
WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x000f00))),
WASM_FINALLY(WASM_SET_LOCAL(
0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x00f000))))),
WASM_GET_LOCAL(0));
CHECK_EQ(0x7000ffff, r.Call(0x70000000, 2));
CHECK_EQ(0x7000fff0, r.Call(0x70000000, 1));
CHECK_EQ(0x7000f0f0, r.Call(0x70000000, 40));
}
WASM_EXEC_TEST(TryFinally_multiple) {
if (execution_mode == kExecuteInterpreted) {
// TODO(jpp): implement eh support in the interpreter.
return;
}
FLAG_wasm_eh_prototype = true;
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
// Handy-dandy shortcuts for recurring patterns for this test.
#define I32_IOR_LOCAL(local, value) \
WASM_SET_LOCAL(local, WASM_I32_IOR(WASM_GET_LOCAL(local), WASM_I32V(value)))
#define IF_LOCAL_IS_BREAK_TO(local, value, depth) \
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(local), WASM_I32V(value)), \
WASM_BREAK(depth))
// r(i32 p, i32 q) -> i32 {
// a: try {
// b: try {
// c: try {
// d: try {
// e: try {
// switch (q) {
// case 1: break e;
// case 2: break d;
// case 3: break c;
// case 4: break b;
// case 5: break a;
// }
// p |= 0x00000001;
// } finally {
// p |= 0x00000002;
// }
// switch (q) {
// case 6: break d;
// case 7: break c;
// case 8: break b;
// case 9: break a;
// }
// p |= 0x00000004;
// } finally {
// p |= 0x00000008;
// }
// switch (q) {
// case 10: break c;
// case 11: break b;
// case 12: break a;
// }
// p |= 0x00000010;
// } finally {
// p |= 0x00000020;
// }
// switch (q) {
// case 13: break b;
// case 14: break a;
// }
// p |= 0x00000040;
// } finally {
// p |= 0x00000080;
// }
// switch (q) {
// case 15: break a;
// }
// p |= 0x00000100;
// } finally {
// p |= 0x00000200;
// }
// return p;
// }
BUILD(
r,
WASM_TRY_FINALLY(
WASM_TRY_FINALLY(
WASM_TRY_FINALLY(
WASM_TRY_FINALLY(
WASM_TRY_FINALLY(
IF_LOCAL_IS_BREAK_TO(1, 1, 0),
IF_LOCAL_IS_BREAK_TO(1, 2, 1),
IF_LOCAL_IS_BREAK_TO(1, 3, 2),
IF_LOCAL_IS_BREAK_TO(1, 4, 3),
IF_LOCAL_IS_BREAK_TO(1, 5, 4),
I32_IOR_LOCAL(0, 0x00000001),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000002))),
IF_LOCAL_IS_BREAK_TO(1, 6, 0),
IF_LOCAL_IS_BREAK_TO(1, 7, 1),
IF_LOCAL_IS_BREAK_TO(1, 8, 2),
IF_LOCAL_IS_BREAK_TO(1, 9, 3),
I32_IOR_LOCAL(0, 0x00000004),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000008))),
IF_LOCAL_IS_BREAK_TO(1, 10, 0),
IF_LOCAL_IS_BREAK_TO(1, 11, 1),
IF_LOCAL_IS_BREAK_TO(1, 12, 2), I32_IOR_LOCAL(0, 0x00000010),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000020))),
IF_LOCAL_IS_BREAK_TO(1, 13, 0), IF_LOCAL_IS_BREAK_TO(1, 14, 1),
I32_IOR_LOCAL(0, 0x00000040),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000080))),
IF_LOCAL_IS_BREAK_TO(1, 15, 0), I32_IOR_LOCAL(0, 0x00000100),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000200))),
WASM_GET_LOCAL(0));
#undef WASM_IF_LOCAL_IS_BREAK_TO
#undef WASM_I32_IOR_LOCAL
const struct {
uint32_t inputs[2];
uint32_t expected_output;
} kTests[] = {
{{0x80000000u, 0}, 0x800003ffu}, {{0x80000000u, 1}, 0x800003feu},
{{0x80000000u, 2}, 0x800003fau}, {{0x80000000u, 3}, 0x800003eau},
{{0x80000000u, 4}, 0x800003aau}, {{0x80000000u, 5}, 0x800002aau},
{{0x80000000u, 6}, 0x800003fbu}, {{0x80000000u, 7}, 0x800003ebu},
{{0x80000000u, 8}, 0x800003abu}, {{0x80000000u, 9}, 0x800002abu},
{{0x80000000u, 10}, 0x800003efu}, {{0x80000000u, 11}, 0x800003afu},
{{0x80000000u, 12}, 0x800002afu}, {{0x80000000u, 13}, 0x800003bfu},
{{0x80000000u, 14}, 0x800002bfu}, {{0x80000000u, 15}, 0x800002ffu},
};
for (uint32_t ii = 0; ii < arraysize(kTests); ++ii) {
const auto& test_instance = kTests[ii];
CHECK_EQ(test_instance.expected_output,
static_cast<uint32_t>(
r.Call(test_instance.inputs[0], test_instance.inputs[1])));
}
}
WASM_EXEC_TEST(TryFinally_break_within_finally) {
if (execution_mode == kExecuteInterpreted) {
// TODO(jpp): implement eh support in the interpreter.
return;
}
FLAG_wasm_eh_prototype = true;
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
#define I32_IOR_LOCAL(local, value) \
WASM_SET_LOCAL(local, WASM_I32_IOR(WASM_GET_LOCAL(local), WASM_I32V(value)))
#define IF_LOCAL_IS_BREAK_TO(local, value, depth) \
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(local), WASM_I32V(value)), \
WASM_BREAK(depth))
// r(i32 p, i32 q) -> i32 {
// a: try {
// } finally {
// b: try {
// c: try {
// } finally {
// d: try {
// e: try {
// } finally {
// f: try {
// } finally {
// if (q == 1) {
// break a;
// }
// p |= 0x00000001
// }
// p |= 0x00000002
// }
// p |= 0x00000004
// } finally {
// p |= 0x00000008 /* should run */
// }
// p |= 0x00000010
// }
// p |= 0x00000020
// } finally {
// p |= 0x00000040 /* should run */
// }
// p |= 0x00000080
// }
// return p;
// }
BUILD(r,
WASM_TRY_FINALLY( // a
WASM_FINALLY(
WASM_TRY_FINALLY( // b
WASM_TRY_FINALLY( // c
WASM_FINALLY(
WASM_TRY_FINALLY( // d
WASM_TRY_FINALLY( // e
WASM_FINALLY(
WASM_TRY_FINALLY( // f
WASM_FINALLY(
IF_LOCAL_IS_BREAK_TO(1, 1, 5),
I32_IOR_LOCAL(0, 0x00000001))),
I32_IOR_LOCAL(0, 0x00000002))),
I32_IOR_LOCAL(0, 0x00000004),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000008))),
I32_IOR_LOCAL(0, 0x00000010))),
I32_IOR_LOCAL(0, 0x00000020),
WASM_FINALLY(I32_IOR_LOCAL(0, 0x00000040))),
I32_IOR_LOCAL(0, 0x00000080))),
WASM_GET_LOCAL(0));
#undef WASM_IF_LOCAL_IS_BREAK_TO
#undef WASM_I32_IOR_LOCAL
CHECK_EQ(0x40000048, r.Call(0x40000000, 1));
}
// TODO(jpp): WASM_EXEC_TEST(TryCatchFinally)
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