2015-12-11 12:26:16 +00:00
|
|
|
// 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 "test/unittests/test-utils.h"
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
|
2016-10-05 11:59:47 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
#include "src/objects.h"
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
#include "src/wasm/function-body-decoder.h"
|
2016-11-09 08:37:05 +00:00
|
|
|
#include "src/wasm/signature-map.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/wasm-macro-gen.h"
|
|
|
|
#include "src/wasm/wasm-module.h"
|
2016-09-12 10:16:06 +00:00
|
|
|
#include "src/wasm/wasm-opcodes.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define B1(a) WASM_BLOCK(a)
|
|
|
|
#define B2(a, b) WASM_BLOCK(a, b)
|
|
|
|
#define B3(a, b, c) WASM_BLOCK(a, b, c)
|
|
|
|
|
|
|
|
#define WASM_IF_OP kExprIf, kLocalVoid
|
|
|
|
#define WASM_LOOP_OP kExprLoop, kLocalVoid
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
static const byte kCodeGetLocal0[] = {kExprGetLocal, 0};
|
|
|
|
static const byte kCodeGetLocal1[] = {kExprGetLocal, 1};
|
2016-04-29 09:15:26 +00:00
|
|
|
static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)};
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte kCodeTeeLocal0[] = {WASM_TEE_LOCAL(0, WASM_ZERO)};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
static const ValueType kValueTypes[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64};
|
2015-12-11 12:26:16 +00:00
|
|
|
static const MachineType machineTypes[] = {
|
|
|
|
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
|
|
|
|
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
|
|
|
|
MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
|
|
|
|
MachineType::Float64()};
|
|
|
|
|
|
|
|
static const WasmOpcode kInt32BinopOpcodes[] = {
|
|
|
|
kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU,
|
|
|
|
kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor,
|
|
|
|
kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS,
|
|
|
|
kExprI32LeS, kExprI32LtU, kExprI32LeU};
|
|
|
|
|
2016-02-08 21:18:43 +00:00
|
|
|
#define WASM_BRV_IF_ZERO(depth, val) \
|
2016-09-27 20:46:10 +00:00
|
|
|
val, WASM_ZERO, kExprBrIf, static_cast<byte>(depth)
|
|
|
|
|
|
|
|
#define EXPECT_VERIFIES_C(sig, x) \
|
|
|
|
Verify(kSuccess, sigs.sig(), x, x + arraysize(x))
|
|
|
|
|
|
|
|
#define EXPECT_FAILURE_C(sig, x) Verify(kError, sigs.sig(), x, x + arraysize(x))
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_VERIFIES_SC(sig, x) Verify(kSuccess, sig, x, x + arraysize(x))
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_FAILURE_SC(sig, x) Verify(kError, sig, x, x + arraysize(x))
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_VERIFIES_S(env, ...) \
|
2015-12-11 12:26:16 +00:00
|
|
|
do { \
|
|
|
|
static byte code[] = {__VA_ARGS__}; \
|
|
|
|
Verify(kSuccess, env, code, code + arraysize(code)); \
|
|
|
|
} while (false)
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_FAILURE_S(env, ...) \
|
2015-12-11 12:26:16 +00:00
|
|
|
do { \
|
|
|
|
static byte code[] = {__VA_ARGS__}; \
|
|
|
|
Verify(kError, env, code, code + arraysize(code)); \
|
|
|
|
} while (false)
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_VERIFIES(sig, ...) \
|
2016-03-07 21:04:07 +00:00
|
|
|
do { \
|
|
|
|
static const byte code[] = {__VA_ARGS__}; \
|
2016-09-27 20:46:10 +00:00
|
|
|
Verify(kSuccess, sigs.sig(), code, code + sizeof(code)); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define EXPECT_FAILURE(sig, ...) \
|
|
|
|
do { \
|
|
|
|
static const byte code[] = {__VA_ARGS__}; \
|
|
|
|
Verify(kError, sigs.sig(), code, code + sizeof(code)); \
|
2015-12-11 12:26:16 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-09-21 13:15:59 +00:00
|
|
|
static bool old_eh_flag;
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
class FunctionBodyDecoderTest : public TestWithZone {
|
2015-12-11 12:26:16 +00:00
|
|
|
public:
|
2016-12-21 13:43:00 +00:00
|
|
|
typedef std::pair<uint32_t, ValueType> LocalsDecl;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
FunctionBodyDecoderTest() : module(nullptr), local_decls(zone()) {}
|
2016-05-17 17:53:46 +00:00
|
|
|
|
2016-09-21 13:15:59 +00:00
|
|
|
static void SetUpTestCase() { old_eh_flag = FLAG_wasm_eh_prototype; }
|
|
|
|
|
|
|
|
static void TearDownTestCase() {
|
|
|
|
// Reset the wasm_eh_prototype flag
|
|
|
|
FLAG_wasm_eh_prototype = old_eh_flag;
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TestSignatures sigs;
|
2016-03-07 21:04:07 +00:00
|
|
|
ModuleEnv* module;
|
|
|
|
LocalDeclEncoder local_decls;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
void AddLocals(ValueType type, uint32_t count) {
|
2016-03-07 21:04:07 +00:00
|
|
|
local_decls.AddLocals(count, type);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 09:15:26 +00:00
|
|
|
// Prepends local variable declarations and renders nice error messages for
|
2016-03-07 21:04:07 +00:00
|
|
|
// verification failures.
|
|
|
|
void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte* end) {
|
2016-05-25 08:32:37 +00:00
|
|
|
local_decls.Prepend(zone(), &start, &end);
|
2016-03-07 21:04:07 +00:00
|
|
|
// Verify the code.
|
2017-01-04 05:14:04 +00:00
|
|
|
DecodeResult result = VerifyWasmCode(
|
|
|
|
zone()->allocator(), module == nullptr ? nullptr : module->module, sig,
|
|
|
|
start, end);
|
2016-03-07 21:04:07 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
if (result.error_code != expected) {
|
|
|
|
ptrdiff_t pc = result.error_pc - result.start;
|
|
|
|
ptrdiff_t pt = result.error_pt - result.start;
|
|
|
|
std::ostringstream str;
|
|
|
|
if (expected == kSuccess) {
|
|
|
|
str << "Verification failed: " << result.error_code << " pc = +" << pc;
|
|
|
|
if (result.error_pt) str << ", pt = +" << pt;
|
|
|
|
str << ", msg = " << result.error_msg.get();
|
|
|
|
} else {
|
|
|
|
str << "Verification expected: " << expected << ", but got "
|
|
|
|
<< result.error_code;
|
|
|
|
if (result.error_code != kSuccess) {
|
|
|
|
str << " pc = +" << pc;
|
|
|
|
if (result.error_pt) str << ", pt = +" << pt;
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_TRUE(false) << str.str().c_str();
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestBinop(WasmOpcode opcode, FunctionSig* success) {
|
|
|
|
// op(local[0], local[1])
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(success, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
// Try all combinations of return and parameter types.
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
for (size_t k = 0; k < arraysize(kValueTypes); k++) {
|
|
|
|
ValueType types[] = {kValueTypes[i], kValueTypes[j], kValueTypes[k]};
|
2015-12-11 12:26:16 +00:00
|
|
|
if (types[0] != success->GetReturn(0) ||
|
|
|
|
types[1] != success->GetParam(0) ||
|
|
|
|
types[2] != success->GetParam(1)) {
|
|
|
|
// Test signature mismatch.
|
|
|
|
FunctionSig sig(1, 2, types);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestUnop(WasmOpcode opcode, FunctionSig* success) {
|
|
|
|
TestUnop(opcode, success->GetReturn(), success->GetParam(0));
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
void TestUnop(WasmOpcode opcode, ValueType ret_type, ValueType param_type) {
|
2015-12-11 12:26:16 +00:00
|
|
|
// Return(op(local[0]))
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))};
|
2015-12-11 12:26:16 +00:00
|
|
|
{
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType types[] = {ret_type, param_type};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 1, types);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try all combinations of return and parameter types.
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType types[] = {kValueTypes[i], kValueTypes[j]};
|
2015-12-11 12:26:16 +00:00
|
|
|
if (types[0] != ret_type || types[1] != param_type) {
|
|
|
|
// Test signature mismatch.
|
|
|
|
FunctionSig sig(1, 1, types);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int8Const) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code[] = {kExprI8Const, 0};
|
|
|
|
for (int i = -128; i < 128; i++) {
|
|
|
|
code[1] = static_cast<byte>(i);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, EmptyFunction) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code[] = {0};
|
2016-03-07 21:04:07 +00:00
|
|
|
Verify(kSuccess, sigs.v_v(), code, code);
|
|
|
|
Verify(kError, sigs.i_i(), code, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IncompleteIf1) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code[] = {kExprIf};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32V_1(0));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Const) {
|
2015-12-11 12:26:16 +00:00
|
|
|
const int kInc = 4498211;
|
|
|
|
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
|
2016-03-04 19:05:47 +00:00
|
|
|
// TODO(binji): expand test for other sized int32s; 1 through 5 bytes.
|
|
|
|
byte code[] = {WASM_I32V(i)};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int64Const) {
|
2015-12-11 12:26:16 +00:00
|
|
|
const int kInc = 4498211;
|
|
|
|
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
|
2016-03-04 19:05:47 +00:00
|
|
|
byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(l_l, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Float32Const) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code[] = {kExprF32Const, 0, 0, 0, 0};
|
|
|
|
float* ptr = reinterpret_cast<float*>(code + 1);
|
|
|
|
for (int i = 0; i < 30; i++) {
|
2016-08-26 12:29:44 +00:00
|
|
|
WriteLittleEndianValue<float>(ptr, i * -7.75f);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(f_ff, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Float64Const) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
double* ptr = reinterpret_cast<double*>(code + 1);
|
|
|
|
for (int i = 0; i < 30; i++) {
|
2016-08-26 12:29:44 +00:00
|
|
|
WriteLittleEndianValue<double>(ptr, i * 33.45);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(d_dd, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Const_off_end) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44};
|
|
|
|
|
|
|
|
for (int size = 1; size <= 4; size++) {
|
2016-03-07 21:04:07 +00:00
|
|
|
Verify(kError, sigs.i_i(), code, code + size);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal0_param) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, kCodeGetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal0_local) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_v, kCodeGetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TooManyLocals) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 4034986500);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_v, kCodeGetLocal0);
|
2016-08-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal0_param_n) {
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < arraysize(array); i++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocalN_local) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (byte i = 1; i < 8; i++) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
for (byte j = 0; j < i; j++) {
|
|
|
|
byte code[] = {kExprGetLocal, j};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal0_fail_no_params) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_v, kCodeGetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal1_fail_no_locals) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, kCodeGetLocal1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal_off_end) {
|
2015-12-11 12:26:16 +00:00
|
|
|
static const byte code[] = {kExprGetLocal};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NumLocalBelowLimit) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, kMaxNumWasmLocals - 1);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_NOP);
|
2016-08-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NumLocalAtLimit) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, kMaxNumWasmLocals);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_NOP);
|
2016-08-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NumLocalAboveLimit) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, kMaxNumWasmLocals + 1);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_v, WASM_NOP);
|
2016-08-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal_varint) {
|
2016-12-14 17:45:59 +00:00
|
|
|
const int kMaxLocals = kMaxNumWasmLocals - 1;
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, kMaxLocals);
|
2016-03-07 21:04:07 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66));
|
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777));
|
2016-12-14 17:45:59 +00:00
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(8888));
|
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(9999));
|
2016-09-27 20:46:10 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1));
|
|
|
|
EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals));
|
|
|
|
EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals));
|
|
|
|
EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal_toomany) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, kMaxNumWasmLocals - 100);
|
|
|
|
AddLocals(kWasmI32, 100);
|
2016-12-14 17:45:59 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_v, kExprGetLocal, U32V_1(66));
|
|
|
|
EXPECT_FAILURE(i_i, kExprGetLocal, U32V_1(66));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Binops_off_end) {
|
2015-12-11 12:26:16 +00:00
|
|
|
byte code1[] = {0}; // [opcode]
|
|
|
|
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
|
|
|
|
code1[0] = kInt32BinopOpcodes[i];
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode]
|
2015-12-11 12:26:16 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
|
2016-04-29 09:15:26 +00:00
|
|
|
code3[2] = kInt32BinopOpcodes[i];
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code3);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode]
|
2015-12-11 12:26:16 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
|
2016-05-09 10:34:17 +00:00
|
|
|
code4[2] = kInt32BinopOpcodes[i];
|
2015-12-11 12:26:16 +00:00
|
|
|
code4[3] = kInt32BinopOpcodes[i];
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code4);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock1) {
|
2016-05-09 10:34:17 +00:00
|
|
|
static const byte code[] = {WASM_ZERO, kExprBlock, WASM_ZERO, kExprI32Add,
|
|
|
|
kExprEnd};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2016-05-09 10:34:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock2) {
|
2016-05-09 10:34:17 +00:00
|
|
|
static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, kExprI32Add,
|
|
|
|
kExprEnd};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2016-05-09 10:34:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock3) {
|
2016-05-09 10:34:17 +00:00
|
|
|
static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kExprI32Add,
|
|
|
|
kExprElse, kExprI32Add, kExprEnd};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2016-05-09 10:34:17 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Nop) {
|
2015-12-11 12:26:16 +00:00
|
|
|
static const byte code[] = {kExprNop};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SetLocal0_void) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_SET_LOCAL(0, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SetLocal0_param) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, kCodeSetLocal0);
|
|
|
|
EXPECT_FAILURE_C(f_ff, kCodeSetLocal0);
|
|
|
|
EXPECT_FAILURE_C(d_dd, kCodeSetLocal0);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TeeLocal0_param) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0);
|
|
|
|
EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0);
|
|
|
|
EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SetLocal0_local) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_v, kCodeSetLocal0);
|
|
|
|
EXPECT_FAILURE_C(v_v, kCodeSetLocal0);
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_v, kCodeSetLocal0);
|
|
|
|
EXPECT_VERIFIES_C(v_v, kCodeSetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_v, kCodeTeeLocal0);
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (byte i = 1; i < 8; i++) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
for (byte j = 0; j < i; j++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockN) {
|
2016-04-29 09:15:26 +00:00
|
|
|
const int kMaxSize = 200;
|
2016-09-27 20:46:10 +00:00
|
|
|
byte buffer[kMaxSize + 3];
|
2016-04-29 09:15:26 +00:00
|
|
|
|
|
|
|
for (int i = 0; i <= kMaxSize; i++) {
|
|
|
|
memset(buffer, kExprNop, sizeof(buffer));
|
|
|
|
buffer[0] = kExprBlock;
|
2016-09-27 20:46:10 +00:00
|
|
|
buffer[1] = kLocalVoid;
|
|
|
|
buffer[i + 2] = kExprEnd;
|
|
|
|
Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 3);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define WASM_EMPTY_BLOCK kExprBlock, kLocalVoid, kExprEnd
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {WASM_EMPTY_BLOCK};
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0_fallthru1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {WASM_BLOCK(WASM_EMPTY_BLOCK)};
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0Block0) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK};
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0_end) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0_end_end) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))};
|
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
|
|
|
EXPECT_FAILURE_C(d_dd, code);
|
|
|
|
EXPECT_FAILURE_C(i_f, code);
|
|
|
|
EXPECT_FAILURE_C(i_d, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block1_i) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_I(WASM_ZERO)};
|
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(f_ff, code);
|
|
|
|
EXPECT_FAILURE_C(d_dd, code);
|
|
|
|
EXPECT_FAILURE_C(l_ll, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block1_f) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_F(WASM_F32(0))};
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
|
|
|
EXPECT_VERIFIES_C(f_ff, code);
|
|
|
|
EXPECT_FAILURE_C(d_dd, code);
|
|
|
|
EXPECT_FAILURE_C(l_ll, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block1_continue) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0)));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block1_br) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, B1(WASM_BR(0)));
|
|
|
|
EXPECT_VERIFIES(v_v, B1(WASM_BR(1)));
|
|
|
|
EXPECT_FAILURE(v_v, B1(WASM_BR(2)));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block2_br) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_BR(0)));
|
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_BR(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK(WASM_NOP, WASM_NOP));
|
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_NOP, WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_NOP, WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_NOP));
|
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block2b) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)};
|
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(f_ff, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block2_fallthru) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(
|
|
|
|
i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)),
|
|
|
|
WASM_I8(23));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block3) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block5) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO));
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(
|
|
|
|
v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
|
|
|
}
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockType) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(f_f, WASM_BLOCK_F(WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(d_d, WASM_BLOCK_D(WASM_GET_LOCAL(0)));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockType_fail) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK_F(WASM_F32(0.0)));
|
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK_D(WASM_F64(1.1)));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(l_l, WASM_BLOCK_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(l_l, WASM_BLOCK_F(WASM_F32(0.0)));
|
|
|
|
EXPECT_FAILURE(l_l, WASM_BLOCK_D(WASM_F64(1.1)));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(f_ff, WASM_BLOCK_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(f_ff, WASM_BLOCK_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(f_ff, WASM_BLOCK_D(WASM_F64(1.1)));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(d_dd, WASM_BLOCK_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(d_dd, WASM_BLOCK_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(d_dd, WASM_BLOCK_F(WASM_F32(0.0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockF32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {WASM_BLOCK_F(kExprF32Const, 0, 0, 0, 0)};
|
|
|
|
EXPECT_VERIFIES_C(f_ff, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(d_dd, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockN_off_end) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK(kExprNop, kExprNop, kExprNop, kExprNop)};
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
for (size_t i = 1; i < arraysize(code); i++) {
|
|
|
|
Verify(kError, sigs.v_v(), code, code + i);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block2_continue) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(0)));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(1)));
|
|
|
|
EXPECT_FAILURE(v_v, WASM_LOOP(WASM_NOP, WASM_BR(2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block3_continue) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0))));
|
|
|
|
EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1))));
|
|
|
|
EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2))));
|
|
|
|
EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3))));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NestedBlock_return) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO))));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockBrBinop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(
|
|
|
|
i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_empty1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd);
|
2016-05-09 14:45:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_empty2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd);
|
2016-05-09 14:45:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_empty3) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd);
|
|
|
|
EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd);
|
2016-05-09 14:45:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_empty4) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd);
|
|
|
|
EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd);
|
2016-05-09 14:45:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_empty_stack) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {kExprIf};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_incomplete1) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {kExprI8Const, 0, kExprIf};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_incomplete2) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {kExprI8Const, 0, kExprIf, kExprNop};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_else_else) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd};
|
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfEmpty) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfSet) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i,
|
|
|
|
WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO)));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseEmpty) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd);
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseUnreachable1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE,
|
|
|
|
WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
|
|
|
WASM_UNREACHABLE));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseUnreachable2) {
|
2016-04-29 09:15:26 +00:00
|
|
|
static const byte code[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType types[] = {kWasmI32, kValueTypes[i]};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 1, types);
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (kValueTypes[i] == kWasmI32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfBreak) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0)));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1)));
|
|
|
|
EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseBreak) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0)));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1)));
|
|
|
|
EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2)));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block_else) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfNop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfNopElseNop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_end_end) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd};
|
|
|
|
EXPECT_VERIFIES_C(v_i, code);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_end_end_end) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP,
|
|
|
|
kExprEnd, kExprEnd, kExprEnd};
|
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_falloff1) {
|
2016-04-29 09:15:26 +00:00
|
|
|
static const byte code[] = {kExprGetLocal, 0, kExprIf};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_falloff2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP};
|
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElse_falloff) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprNop,
|
|
|
|
kExprElse};
|
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseNop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfBlock1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(
|
|
|
|
v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)),
|
|
|
|
WASM_NOP));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfBlock1b) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i,
|
|
|
|
WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO))));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfBlock2a) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i,
|
|
|
|
WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO),
|
2016-04-29 09:15:26 +00:00
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO))));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfBlock2b) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(
|
|
|
|
v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO)),
|
|
|
|
WASM_NOP));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseSet) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i,
|
|
|
|
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO),
|
2016-04-29 09:15:26 +00:00
|
|
|
WASM_SET_LOCAL(0, WASM_I8(1))));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop0) {
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop1) {
|
2016-07-21 11:04:06 +00:00
|
|
|
static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_i, code);
|
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(f_ff, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop1_continue) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop1_break) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(1)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop2_continue) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop2_break) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1)));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, InfiniteLoop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoopType) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoopType_void) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_v, WASM_LOOP_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(v_v, WASM_LOOP_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(v_v, WASM_LOOP_F(WASM_F32(0.0)));
|
|
|
|
EXPECT_FAILURE(v_v, WASM_LOOP_D(WASM_F64(1.1)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoopType_fail) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_LOOP_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(i_i, WASM_LOOP_F(WASM_F32(0.0)));
|
|
|
|
EXPECT_FAILURE(i_i, WASM_LOOP_D(WASM_F64(1.1)));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(l_l, WASM_LOOP_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(l_l, WASM_LOOP_F(WASM_F32(0.0)));
|
|
|
|
EXPECT_FAILURE(l_l, WASM_LOOP_D(WASM_F64(1.1)));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(f_ff, WASM_LOOP_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(f_ff, WASM_LOOP_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(f_ff, WASM_LOOP_D(WASM_F64(1.1)));
|
|
|
|
|
|
|
|
EXPECT_FAILURE(d_dd, WASM_LOOP_I(WASM_ZERO));
|
|
|
|
EXPECT_FAILURE(d_dd, WASM_LOOP_L(WASM_I64V_1(0)));
|
|
|
|
EXPECT_FAILURE(d_dd, WASM_LOOP_F(WASM_F32(0.0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ReturnVoid1) {
|
2015-12-11 12:26:16 +00:00
|
|
|
static const byte code[] = {kExprNop};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(i_f, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ReturnVoid2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte code[] = {WASM_BLOCK(WASM_BR(0))};
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(i_f, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ReturnVoid3) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_v, kExprI8Const, 0);
|
|
|
|
EXPECT_FAILURE(v_v, kExprI32Const, 0);
|
|
|
|
EXPECT_FAILURE(v_v, kExprI64Const, 0);
|
|
|
|
EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0);
|
|
|
|
EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_i, kExprGetLocal, 0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, kExprUnreachable);
|
|
|
|
EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable);
|
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable_binop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable_select) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i,
|
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8)));
|
|
|
|
EXPECT_VERIFIES(
|
|
|
|
i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES(
|
|
|
|
i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_off_end) {
|
2016-04-29 09:15:26 +00:00
|
|
|
static const byte kCode[] = {
|
|
|
|
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))};
|
|
|
|
for (size_t len = 3; len < arraysize(kCode); len++) {
|
2016-03-07 21:04:07 +00:00
|
|
|
Verify(kError, sigs.i_i(), kCode, kCode + len);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_type1) {
|
2016-04-29 09:15:26 +00:00
|
|
|
// float|double ? 1 : 2
|
|
|
|
static const byte kCode[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))};
|
|
|
|
EXPECT_VERIFIES_C(i_i, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_f, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_d, kCode);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_type2) {
|
2016-04-29 09:15:26 +00:00
|
|
|
// 1 ? float|double : 2
|
|
|
|
static const byte kCode[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))};
|
|
|
|
EXPECT_VERIFIES_C(i_i, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_f, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_d, kCode);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_type3) {
|
2016-04-29 09:15:26 +00:00
|
|
|
// stmt ? 0 : 1
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte kCode[] = {
|
|
|
|
WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))};
|
|
|
|
EXPECT_FAILURE_C(i_i, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_f, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_d, kCode);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_type4) {
|
2016-04-29 09:15:26 +00:00
|
|
|
// 0 ? stmt : 1
|
|
|
|
static const byte kCode[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))};
|
|
|
|
EXPECT_FAILURE_C(i_i, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_f, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_d, kCode);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_type5) {
|
2016-04-29 09:15:26 +00:00
|
|
|
// 0 ? 1 : stmt
|
2016-09-27 20:46:10 +00:00
|
|
|
static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)};
|
|
|
|
EXPECT_FAILURE_C(i_i, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_f, kCode);
|
|
|
|
EXPECT_FAILURE_C(i_d, kCode);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int64Local_param) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(l_l, kCodeGetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int64Locals) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (byte i = 1; i < 8; i++) {
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI64, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
for (byte j = 0; j < i; j++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Binops) {
|
2015-12-11 12:26:16 +00:00
|
|
|
TestBinop(kExprI32Add, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32Sub, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32Mul, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32DivS, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32DivU, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32RemS, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32RemU, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32And, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32Ior, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32Xor, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32Shl, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32ShrU, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32ShrS, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32Eq, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32LtS, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32LeS, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32LtU, sigs.i_ii());
|
|
|
|
TestBinop(kExprI32LeU, sigs.i_ii());
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, DoubleBinops) {
|
2015-12-11 12:26:16 +00:00
|
|
|
TestBinop(kExprF64Add, sigs.d_dd());
|
|
|
|
TestBinop(kExprF64Sub, sigs.d_dd());
|
|
|
|
TestBinop(kExprF64Mul, sigs.d_dd());
|
|
|
|
TestBinop(kExprF64Div, sigs.d_dd());
|
|
|
|
|
|
|
|
TestBinop(kExprF64Eq, sigs.i_dd());
|
|
|
|
TestBinop(kExprF64Lt, sigs.i_dd());
|
|
|
|
TestBinop(kExprF64Le, sigs.i_dd());
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, FloatBinops) {
|
2015-12-11 12:26:16 +00:00
|
|
|
TestBinop(kExprF32Add, sigs.f_ff());
|
|
|
|
TestBinop(kExprF32Sub, sigs.f_ff());
|
|
|
|
TestBinop(kExprF32Mul, sigs.f_ff());
|
|
|
|
TestBinop(kExprF32Div, sigs.f_ff());
|
|
|
|
|
|
|
|
TestBinop(kExprF32Eq, sigs.i_ff());
|
|
|
|
TestBinop(kExprF32Lt, sigs.i_ff());
|
|
|
|
TestBinop(kExprF32Le, sigs.i_ff());
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TypeConversions) {
|
2016-12-21 13:43:00 +00:00
|
|
|
TestUnop(kExprI32SConvertF32, kWasmI32, kWasmF32);
|
|
|
|
TestUnop(kExprI32SConvertF64, kWasmI32, kWasmF64);
|
|
|
|
TestUnop(kExprI32UConvertF32, kWasmI32, kWasmF32);
|
|
|
|
TestUnop(kExprI32UConvertF64, kWasmI32, kWasmF64);
|
|
|
|
TestUnop(kExprF64SConvertI32, kWasmF64, kWasmI32);
|
|
|
|
TestUnop(kExprF64UConvertI32, kWasmF64, kWasmI32);
|
|
|
|
TestUnop(kExprF64ConvertF32, kWasmF64, kWasmF32);
|
|
|
|
TestUnop(kExprF32SConvertI32, kWasmF32, kWasmI32);
|
|
|
|
TestUnop(kExprF32UConvertI32, kWasmF32, kWasmI32);
|
|
|
|
TestUnop(kExprF32ConvertF64, kWasmF32, kWasmF64);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosStmt) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
|
|
|
|
EXPECT_VERIFIES(
|
|
|
|
v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40)));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_NOP);
|
|
|
|
EXPECT_VERIFIES(v_v, B1(WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosContinue) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosVariadic) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, B3(WASM_NOP, WASM_NOP, WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosNestedBlocks) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP)));
|
|
|
|
EXPECT_VERIFIES(v_v, B3(WASM_NOP, // --
|
|
|
|
B2(WASM_NOP, WASM_NOP), // --
|
|
|
|
B2(WASM_NOP, WASM_NOP))); // --
|
|
|
|
EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP))));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultipleReturn) {
|
2016-12-21 13:43:00 +00:00
|
|
|
static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32,
|
|
|
|
kWasmI32};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig_ii_v(2, 0, kIntTypes5);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
|
|
|
|
EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
FunctionSig sig_iii_v(3, 0, kIntTypes5);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig_iii_v,
|
|
|
|
WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44)));
|
|
|
|
EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) {
|
2016-12-21 13:43:00 +00:00
|
|
|
static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32,
|
|
|
|
kWasmI32};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig_ii_v(2, 0, kIntTypes5);
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE);
|
|
|
|
EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
FunctionSig sig_iii_v(3, 0, kIntTypes5);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44));
|
|
|
|
EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosInt32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25)));
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29)));
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosInt64) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21)));
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24)));
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29)));
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29)));
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25)));
|
|
|
|
EXPECT_VERIFIES(i_ll, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllSimpleExpressions) {
|
2015-12-11 12:26:16 +00:00
|
|
|
// Test all simple expressions which are described by a signature.
|
|
|
|
#define DECODE_TEST(name, opcode, sig) \
|
|
|
|
{ \
|
|
|
|
FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \
|
|
|
|
if (sig->parameter_count() == 1) { \
|
|
|
|
TestUnop(kExpr##name, sig); \
|
|
|
|
} else { \
|
|
|
|
TestBinop(kExpr##name, sig); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
FOREACH_SIMPLE_OPCODE(DECODE_TEST);
|
|
|
|
|
|
|
|
#undef DECODE_TEST
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MemorySize) {
|
2016-10-26 16:56:05 +00:00
|
|
|
byte code[] = {kExprMemorySize, 0};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(f_ff, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoadMemOffset) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int offset = 0; offset < 128; offset += 7) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT,
|
|
|
|
static_cast<byte>(offset)};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) {
|
2016-09-02 11:59:09 +00:00
|
|
|
struct {
|
|
|
|
WasmOpcode instruction;
|
|
|
|
uint32_t maximum_aligment;
|
|
|
|
} values[] = {
|
|
|
|
{kExprI32LoadMem8U, 0}, // --
|
|
|
|
{kExprI32LoadMem8S, 0}, // --
|
|
|
|
{kExprI32LoadMem16U, 1}, // --
|
|
|
|
{kExprI32LoadMem16S, 1}, // --
|
|
|
|
{kExprI64LoadMem8U, 0}, // --
|
|
|
|
{kExprI64LoadMem8S, 0}, // --
|
|
|
|
{kExprI64LoadMem16U, 1}, // --
|
|
|
|
{kExprI64LoadMem16S, 1}, // --
|
|
|
|
{kExprI64LoadMem32U, 2}, // --
|
|
|
|
{kExprI64LoadMem32S, 2}, // --
|
|
|
|
{kExprI32LoadMem, 2}, // --
|
|
|
|
{kExprI64LoadMem, 3}, // --
|
|
|
|
{kExprF32LoadMem, 2}, // --
|
|
|
|
{kExprF64LoadMem, 3}, // --
|
|
|
|
};
|
|
|
|
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(values); i++) {
|
2016-09-02 11:59:09 +00:00
|
|
|
for (byte alignment = 0; alignment <= 4; alignment++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_ZERO, static_cast<byte>(values[i].instruction),
|
|
|
|
alignment, ZERO_OFFSET, WASM_DROP};
|
2016-09-02 11:59:09 +00:00
|
|
|
if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_i, code);
|
2016-09-02 11:59:09 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
2016-09-02 11:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StoreMemOffset) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int offset = 0; offset < 128; offset += 7) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset,
|
|
|
|
WASM_ZERO, WASM_ZERO)};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StoreMemOffset_void) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO,
|
|
|
|
WASM_ZERO));
|
|
|
|
}
|
|
|
|
|
2016-04-29 09:15:26 +00:00
|
|
|
#define BYTE0(x) ((x)&0x7F)
|
|
|
|
#define BYTE1(x) ((x >> 7) & 0x7F)
|
|
|
|
#define BYTE2(x) ((x >> 14) & 0x7F)
|
|
|
|
#define BYTE3(x) ((x >> 21) & 0x7F)
|
|
|
|
|
|
|
|
#define VARINT1(x) BYTE0(x)
|
|
|
|
#define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x)
|
|
|
|
#define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x)
|
|
|
|
#define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x)
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoadMemOffset_varint) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT1(0x45));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT2(0x3999));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT3(0x344445));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT4(0x36666667));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StoreMemOffset_varint) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT1(0x33));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT2(0x1111));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT3(0x222222));
|
|
|
|
EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT,
|
|
|
|
VARINT4(0x44444444));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType local_type = kValueTypes[i];
|
2015-12-11 12:26:16 +00:00
|
|
|
for (size_t j = 0; j < arraysize(machineTypes); j++) {
|
|
|
|
MachineType mem_type = machineTypes[j];
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 0, &local_type);
|
2016-12-21 13:43:00 +00:00
|
|
|
if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType local_type = kValueTypes[i];
|
2015-12-11 12:26:16 +00:00
|
|
|
for (size_t j = 0; j < arraysize(machineTypes); j++) {
|
|
|
|
MachineType mem_type = machineTypes[j];
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(0, 1, &local_type);
|
2016-12-21 13:43:00 +00:00
|
|
|
if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// A helper for tests that require a module environment for functions and
|
|
|
|
// globals.
|
|
|
|
class TestModuleEnv : public ModuleEnv {
|
|
|
|
public:
|
2016-11-30 15:02:40 +00:00
|
|
|
explicit TestModuleEnv(ModuleOrigin origin = kWasmOrigin)
|
|
|
|
: ModuleEnv(&mod, nullptr) {
|
|
|
|
mod.origin = origin;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2016-12-21 13:43:00 +00:00
|
|
|
byte AddGlobal(ValueType type, bool mutability = true) {
|
2016-10-06 15:43:10 +00:00
|
|
|
mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false});
|
2016-02-28 19:04:10 +00:00
|
|
|
CHECK(mod.globals.size() <= 127);
|
|
|
|
return static_cast<byte>(mod.globals.size() - 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
byte AddSignature(FunctionSig* sig) {
|
2016-02-28 19:04:10 +00:00
|
|
|
mod.signatures.push_back(sig);
|
|
|
|
CHECK(mod.signatures.size() <= 127);
|
|
|
|
return static_cast<byte>(mod.signatures.size() - 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
byte AddFunction(FunctionSig* sig) {
|
2016-09-27 20:46:10 +00:00
|
|
|
mod.functions.push_back({sig, // sig
|
|
|
|
0, // func_index
|
|
|
|
0, // sig_index
|
|
|
|
0, // name_offset
|
|
|
|
0, // name_length
|
|
|
|
0, // code_start_offset
|
|
|
|
0, // code_end_offset
|
|
|
|
false, // import
|
|
|
|
false}); // export
|
2016-02-28 19:04:10 +00:00
|
|
|
CHECK(mod.functions.size() <= 127);
|
|
|
|
return static_cast<byte>(mod.functions.size() - 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2016-02-19 14:58:25 +00:00
|
|
|
byte AddImport(FunctionSig* sig) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte result = AddFunction(sig);
|
|
|
|
mod.functions[result].imported = true;
|
|
|
|
return result;
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-11-09 08:37:05 +00:00
|
|
|
void InitializeFunctionTable() {
|
|
|
|
mod.function_tables.push_back(
|
|
|
|
{0, 0, true, std::vector<int32_t>(), false, false, SignatureMap()});
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
private:
|
|
|
|
WasmModule mod;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleCalls) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
module_env.AddFunction(sigs.i_v());
|
|
|
|
module_env.AddFunction(sigs.i_i());
|
|
|
|
module_env.AddFunction(sigs.i_ii());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(27)));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
module_env.AddFunction(sigs.i_i());
|
|
|
|
module_env.AddFunction(sigs.i_ii());
|
|
|
|
module_env.AddFunction(sigs.f_ff());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(0));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_ZERO));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs2) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
module_env.AddFunction(sigs.i_i());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
module_env.AddFunction(sigs.i_f());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
module_env.AddFunction(sigs.i_d());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiReturn) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FLAG_wasm_mv_prototype = true;
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType storage[] = {kWasmI32, kWasmI32};
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig sig_ii_v(2, 0, storage);
|
|
|
|
FunctionSig sig_v_ii(0, 2, storage);
|
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
|
|
|
|
|
|
|
module_env.AddFunction(&sig_v_ii);
|
|
|
|
module_env.AddFunction(&sig_ii_v);
|
|
|
|
|
|
|
|
EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1));
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP);
|
|
|
|
EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiReturnType) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FLAG_wasm_mv_prototype = true;
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t a = 0; a < arraysize(kValueTypes); a++) {
|
|
|
|
for (size_t b = 0; b < arraysize(kValueTypes); b++) {
|
|
|
|
for (size_t c = 0; c < arraysize(kValueTypes); c++) {
|
|
|
|
for (size_t d = 0; d < arraysize(kValueTypes); d++) {
|
|
|
|
ValueType storage_ab[] = {kValueTypes[a], kValueTypes[b]};
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig sig_ab_v(2, 0, storage_ab);
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType storage_cd[] = {kValueTypes[c], kValueTypes[d]};
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig sig_cd_v(2, 0, storage_cd);
|
|
|
|
|
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
|
|
|
module_env.AddFunction(&sig_cd_v);
|
|
|
|
|
|
|
|
EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0));
|
|
|
|
|
|
|
|
if (a == c && b == d) {
|
|
|
|
EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0));
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE_S(&sig_ab_v, WASM_CALL_FUNCTION0(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleIndirectCalls) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-11-09 08:37:05 +00:00
|
|
|
module_env.InitializeFunctionTable();
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
byte f0 = module_env.AddSignature(sigs.i_v());
|
|
|
|
byte f1 = module_env.AddSignature(sigs.i_i());
|
|
|
|
byte f2 = module_env.AddSignature(sigs.i_ii());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22)));
|
|
|
|
EXPECT_VERIFIES_S(
|
2016-04-29 09:15:26 +00:00
|
|
|
sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-11-09 08:37:05 +00:00
|
|
|
module_env.InitializeFunctionTable();
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
module_env.AddSignature(sigs.i_v());
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22)));
|
2015-12-11 12:26:16 +00:00
|
|
|
module_env.AddSignature(sigs.i_i());
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-11-09 08:37:05 +00:00
|
|
|
module_env.InitializeFunctionTable();
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
byte f0 = module_env.AddFunction(sigs.i_f());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
byte f1 = module_env.AddFunction(sigs.i_d());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) {
|
2016-11-09 08:37:05 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
|
|
|
|
|
|
|
byte f0 = module_env.AddSignature(sigs.i_v());
|
|
|
|
byte f1 = module_env.AddSignature(sigs.i_i());
|
|
|
|
byte f2 = module_env.AddSignature(sigs.i_ii());
|
|
|
|
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22)));
|
|
|
|
EXPECT_FAILURE_S(
|
|
|
|
sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72)));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2016-02-19 14:58:25 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2016-02-19 14:58:25 +00:00
|
|
|
|
|
|
|
byte f0 = module_env.AddImport(sigs.i_v());
|
|
|
|
byte f1 = module_env.AddImport(sigs.i_i());
|
|
|
|
byte f2 = module_env.AddImport(sigs.i_ii());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(22)));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72)));
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2016-02-19 14:58:25 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2016-02-19 14:58:25 +00:00
|
|
|
|
|
|
|
byte f0 = module_env.AddImport(sigs.i_f());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I8(17)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2)));
|
2016-02-19 14:58:25 +00:00
|
|
|
|
|
|
|
byte f1 = module_env.AddImport(sigs.i_d());
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16)));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6)));
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Globals) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
module_env.AddGlobal(kWasmI32);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig* sig = sigs.v_v();
|
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
uint32_t g0 = module_env.AddGlobal(kWasmI32, true);
|
|
|
|
uint32_t g1 = module_env.AddGlobal(kWasmI32, false);
|
2016-09-27 20:46:10 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Globals_fail) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
module_env.AddGlobal(kWasmI64);
|
|
|
|
module_env.AddGlobal(kWasmI64);
|
|
|
|
module_env.AddGlobal(kWasmF32);
|
|
|
|
module_env.AddGlobal(kWasmF64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2));
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO);
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO);
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO);
|
|
|
|
EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int64Globals) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.l_l();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
module_env.AddGlobal(kWasmI64);
|
|
|
|
module_env.AddGlobal(kWasmI64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)),
|
|
|
|
WASM_GET_LOCAL(0));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)),
|
|
|
|
WASM_GET_LOCAL(0));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Float32Globals) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.f_ff();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
module_env.AddGlobal(kWasmF32);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)),
|
|
|
|
WASM_GET_LOCAL(0));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Float64Globals) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sig = sigs.d_dd();
|
2015-12-11 12:26:16 +00:00
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
module_env.AddGlobal(kWasmF64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0));
|
|
|
|
EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)),
|
|
|
|
WASM_GET_LOCAL(0));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllGetGlobalCombinations) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType local_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType global_type = kValueTypes[j];
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 0, &local_type);
|
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2016-07-21 12:34:28 +00:00
|
|
|
module_env.AddGlobal(global_type);
|
|
|
|
if (local_type == global_type) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0));
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllSetGlobalCombinations) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType local_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType global_type = kValueTypes[j];
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(0, 1, &local_type);
|
|
|
|
TestModuleEnv module_env;
|
2016-03-07 21:04:07 +00:00
|
|
|
module = &module_env;
|
2016-07-21 12:34:28 +00:00
|
|
|
module_env.AddGlobal(global_type);
|
|
|
|
if (local_type == global_type) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, WasmGrowMemory) {
|
2016-09-12 10:16:06 +00:00
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
|
|
|
|
2016-10-26 16:56:05 +00:00
|
|
|
byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(i_d, code);
|
2016-09-12 10:16:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AsmJsGrowMemory) {
|
2016-11-30 15:02:40 +00:00
|
|
|
TestModuleEnv module_env(kAsmJsOrigin);
|
2016-09-12 10:16:06 +00:00
|
|
|
module = &module_env;
|
|
|
|
|
2016-10-26 16:56:05 +00:00
|
|
|
byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2016-09-12 10:16:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) {
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType float32int32float32[] = {kWasmF32, kWasmI32, kWasmF32};
|
2016-09-12 10:16:06 +00:00
|
|
|
FunctionSig sig_f_if(1, 2, float32int32float32);
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType float64int32float64[] = {kWasmF64, kWasmI32, kWasmF64};
|
2016-09-12 10:16:06 +00:00
|
|
|
FunctionSig sig_d_id(1, 2, float64int32float64);
|
|
|
|
struct {
|
|
|
|
WasmOpcode op;
|
|
|
|
FunctionSig* sig;
|
|
|
|
} AsmJsBinOps[] = {
|
|
|
|
{kExprF64Atan2, sigs.d_dd()},
|
|
|
|
{kExprF64Pow, sigs.d_dd()},
|
|
|
|
{kExprF64Mod, sigs.d_dd()},
|
|
|
|
{kExprI32AsmjsDivS, sigs.i_ii()},
|
|
|
|
{kExprI32AsmjsDivU, sigs.i_ii()},
|
|
|
|
{kExprI32AsmjsRemS, sigs.i_ii()},
|
|
|
|
{kExprI32AsmjsRemU, sigs.i_ii()},
|
|
|
|
{kExprI32AsmjsStoreMem8, sigs.i_ii()},
|
|
|
|
{kExprI32AsmjsStoreMem16, sigs.i_ii()},
|
|
|
|
{kExprI32AsmjsStoreMem, sigs.i_ii()},
|
|
|
|
{kExprF32AsmjsStoreMem, &sig_f_if},
|
|
|
|
{kExprF64AsmjsStoreMem, &sig_d_id},
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2016-11-30 15:02:40 +00:00
|
|
|
TestModuleEnv module_env(kAsmJsOrigin);
|
2016-09-12 10:16:06 +00:00
|
|
|
module = &module_env;
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) {
|
2016-09-12 10:16:06 +00:00
|
|
|
TestBinop(AsmJsBinOps[i].op, AsmJsBinOps[i].sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) {
|
2016-09-12 10:16:06 +00:00
|
|
|
byte code[] = {
|
|
|
|
WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code);
|
2016-09-12 10:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) {
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType float32int32[] = {kWasmF32, kWasmI32};
|
2016-09-21 14:07:18 +00:00
|
|
|
FunctionSig sig_f_i(1, 1, float32int32);
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType float64int32[] = {kWasmF64, kWasmI32};
|
2016-09-21 14:07:18 +00:00
|
|
|
FunctionSig sig_d_i(1, 1, float64int32);
|
2016-09-12 10:16:06 +00:00
|
|
|
struct {
|
|
|
|
WasmOpcode op;
|
|
|
|
FunctionSig* sig;
|
|
|
|
} AsmJsUnOps[] = {{kExprF64Acos, sigs.d_d()},
|
|
|
|
{kExprF64Asin, sigs.d_d()},
|
|
|
|
{kExprF64Atan, sigs.d_d()},
|
|
|
|
{kExprF64Cos, sigs.d_d()},
|
|
|
|
{kExprF64Sin, sigs.d_d()},
|
|
|
|
{kExprF64Tan, sigs.d_d()},
|
|
|
|
{kExprF64Exp, sigs.d_d()},
|
|
|
|
{kExprF64Log, sigs.d_d()},
|
|
|
|
{kExprI32AsmjsLoadMem8S, sigs.i_i()},
|
|
|
|
{kExprI32AsmjsLoadMem8U, sigs.i_i()},
|
|
|
|
{kExprI32AsmjsLoadMem16S, sigs.i_i()},
|
|
|
|
{kExprI32AsmjsLoadMem16U, sigs.i_i()},
|
|
|
|
{kExprI32AsmjsLoadMem, sigs.i_i()},
|
|
|
|
{kExprF32AsmjsLoadMem, &sig_f_i},
|
|
|
|
{kExprF64AsmjsLoadMem, &sig_d_i},
|
|
|
|
{kExprI32AsmjsSConvertF32, sigs.i_f()},
|
|
|
|
{kExprI32AsmjsUConvertF32, sigs.i_f()},
|
|
|
|
{kExprI32AsmjsSConvertF64, sigs.i_d()},
|
|
|
|
{kExprI32AsmjsUConvertF64, sigs.i_d()}};
|
|
|
|
{
|
2016-11-30 15:02:40 +00:00
|
|
|
TestModuleEnv module_env(kAsmJsOrigin);
|
2016-09-12 10:16:06 +00:00
|
|
|
module = &module_env;
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) {
|
2016-09-12 10:16:06 +00:00
|
|
|
TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
TestModuleEnv module_env;
|
|
|
|
module = &module_env;
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) {
|
2016-09-12 10:16:06 +00:00
|
|
|
byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code);
|
2016-09-12 10:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakEnd) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(
|
|
|
|
i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO)));
|
|
|
|
EXPECT_VERIFIES(
|
|
|
|
i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO))));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIfBinop) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD(
|
|
|
|
WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD(
|
|
|
|
WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))));
|
|
|
|
EXPECT_VERIFIES_S(
|
|
|
|
sigs.f_ff(),
|
|
|
|
WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO))));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIfBinop_fail) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(
|
|
|
|
sigs.f_ff(),
|
|
|
|
WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))));
|
|
|
|
EXPECT_FAILURE_S(
|
|
|
|
sigs.i_i(),
|
|
|
|
WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO))));
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakNesting1) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
// (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_I(
|
2016-07-21 11:04:06 +00:00
|
|
|
WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)),
|
|
|
|
WASM_SET_LOCAL(0, WASM_I8(1))),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_ZERO)};
|
2015-12-11 12:26:16 +00:00
|
|
|
if (i < 3) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakNesting2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
for (int i = 0; i < 7; i++) {
|
|
|
|
byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BR(i)), WASM_NOP))};
|
|
|
|
if (i <= 3) {
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakNesting3) {
|
2016-09-27 20:46:10 +00:00
|
|
|
for (int i = 0; i < 7; i++) {
|
2016-03-07 21:04:07 +00:00
|
|
|
// (block[1] (loop[1] (block[1] (if 0 break[N])
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))};
|
|
|
|
if (i < 4) {
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
|
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), WASM_BRV_IF_ZERO(0, WASM_I8(0)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
|
|
|
|
EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_I8(11))));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int mask = 0; mask < 64; mask++) {
|
|
|
|
for (int i = 0; i < 14; i++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK(WASM_BLOCK(
|
|
|
|
WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
int depth = 6;
|
2016-09-27 20:46:10 +00:00
|
|
|
int m = mask;
|
|
|
|
for (size_t pos = 0; pos < sizeof(code); pos++) {
|
|
|
|
if (code[pos] != kExprBlock) continue;
|
|
|
|
if (m & 1) {
|
|
|
|
code[pos] = kExprLoop;
|
|
|
|
code[pos + 1] = kLocalVoid;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2016-09-27 20:46:10 +00:00
|
|
|
m >>= 1;
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
if (i <= depth) {
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheck) {
|
2016-03-07 21:04:07 +00:00
|
|
|
FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()};
|
|
|
|
for (size_t i = 0; i < arraysize(sigarray); i++) {
|
|
|
|
FunctionSig* sig = sigarray[i];
|
2015-12-11 12:26:16 +00:00
|
|
|
// unify X and X => OK
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_T(
|
|
|
|
sig->GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
|
|
|
|
WASM_GET_LOCAL(0))};
|
|
|
|
EXPECT_VERIFIES_SC(sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// unify i32 and f32 => fail
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)),
|
|
|
|
WASM_F32(1.2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
// unify f64 and f64 => OK
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(
|
|
|
|
d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
|
|
|
|
WASM_F64(1.2)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]};
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig sig(1, 2, storage);
|
|
|
|
byte code[] = {WASM_BLOCK_T(
|
|
|
|
sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
|
|
|
|
WASM_GET_LOCAL(1))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
if (i == j) {
|
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]};
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig sig(1, 2, storage);
|
|
|
|
byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO,
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)),
|
|
|
|
WASM_GET_LOCAL(1))};
|
|
|
|
|
|
|
|
if (i == j) {
|
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 2, storage);
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO,
|
|
|
|
WASM_GET_LOCAL(1),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
if (i == j) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_Unify) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int which = 0; which < 2; which++) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
|
|
|
ValueType storage[] = {kWasmI32, kWasmI32, type};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 2, storage);
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code1[] = {WASM_BLOCK_T(
|
|
|
|
type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))),
|
|
|
|
WASM_GET_LOCAL(which ^ 1))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (type == kWasmI32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code1);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType types[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]};
|
2016-09-27 20:46:10 +00:00
|
|
|
FunctionSig sig(1, 2, types);
|
|
|
|
byte code[] = {WASM_BLOCK_T(
|
|
|
|
types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (types[2] == kWasmI32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2016-02-08 21:18:43 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2016-02-08 21:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIf_val_type) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueType types[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j],
|
|
|
|
kWasmI32};
|
2016-02-08 21:18:43 +00:00
|
|
|
FunctionSig sig(1, 3, types);
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_T(
|
|
|
|
types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)),
|
|
|
|
WASM_DROP, WASM_GET_LOCAL(0))};
|
2016-02-08 21:18:43 +00:00
|
|
|
|
|
|
|
if (i == j) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2016-02-08 21:18:43 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2016-02-08 21:18:43 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIf_Unify) {
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int which = 0; which < 2; which++) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
|
|
|
ValueType storage[] = {kWasmI32, kWasmI32, type};
|
2015-12-11 12:26:16 +00:00
|
|
|
FunctionSig sig(1, 2, storage);
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)),
|
|
|
|
WASM_DROP, WASM_GET_LOCAL(which ^ 1))};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (type == kWasmI32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_SC(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable0) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static byte code[] = {kExprBrTable, 0, BR_TARGET(0)};
|
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable0b) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(0)};
|
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable0c) {
|
2016-09-27 20:46:10 +00:00
|
|
|
static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)};
|
|
|
|
EXPECT_FAILURE_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable1a) {
|
2016-04-29 09:15:26 +00:00
|
|
|
static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2016-01-28 12:54:12 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable1b) {
|
2016-04-29 09:15:26 +00:00
|
|
|
static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
|
|
|
EXPECT_FAILURE_C(i_i, code);
|
|
|
|
EXPECT_FAILURE_C(f_ff, code);
|
|
|
|
EXPECT_FAILURE_C(d_dd, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable2a) {
|
2015-12-11 12:26:16 +00:00
|
|
|
static byte code[] = {
|
2016-04-29 09:15:26 +00:00
|
|
|
B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable2b) {
|
2016-03-04 23:48:00 +00:00
|
|
|
static byte code[] = {WASM_BLOCK(
|
2016-07-21 11:04:06 +00:00
|
|
|
WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_C(v_v, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_off_end) {
|
2016-04-29 09:15:26 +00:00
|
|
|
static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
|
2016-03-04 23:48:00 +00:00
|
|
|
for (size_t len = 1; len < sizeof(code); len++) {
|
2016-03-07 21:04:07 +00:00
|
|
|
Verify(kError, sigs.i_i(), code, code + len);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br1) {
|
2016-03-04 23:48:00 +00:00
|
|
|
for (int depth = 0; depth < 4; depth++) {
|
2016-04-29 09:15:26 +00:00
|
|
|
byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
|
2016-09-27 20:46:10 +00:00
|
|
|
if (depth <= 1) {
|
|
|
|
EXPECT_VERIFIES_C(v_i, code);
|
2016-03-04 23:48:00 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
2016-03-04 23:48:00 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
for (int depth = 0; depth < 7; depth++) {
|
2016-03-04 23:48:00 +00:00
|
|
|
byte code[] = {
|
2016-07-21 11:04:06 +00:00
|
|
|
WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
|
2016-09-27 20:46:10 +00:00
|
|
|
if (depth < 2) {
|
|
|
|
EXPECT_VERIFIES_C(v_i, code);
|
2016-03-04 23:48:00 +00:00
|
|
|
} else {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_C(v_i, code);
|
2016-03-04 23:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Brv1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO)));
|
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO))));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Brv1_type) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0))));
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Brv1_type_n) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0))));
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrvIf1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_v, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO)));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrvIf1_type) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrvIf1_type_n) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))));
|
|
|
|
EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Select) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(i_i,
|
|
|
|
WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(f_ff, WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(d_dd, WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO));
|
|
|
|
EXPECT_VERIFIES(l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO));
|
2016-02-05 13:34:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Select_fail1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0)));
|
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0)));
|
2016-02-05 13:34:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Select_fail2) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
|
|
|
if (type == kWasmI32) continue;
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType types[] = {type, kWasmI32, type};
|
2016-02-05 13:34:41 +00:00
|
|
|
FunctionSig sig(1, 2, types);
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1),
|
|
|
|
WASM_GET_LOCAL(0)));
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(0)));
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
|
|
|
WASM_GET_LOCAL(0)));
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(1)));
|
2016-02-05 13:34:41 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Select_TypeCheck) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_i,
|
|
|
|
WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0)));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Throw) {
|
2016-08-11 13:14:51 +00:00
|
|
|
FLAG_wasm_eh_prototype = true;
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow);
|
2016-08-11 13:14:51 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(i_d, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0));
|
|
|
|
EXPECT_FAILURE(i_f, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0));
|
|
|
|
EXPECT_FAILURE(l_l, WASM_GET_LOCAL(0), kExprThrow, WASM_I64V(0));
|
2016-08-11 13:14:51 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define WASM_TRY_OP kExprTry, kLocalVoid
|
|
|
|
|
2016-08-11 13:14:51 +00:00
|
|
|
#define WASM_CATCH(local) kExprCatch, static_cast<byte>(local)
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TryCatch) {
|
2016-08-11 13:14:51 +00:00
|
|
|
FLAG_wasm_eh_prototype = true;
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd);
|
2016-08-11 13:14:51 +00:00
|
|
|
|
|
|
|
// Missing catch.
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd);
|
2016-08-11 13:14:51 +00:00
|
|
|
|
|
|
|
// Missing end.
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0));
|
2016-08-11 13:14:51 +00:00
|
|
|
|
|
|
|
// Double catch.
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValBlock1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FLAG_wasm_mv_prototype = true;
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_GET_LOCAL(1)),
|
|
|
|
kExprI32Add);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValBlock2) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FLAG_wasm_mv_prototype = true;
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_GET_LOCAL(1)),
|
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP));
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValBlockBr1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FLAG_wasm_mv_prototype = true;
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_FAILURE(
|
|
|
|
i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_BR(0)),
|
|
|
|
kExprI32Add);
|
|
|
|
EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_GET_LOCAL(1), WASM_BR(0)),
|
|
|
|
kExprI32Add);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValIf1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
FLAG_wasm_mv_prototype = true;
|
|
|
|
EXPECT_FAILURE(
|
2016-12-21 13:43:00 +00:00
|
|
|
i_ii, WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
|
|
|
|
kExprI32Add);
|
|
|
|
EXPECT_FAILURE(i_ii,
|
2016-12-21 13:43:00 +00:00
|
|
|
WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1))),
|
|
|
|
kExprI32Add);
|
|
|
|
EXPECT_VERIFIES(
|
2016-12-21 13:43:00 +00:00
|
|
|
i_ii, WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
|
|
|
|
kExprI32Add);
|
|
|
|
}
|
|
|
|
|
|
|
|
class BranchTableIteratorTest : public TestWithZone {
|
|
|
|
public:
|
|
|
|
BranchTableIteratorTest() : TestWithZone() {}
|
|
|
|
void CheckBrTableSize(const byte* start, const byte* end) {
|
|
|
|
Decoder decoder(start, end);
|
|
|
|
BranchTableOperand operand(&decoder, start);
|
|
|
|
BranchTableIterator iterator(&decoder, operand);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(end - start - 1u, iterator.length());
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_TRUE(decoder.ok());
|
|
|
|
}
|
|
|
|
void CheckBrTableError(const byte* start, const byte* end) {
|
|
|
|
Decoder decoder(start, end);
|
|
|
|
BranchTableOperand operand(&decoder, start);
|
|
|
|
BranchTableIterator iterator(&decoder, operand);
|
|
|
|
iterator.length();
|
|
|
|
EXPECT_FALSE(decoder.ok());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CHECK_BR_TABLE_LENGTH(...) \
|
|
|
|
{ \
|
|
|
|
static byte code[] = {kExprBrTable, __VA_ARGS__}; \
|
|
|
|
CheckBrTableSize(code, code + sizeof(code)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_BR_TABLE_ERROR(...) \
|
|
|
|
{ \
|
|
|
|
static byte code[] = {kExprBrTable, __VA_ARGS__}; \
|
|
|
|
CheckBrTableError(code, code + sizeof(code)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BranchTableIteratorTest, count0) {
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_1(1));
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_2(200));
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_3(30000));
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_4(400000));
|
|
|
|
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_1(2));
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_2(300));
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_3(40000));
|
|
|
|
CHECK_BR_TABLE_LENGTH(0, U32V_4(500000));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BranchTableIteratorTest, count1) {
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_1(1), U32V_1(6));
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_2(200), U32V_1(8));
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_3(30000), U32V_1(9));
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_4(400000), U32V_1(11));
|
|
|
|
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_1(2), U32V_2(6));
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_2(300), U32V_2(7));
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_3(40000), U32V_2(8));
|
|
|
|
CHECK_BR_TABLE_LENGTH(1, U32V_4(500000), U32V_2(9));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BranchTableIteratorTest, error0) {
|
|
|
|
CHECK_BR_TABLE_ERROR(0);
|
|
|
|
CHECK_BR_TABLE_ERROR(1, U32V_1(33));
|
2016-08-11 13:14:51 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
class WasmOpcodeLengthTest : public TestWithZone {
|
|
|
|
public:
|
|
|
|
WasmOpcodeLengthTest() : TestWithZone() {}
|
|
|
|
};
|
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
#define EXPECT_LENGTH(expected, opcode) \
|
|
|
|
{ \
|
|
|
|
static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \
|
|
|
|
EXPECT_EQ(static_cast<unsigned>(expected), \
|
|
|
|
OpcodeLength(code, code + sizeof(code))); \
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 11:55:30 +00:00
|
|
|
#define EXPECT_LENGTH_N(expected, ...) \
|
|
|
|
{ \
|
|
|
|
static const byte code[] = {__VA_ARGS__}; \
|
|
|
|
EXPECT_EQ(static_cast<unsigned>(expected), \
|
|
|
|
OpcodeLength(code, code + sizeof(code))); \
|
2016-03-11 18:01:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, Statements) {
|
|
|
|
EXPECT_LENGTH(1, kExprNop);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_LENGTH(2, kExprBlock);
|
|
|
|
EXPECT_LENGTH(2, kExprLoop);
|
|
|
|
EXPECT_LENGTH(2, kExprIf);
|
2016-04-29 09:15:26 +00:00
|
|
|
EXPECT_LENGTH(1, kExprElse);
|
|
|
|
EXPECT_LENGTH(1, kExprEnd);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_LENGTH(1, kExprSelect);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_LENGTH(2, kExprBr);
|
|
|
|
EXPECT_LENGTH(2, kExprBrIf);
|
2016-08-11 13:14:51 +00:00
|
|
|
EXPECT_LENGTH(1, kExprThrow);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_LENGTH(2, kExprTry);
|
2016-08-11 13:14:51 +00:00
|
|
|
EXPECT_LENGTH(2, kExprCatch);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
|
|
|
|
EXPECT_LENGTH(2, kExprI8Const);
|
|
|
|
EXPECT_LENGTH(5, kExprF32Const);
|
|
|
|
EXPECT_LENGTH(9, kExprF64Const);
|
|
|
|
EXPECT_LENGTH(2, kExprGetLocal);
|
|
|
|
EXPECT_LENGTH(2, kExprSetLocal);
|
2016-08-02 22:38:54 +00:00
|
|
|
EXPECT_LENGTH(2, kExprGetGlobal);
|
|
|
|
EXPECT_LENGTH(2, kExprSetGlobal);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_LENGTH(2, kExprCallFunction);
|
2016-10-26 16:56:05 +00:00
|
|
|
EXPECT_LENGTH(3, kExprCallIndirect);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 18:01:49 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, I32Const) {
|
|
|
|
EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1));
|
|
|
|
EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999));
|
|
|
|
EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999));
|
|
|
|
EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999));
|
|
|
|
EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999));
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-11 18:01:49 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, I64Const) {
|
|
|
|
EXPECT_LENGTH_N(2, kExprI64Const, U32V_1(1));
|
|
|
|
EXPECT_LENGTH_N(3, kExprI64Const, U32V_2(99));
|
|
|
|
EXPECT_LENGTH_N(4, kExprI64Const, U32V_3(9999));
|
|
|
|
EXPECT_LENGTH_N(5, kExprI64Const, U32V_4(99999));
|
|
|
|
EXPECT_LENGTH_N(6, kExprI64Const, U32V_5(9999999));
|
|
|
|
EXPECT_LENGTH_N(7, WASM_I64V_6(777777));
|
|
|
|
EXPECT_LENGTH_N(8, WASM_I64V_7(7777777));
|
|
|
|
EXPECT_LENGTH_N(9, WASM_I64V_8(77777777));
|
|
|
|
EXPECT_LENGTH_N(10, WASM_I64V_9(777777777));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 18:01:49 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, VariableLength) {
|
2016-08-02 22:38:54 +00:00
|
|
|
EXPECT_LENGTH_N(2, kExprGetGlobal, U32V_1(1));
|
|
|
|
EXPECT_LENGTH_N(3, kExprGetGlobal, U32V_2(33));
|
|
|
|
EXPECT_LENGTH_N(4, kExprGetGlobal, U32V_3(44));
|
|
|
|
EXPECT_LENGTH_N(5, kExprGetGlobal, U32V_4(66));
|
|
|
|
EXPECT_LENGTH_N(6, kExprGetGlobal, U32V_5(77));
|
2016-03-11 18:01:49 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, LoadsAndStores) {
|
2016-03-09 18:51:28 +00:00
|
|
|
EXPECT_LENGTH(3, kExprI32LoadMem8S);
|
|
|
|
EXPECT_LENGTH(3, kExprI32LoadMem8U);
|
|
|
|
EXPECT_LENGTH(3, kExprI32LoadMem16S);
|
|
|
|
EXPECT_LENGTH(3, kExprI32LoadMem16U);
|
|
|
|
EXPECT_LENGTH(3, kExprI32LoadMem);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem8S);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem8U);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem16S);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem16U);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem32S);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem32U);
|
|
|
|
EXPECT_LENGTH(3, kExprI64LoadMem);
|
|
|
|
EXPECT_LENGTH(3, kExprF32LoadMem);
|
|
|
|
EXPECT_LENGTH(3, kExprF64LoadMem);
|
|
|
|
|
|
|
|
EXPECT_LENGTH(3, kExprI32StoreMem8);
|
|
|
|
EXPECT_LENGTH(3, kExprI32StoreMem16);
|
|
|
|
EXPECT_LENGTH(3, kExprI32StoreMem);
|
|
|
|
EXPECT_LENGTH(3, kExprI64StoreMem8);
|
|
|
|
EXPECT_LENGTH(3, kExprI64StoreMem16);
|
|
|
|
EXPECT_LENGTH(3, kExprI64StoreMem32);
|
|
|
|
EXPECT_LENGTH(3, kExprI64StoreMem);
|
|
|
|
EXPECT_LENGTH(3, kExprF32StoreMem);
|
|
|
|
EXPECT_LENGTH(3, kExprF64StoreMem);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, MiscMemExpressions) {
|
2016-10-26 16:56:05 +00:00
|
|
|
EXPECT_LENGTH(2, kExprMemorySize);
|
|
|
|
EXPECT_LENGTH(2, kExprGrowMemory);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, SimpleExpressions) {
|
|
|
|
EXPECT_LENGTH(1, kExprI32Add);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Sub);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Mul);
|
|
|
|
EXPECT_LENGTH(1, kExprI32DivS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32DivU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32RemS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32RemU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32And);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Ior);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Xor);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Shl);
|
|
|
|
EXPECT_LENGTH(1, kExprI32ShrU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32ShrS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Eq);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Ne);
|
|
|
|
EXPECT_LENGTH(1, kExprI32LtS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32LeS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32LtU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32LeU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32GtS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32GeS);
|
|
|
|
EXPECT_LENGTH(1, kExprI32GtU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32GeU);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Clz);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Ctz);
|
|
|
|
EXPECT_LENGTH(1, kExprI32Popcnt);
|
2016-02-28 19:01:27 +00:00
|
|
|
EXPECT_LENGTH(1, kExprI32Eqz);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_LENGTH(1, kExprI64Add);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Sub);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Mul);
|
|
|
|
EXPECT_LENGTH(1, kExprI64DivS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64DivU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64RemS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64RemU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64And);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Ior);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Xor);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Shl);
|
|
|
|
EXPECT_LENGTH(1, kExprI64ShrU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64ShrS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Eq);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Ne);
|
|
|
|
EXPECT_LENGTH(1, kExprI64LtS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64LeS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64LtU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64LeU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64GtS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64GeS);
|
|
|
|
EXPECT_LENGTH(1, kExprI64GtU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64GeU);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Clz);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Ctz);
|
|
|
|
EXPECT_LENGTH(1, kExprI64Popcnt);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Add);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Sub);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Mul);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Div);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Min);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Max);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Abs);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Neg);
|
|
|
|
EXPECT_LENGTH(1, kExprF32CopySign);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Ceil);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Floor);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Trunc);
|
|
|
|
EXPECT_LENGTH(1, kExprF32NearestInt);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Sqrt);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Eq);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Ne);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Lt);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Le);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Gt);
|
|
|
|
EXPECT_LENGTH(1, kExprF32Ge);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Add);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Sub);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Mul);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Div);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Min);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Max);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Abs);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Neg);
|
|
|
|
EXPECT_LENGTH(1, kExprF64CopySign);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Ceil);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Floor);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Trunc);
|
|
|
|
EXPECT_LENGTH(1, kExprF64NearestInt);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Sqrt);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Eq);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Ne);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Lt);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Le);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Gt);
|
|
|
|
EXPECT_LENGTH(1, kExprF64Ge);
|
|
|
|
EXPECT_LENGTH(1, kExprI32SConvertF32);
|
|
|
|
EXPECT_LENGTH(1, kExprI32SConvertF64);
|
|
|
|
EXPECT_LENGTH(1, kExprI32UConvertF32);
|
|
|
|
EXPECT_LENGTH(1, kExprI32UConvertF64);
|
|
|
|
EXPECT_LENGTH(1, kExprI32ConvertI64);
|
|
|
|
EXPECT_LENGTH(1, kExprI64SConvertF32);
|
|
|
|
EXPECT_LENGTH(1, kExprI64SConvertF64);
|
|
|
|
EXPECT_LENGTH(1, kExprI64UConvertF32);
|
|
|
|
EXPECT_LENGTH(1, kExprI64UConvertF64);
|
|
|
|
EXPECT_LENGTH(1, kExprI64SConvertI32);
|
|
|
|
EXPECT_LENGTH(1, kExprI64UConvertI32);
|
|
|
|
EXPECT_LENGTH(1, kExprF32SConvertI32);
|
|
|
|
EXPECT_LENGTH(1, kExprF32UConvertI32);
|
|
|
|
EXPECT_LENGTH(1, kExprF32SConvertI64);
|
|
|
|
EXPECT_LENGTH(1, kExprF32UConvertI64);
|
|
|
|
EXPECT_LENGTH(1, kExprF32ConvertF64);
|
|
|
|
EXPECT_LENGTH(1, kExprF32ReinterpretI32);
|
|
|
|
EXPECT_LENGTH(1, kExprF64SConvertI32);
|
|
|
|
EXPECT_LENGTH(1, kExprF64UConvertI32);
|
|
|
|
EXPECT_LENGTH(1, kExprF64SConvertI64);
|
|
|
|
EXPECT_LENGTH(1, kExprF64UConvertI64);
|
|
|
|
EXPECT_LENGTH(1, kExprF64ConvertF32);
|
|
|
|
EXPECT_LENGTH(1, kExprF64ReinterpretI64);
|
|
|
|
EXPECT_LENGTH(1, kExprI32ReinterpretF32);
|
|
|
|
EXPECT_LENGTH(1, kExprI64ReinterpretF64);
|
|
|
|
}
|
|
|
|
|
2016-10-25 22:03:17 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, SimdExpressions) {
|
|
|
|
#define TEST_SIMD(name, opcode, sig) \
|
|
|
|
EXPECT_LENGTH_N(2, kSimdPrefix, static_cast<byte>(kExpr##name & 0xff));
|
|
|
|
FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD)
|
|
|
|
#undef TEST_SIMD
|
|
|
|
#define TEST_SIMD(name, opcode, sig) \
|
|
|
|
EXPECT_LENGTH_N(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xff));
|
|
|
|
FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD)
|
|
|
|
#undef TEST_SIMD
|
|
|
|
// test for bad simd opcode
|
|
|
|
EXPECT_LENGTH_N(2, kSimdPrefix, 0xff);
|
|
|
|
}
|
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
typedef ZoneVector<ValueType> TypesOfLocals;
|
2016-03-07 21:04:07 +00:00
|
|
|
|
|
|
|
class LocalDeclDecoderTest : public TestWithZone {
|
|
|
|
public:
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator;
|
2016-04-05 17:16:08 +00:00
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
size_t ExpectRun(TypesOfLocals map, size_t pos, ValueType expected,
|
2016-03-07 21:04:07 +00:00
|
|
|
size_t count) {
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_EQ(expected, map[pos++]);
|
2016-03-07 21:04:07 +00:00
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-05 17:16:08 +00:00
|
|
|
TEST_F(LocalDeclDecoderTest, EmptyLocals) {
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2017-01-06 22:24:56 +00:00
|
|
|
bool result = DecodeLocalDecls(&decls, nullptr, nullptr);
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_FALSE(result);
|
|
|
|
}
|
|
|
|
|
2016-03-07 21:04:07 +00:00
|
|
|
TEST_F(LocalDeclDecoderTest, NoLocals) {
|
|
|
|
static const byte data[] = {0};
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2017-01-06 22:24:56 +00:00
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_TRUE(result);
|
2017-01-06 22:24:56 +00:00
|
|
|
EXPECT_TRUE(decls.type_list.empty());
|
2016-03-07 21:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LocalDeclDecoderTest, OneLocal) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
2016-03-07 21:04:07 +00:00
|
|
|
const byte data[] = {
|
2016-12-21 13:43:00 +00:00
|
|
|
1, 1, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(type))};
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2017-01-06 22:24:56 +00:00
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_TRUE(result);
|
2017-01-06 22:24:56 +00:00
|
|
|
EXPECT_EQ(1u, decls.type_list.size());
|
2016-04-05 17:16:08 +00:00
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
TypesOfLocals map = decls.type_list;
|
2016-04-06 08:57:32 +00:00
|
|
|
EXPECT_EQ(type, map[0]);
|
2016-03-07 21:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LocalDeclDecoderTest, FiveLocals) {
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
2016-03-07 21:04:07 +00:00
|
|
|
const byte data[] = {
|
2016-12-21 13:43:00 +00:00
|
|
|
1, 5, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(type))};
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2017-01-06 22:24:56 +00:00
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_TRUE(result);
|
2017-01-06 22:24:56 +00:00
|
|
|
EXPECT_EQ(sizeof(data), decls.encoded_size);
|
|
|
|
EXPECT_EQ(5u, decls.type_list.size());
|
2016-04-05 17:16:08 +00:00
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
TypesOfLocals map = decls.type_list;
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(5u, map.size());
|
2016-03-07 21:04:07 +00:00
|
|
|
ExpectRun(map, 0, type, 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LocalDeclDecoderTest, MixedLocals) {
|
|
|
|
for (byte a = 0; a < 3; a++) {
|
|
|
|
for (byte b = 0; b < 3; b++) {
|
|
|
|
for (byte c = 0; c < 3; c++) {
|
|
|
|
for (byte d = 0; d < 3; d++) {
|
|
|
|
const byte data[] = {4, a, kLocalI32, b, kLocalI64,
|
|
|
|
c, kLocalF32, d, kLocalF64};
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2017-01-06 22:24:56 +00:00
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_TRUE(result);
|
2017-01-06 22:24:56 +00:00
|
|
|
EXPECT_EQ(sizeof(data), decls.encoded_size);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(static_cast<uint32_t>(a + b + c + d),
|
2017-01-06 22:24:56 +00:00
|
|
|
decls.type_list.size());
|
2016-04-05 17:16:08 +00:00
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
TypesOfLocals map = decls.type_list;
|
2016-03-07 21:04:07 +00:00
|
|
|
|
|
|
|
size_t pos = 0;
|
2016-12-21 13:43:00 +00:00
|
|
|
pos = ExpectRun(map, pos, kWasmI32, a);
|
|
|
|
pos = ExpectRun(map, pos, kWasmI64, b);
|
|
|
|
pos = ExpectRun(map, pos, kWasmF32, c);
|
|
|
|
pos = ExpectRun(map, pos, kWasmF64, d);
|
2016-03-07 21:04:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LocalDeclDecoderTest, UseEncoder) {
|
|
|
|
const byte* data = nullptr;
|
|
|
|
const byte* end = nullptr;
|
2016-05-17 17:53:46 +00:00
|
|
|
LocalDeclEncoder local_decls(zone());
|
2016-03-07 21:04:07 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
local_decls.AddLocals(5, kWasmF32);
|
|
|
|
local_decls.AddLocals(1337, kWasmI32);
|
|
|
|
local_decls.AddLocals(212, kWasmI64);
|
2016-05-25 08:32:37 +00:00
|
|
|
local_decls.Prepend(zone(), &data, &end);
|
2016-03-07 21:04:07 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2017-01-06 22:24:56 +00:00
|
|
|
bool result = DecodeLocalDecls(&decls, data, end);
|
2016-04-05 17:16:08 +00:00
|
|
|
EXPECT_TRUE(result);
|
2017-01-06 22:24:56 +00:00
|
|
|
EXPECT_EQ(5u + 1337u + 212u, decls.type_list.size());
|
2016-04-05 17:16:08 +00:00
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
TypesOfLocals map = decls.type_list;
|
2016-03-07 21:04:07 +00:00
|
|
|
size_t pos = 0;
|
2016-12-21 13:43:00 +00:00
|
|
|
pos = ExpectRun(map, pos, kWasmF32, 5);
|
|
|
|
pos = ExpectRun(map, pos, kWasmI32, 1337);
|
|
|
|
pos = ExpectRun(map, pos, kWasmI64, 212);
|
2016-03-07 21:04:07 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 12:57:22 +00:00
|
|
|
class BytecodeIteratorTest : public TestWithZone {};
|
|
|
|
|
|
|
|
TEST_F(BytecodeIteratorTest, SimpleForeach) {
|
|
|
|
byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
|
|
|
|
BytecodeIterator iter(code, code + sizeof(code));
|
|
|
|
WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const,
|
|
|
|
kExprElse, kExprI8Const, kExprEnd};
|
|
|
|
size_t pos = 0;
|
2016-12-20 11:28:44 +00:00
|
|
|
for (WasmOpcode opcode : iter.opcodes()) {
|
2016-07-11 12:57:22 +00:00
|
|
|
if (pos >= arraysize(expected)) {
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(expected[pos++], opcode);
|
|
|
|
}
|
|
|
|
EXPECT_EQ(arraysize(expected), pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BytecodeIteratorTest, ForeachTwice) {
|
|
|
|
byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
|
|
|
|
BytecodeIterator iter(code, code + sizeof(code));
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
count = 0;
|
2016-12-20 11:28:44 +00:00
|
|
|
for (WasmOpcode opcode : iter.opcodes()) {
|
2016-07-11 12:57:22 +00:00
|
|
|
USE(opcode);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(6, count);
|
|
|
|
|
|
|
|
count = 0;
|
2016-12-20 11:28:44 +00:00
|
|
|
for (WasmOpcode opcode : iter.opcodes()) {
|
2016-07-11 12:57:22 +00:00
|
|
|
USE(opcode);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(6, count);
|
|
|
|
}
|
|
|
|
|
2016-12-20 11:28:44 +00:00
|
|
|
TEST_F(BytecodeIteratorTest, ForeachOffset) {
|
|
|
|
byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
|
|
|
|
BytecodeIterator iter(code, code + sizeof(code));
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (auto offset : iter.offsets()) {
|
|
|
|
USE(offset);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(6, count);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (auto offset : iter.offsets()) {
|
|
|
|
USE(offset);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
EXPECT_EQ(6, count);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(BytecodeIteratorTest, WithLocalDecls) {
|
2016-07-11 12:57:22 +00:00
|
|
|
byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)};
|
2016-12-21 12:42:06 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
2016-07-11 12:57:22 +00:00
|
|
|
BytecodeIterator iter(code, code + sizeof(code), &decls);
|
|
|
|
|
2017-01-06 22:24:56 +00:00
|
|
|
EXPECT_EQ(3u, decls.encoded_size);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(3u, iter.pc_offset());
|
2016-07-11 12:57:22 +00:00
|
|
|
EXPECT_TRUE(iter.has_next());
|
|
|
|
EXPECT_EQ(kExprI8Const, iter.current());
|
|
|
|
iter.next();
|
|
|
|
EXPECT_TRUE(iter.has_next());
|
|
|
|
EXPECT_EQ(kExprI8Const, iter.current());
|
|
|
|
iter.next();
|
|
|
|
EXPECT_FALSE(iter.has_next());
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|