2016-05-25 08:32:37 +00:00
|
|
|
// Copyright 2016 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 "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
#include "src/wasm/wasm-interpreter.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
|
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
using testing::MakeMatcher;
|
|
|
|
using testing::Matcher;
|
|
|
|
using testing::MatcherInterface;
|
|
|
|
using testing::MatchResultListener;
|
|
|
|
using testing::StringMatchResultListener;
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
|
|
|
#define B1(a) kExprBlock, a, kExprEnd
|
|
|
|
#define B2(a, b) kExprBlock, a, b, kExprEnd
|
|
|
|
#define B3(a, b, c) kExprBlock, a, b, c, kExprEnd
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define TRANSFER_VOID 0
|
|
|
|
#define TRANSFER_ONE 1
|
|
|
|
|
2017-04-25 09:43:39 +00:00
|
|
|
struct ExpectedControlTransfer {
|
2016-05-25 08:32:37 +00:00
|
|
|
pc_t pc;
|
2017-04-25 09:43:39 +00:00
|
|
|
pcdiff_t pc_diff;
|
|
|
|
uint32_t sp_diff;
|
|
|
|
uint32_t target_arity;
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// For nicer error messages.
|
2017-04-25 09:43:39 +00:00
|
|
|
class ControlTransferMatcher
|
|
|
|
: public MatcherInterface<const ControlTransferEntry&> {
|
2016-05-25 08:32:37 +00:00
|
|
|
public:
|
2017-04-25 09:43:39 +00:00
|
|
|
explicit ControlTransferMatcher(pc_t pc,
|
|
|
|
const ExpectedControlTransfer& expected)
|
2016-05-25 08:32:37 +00:00
|
|
|
: pc_(pc), expected_(expected) {}
|
|
|
|
|
|
|
|
void DescribeTo(std::ostream* os) const override {
|
2017-04-25 09:43:39 +00:00
|
|
|
*os << "@" << pc_ << ": pcdiff = " << expected_.pc_diff
|
|
|
|
<< ", spdiff = " << expected_.sp_diff
|
|
|
|
<< ", target arity = " << expected_.target_arity;
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 09:43:39 +00:00
|
|
|
bool MatchAndExplain(const ControlTransferEntry& input,
|
2016-05-25 08:32:37 +00:00
|
|
|
MatchResultListener* listener) const override {
|
2017-04-25 09:43:39 +00:00
|
|
|
if (input.pc_diff == expected_.pc_diff &&
|
|
|
|
input.sp_diff == expected_.sp_diff &&
|
|
|
|
input.target_arity == expected_.target_arity) {
|
|
|
|
return true;
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
2017-04-25 09:43:39 +00:00
|
|
|
*listener << "@" << pc_ << ": pcdiff = " << input.pc_diff
|
|
|
|
<< ", spdiff = " << input.sp_diff
|
|
|
|
<< ", target arity = " << input.target_arity;
|
|
|
|
return false;
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
pc_t pc_;
|
2017-04-25 09:43:39 +00:00
|
|
|
const ExpectedControlTransfer& expected_;
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ControlTransferTest : public TestWithZone {
|
|
|
|
public:
|
2017-04-24 11:39:38 +00:00
|
|
|
template <int code_len>
|
2017-04-25 09:43:39 +00:00
|
|
|
void CheckTransfers(
|
|
|
|
const byte (&code)[code_len],
|
|
|
|
std::initializer_list<ExpectedControlTransfer> expected_transfers) {
|
2017-04-24 11:39:38 +00:00
|
|
|
byte code_with_end[code_len + 1]; // NOLINT: code_len is a constant here
|
|
|
|
memcpy(code_with_end, code, code_len);
|
|
|
|
code_with_end[code_len] = kExprEnd;
|
|
|
|
|
|
|
|
ControlTransferMap map = WasmInterpreter::ComputeControlTransfersForTesting(
|
2017-04-25 09:43:39 +00:00
|
|
|
zone(), nullptr, code_with_end, code_with_end + code_len + 1);
|
2016-05-25 08:32:37 +00:00
|
|
|
// Check all control targets in the map.
|
2017-04-25 09:43:39 +00:00
|
|
|
for (auto& expected_transfer : expected_transfers) {
|
|
|
|
pc_t pc = expected_transfer.pc;
|
|
|
|
EXPECT_TRUE(map.count(pc) > 0) << "expected control target @" << pc;
|
|
|
|
if (!map.count(pc)) continue;
|
|
|
|
auto& entry = map[pc];
|
|
|
|
EXPECT_THAT(entry, MakeMatcher(new ControlTransferMatcher(
|
|
|
|
pc, expected_transfer)));
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
// Check there are no other control targets.
|
2017-04-24 11:39:38 +00:00
|
|
|
CheckNoOtherTargets(code_with_end, code_with_end + code_len + 1, map,
|
2017-04-25 09:43:39 +00:00
|
|
|
expected_transfers);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 09:43:39 +00:00
|
|
|
void CheckNoOtherTargets(
|
|
|
|
const byte* start, const byte* end, ControlTransferMap& map,
|
|
|
|
std::initializer_list<ExpectedControlTransfer> targets) {
|
2016-05-25 08:32:37 +00:00
|
|
|
// Check there are no other control targets.
|
|
|
|
for (pc_t pc = 0; start + pc < end; pc++) {
|
|
|
|
bool found = false;
|
2017-04-24 11:39:38 +00:00
|
|
|
for (auto& target : targets) {
|
|
|
|
if (target.pc == pc) {
|
2016-05-25 08:32:37 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) continue;
|
2017-04-24 11:39:38 +00:00
|
|
|
EXPECT_TRUE(map.count(pc) == 0) << "expected no control @ +" << pc;
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleIf) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprEnd // @4
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 2, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleIf1) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprNop, // @4
|
|
|
|
kExprEnd // @5
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleIf2) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprNop, // @4
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprNop, // @5
|
|
|
|
kExprEnd // @6
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 4, 0, 0}});
|
2016-09-23 15:56:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 17:58:07 +00:00
|
|
|
TEST_F(ControlTransferTest, SimpleIfElse) {
|
2016-09-23 15:56:42 +00:00
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-09-23 15:56:42 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprElse, // @4
|
|
|
|
kExprEnd // @5
|
2016-09-23 15:56:42 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 3, 0, 0}, {4, 2, 0, 0}});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleIfElse_v1) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
|
|
|
0, // @1
|
|
|
|
kExprIf, // @2
|
|
|
|
kLocalVoid, // @3
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprI32Const, // @4
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @5
|
|
|
|
kExprElse, // @6
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprI32Const, // @7
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @8
|
|
|
|
kExprEnd // @9
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 5, 0, 0}, {6, 4, 1, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleIfElse1) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprElse, // @4
|
|
|
|
kExprNop, // @5
|
|
|
|
kExprEnd // @6
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 3, 0, 0}, {4, 3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, IfBr) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprEnd // @6
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 4, 0, 0}, {4, 3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, IfBrElse) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprElse, // @6
|
|
|
|
kExprEnd // @7
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 5, 0, 0}, {4, 4, 0, 0}, {6, 2, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, IfElseBr) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprI32Const, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprIf, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @3
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprElse, // @4
|
|
|
|
kExprBr, // @5
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // @6
|
|
|
|
kExprEnd // @7
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 3, 0, 0}, {4, 4, 0, 0}, {5, 3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, BlockEmpty) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
2017-04-25 09:43:39 +00:00
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprEnd // @2
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br0) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBr, // @2
|
|
|
|
0, // @3
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprEnd // @4
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br1) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprNop, // @2
|
|
|
|
kExprBr, // @3
|
|
|
|
0, // @4
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprEnd // @5
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{3, 3, 0, 0}});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br_v1a) {
|
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprEnd // @6
|
2016-09-27 20:46:10 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{4, 3, 1, 0}});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br_v1b) {
|
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprEnd // @6
|
2016-09-27 20:46:10 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{4, 3, 1, 0}});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br_v1c) {
|
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprI32Const, // @0
|
|
|
|
0, // @1
|
|
|
|
kExprBlock, // @2
|
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprEnd // @6
|
2016-09-27 20:46:10 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{4, 3, 0, 0}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br_v1d) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalI32, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprEnd // @6
|
|
|
|
};
|
|
|
|
CheckTransfers(code, {{4, 3, 1, 1}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br2) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @1
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprNop, // @2
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprNop, // @3
|
|
|
|
kExprBr, // @4
|
|
|
|
0, // @5
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprEnd // @6
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{4, 3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br0b) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBr, // @2
|
|
|
|
0, // @3
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprNop, // @4
|
|
|
|
kExprEnd // @5
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 4, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, Br0c) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
2016-09-27 20:46:10 +00:00
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBr, // @2
|
|
|
|
0, // @3
|
2016-05-25 08:32:37 +00:00
|
|
|
kExprNop, // @4
|
|
|
|
kExprNop, // @5
|
|
|
|
kExprEnd // @6
|
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 5, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleLoop1) {
|
|
|
|
byte code[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprLoop, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBr, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprEnd // @4
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, -2, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleLoop2) {
|
|
|
|
byte code[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprLoop, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprNop, // @2
|
|
|
|
kExprBr, // @3
|
|
|
|
0, // @4
|
|
|
|
kExprEnd // @5
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{3, -3, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleLoopExit1) {
|
|
|
|
byte code[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprLoop, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBr, // @2
|
|
|
|
1, // @3
|
|
|
|
kExprEnd // @4
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{2, 4, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, SimpleLoopExit2) {
|
|
|
|
byte code[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
kExprLoop, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprNop, // @2
|
|
|
|
kExprBr, // @3
|
|
|
|
1, // @4
|
|
|
|
kExprEnd // @5
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{3, 4, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, BrTable0) {
|
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBrTable, // @4
|
|
|
|
0, // @5
|
|
|
|
U32V_1(0), // @6
|
|
|
|
kExprEnd // @7
|
2016-09-23 15:56:42 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{4, 4, 0, 0}});
|
2016-09-23 15:56:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
TEST_F(ControlTransferTest, BrTable0_v1a) {
|
2016-05-25 08:32:37 +00:00
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprI32Const, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprBrTable, // @6
|
|
|
|
0, // @7
|
|
|
|
U32V_1(0), // @8
|
|
|
|
kExprEnd // @9
|
2016-09-23 15:56:42 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{6, 4, 1, 0}});
|
2016-09-23 15:56:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
TEST_F(ControlTransferTest, BrTable0_v1b) {
|
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprI32Const, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprBrTable, // @6
|
|
|
|
0, // @7
|
|
|
|
U32V_1(0), // @8
|
|
|
|
kExprEnd // @9
|
2016-09-27 20:46:10 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{6, 4, 1, 0}});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, BrTable1) {
|
2016-09-23 15:56:42 +00:00
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBrTable, // @4
|
|
|
|
1, // @5
|
|
|
|
U32V_1(0), // @6
|
|
|
|
U32V_1(0), // @7
|
|
|
|
kExprEnd // @8
|
2016-09-27 20:46:10 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{4, 5, 0, 0}, {5, 4, 0, 0}});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, BrTable2) {
|
|
|
|
byte code[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBlock, // @2
|
|
|
|
kLocalVoid, // @3
|
|
|
|
kExprI32Const, // @4
|
|
|
|
0, // @5
|
|
|
|
kExprBrTable, // @6
|
|
|
|
2, // @7
|
|
|
|
U32V_1(0), // @8
|
|
|
|
U32V_1(0), // @9
|
|
|
|
U32V_1(1), // @10
|
|
|
|
kExprEnd, // @11
|
|
|
|
kExprEnd // @12
|
2016-05-25 08:32:37 +00:00
|
|
|
};
|
2017-04-25 09:43:39 +00:00
|
|
|
CheckTransfers(code, {{6, 6, 0, 0}, {7, 5, 0, 0}, {8, 5, 0, 0}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, BiggerSpDiffs) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalI32, // @1
|
|
|
|
kExprI32Const, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBlock, // @4
|
|
|
|
kLocalVoid, // @5
|
|
|
|
kExprI32Const, // @6
|
|
|
|
0, // @7
|
|
|
|
kExprI32Const, // @8
|
|
|
|
0, // @9
|
2017-05-02 17:46:21 +00:00
|
|
|
kExprI32Const, // @10
|
2017-04-25 09:43:39 +00:00
|
|
|
0, // @11
|
2017-05-02 17:46:21 +00:00
|
|
|
kExprBrIf, // @12
|
|
|
|
0, // @13
|
|
|
|
kExprBr, // @14
|
|
|
|
1, // @15
|
|
|
|
kExprEnd, // @16
|
|
|
|
kExprEnd // @17
|
2017-04-25 09:43:39 +00:00
|
|
|
};
|
2017-05-02 17:46:21 +00:00
|
|
|
CheckTransfers(code, {{12, 5, 2, 0}, {14, 4, 3, 1}});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ControlTransferTest, NoInfoForUnreachableCode) {
|
|
|
|
byte code[] = {
|
|
|
|
kExprBlock, // @0
|
|
|
|
kLocalVoid, // @1
|
|
|
|
kExprBr, // @2
|
|
|
|
0, // @3
|
|
|
|
kExprBr, // @4 -- no control transfer entry!
|
|
|
|
1, // @5
|
|
|
|
kExprEnd, // @6
|
|
|
|
kExprBlock, // @7
|
|
|
|
kLocalVoid, // @8
|
|
|
|
kExprUnreachable, // @9
|
|
|
|
kExprI32Const, // @10
|
|
|
|
0, // @11
|
|
|
|
kExprIf, // @12 -- no control transfer entry!
|
|
|
|
kLocalVoid, // @13
|
|
|
|
kExprBr, // @14 -- no control transfer entry!
|
|
|
|
0, // @15
|
|
|
|
kExprElse, // @16 -- no control transfer entry!
|
|
|
|
kExprEnd, // @17
|
|
|
|
kExprEnd // @18
|
|
|
|
};
|
|
|
|
CheckTransfers(code, {{2, 5, 0, 0}});
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|