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.
|
|
|
|
|
2020-06-24 11:17:46 +00:00
|
|
|
#include "src/wasm/function-body-decoder.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
|
|
|
#include "src/objects/objects.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/utils/ostreams.h"
|
2017-02-10 01:16:37 +00:00
|
|
|
#include "src/wasm/function-body-decoder-impl.h"
|
2020-06-24 11:17:46 +00:00
|
|
|
#include "src/wasm/leb-helper.h"
|
2017-04-25 10:13:10 +00:00
|
|
|
#include "src/wasm/local-decl-encoder.h"
|
2016-11-09 08:37:05 +00:00
|
|
|
#include "src/wasm/signature-map.h"
|
2017-02-10 01:16:37 +00:00
|
|
|
#include "src/wasm/wasm-limits.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/wasm-module.h"
|
2020-06-24 11:17:46 +00:00
|
|
|
#include "src/wasm/wasm-opcodes-inl.h"
|
2020-07-31 10:35:16 +00:00
|
|
|
#include "src/zone/zone.h"
|
2017-05-31 13:31:52 +00:00
|
|
|
#include "test/common/wasm/flag-utils.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2020-06-24 11:17:46 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
2018-12-04 13:59:58 +00:00
|
|
|
#include "testing/gmock-support.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2017-09-28 17:55:52 +00:00
|
|
|
namespace function_body_decoder_unittest {
|
2015-12-11 12:26:16 +00:00
|
|
|
|
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)
|
|
|
|
|
2020-09-29 07:46:36 +00:00
|
|
|
#define WASM_IF_OP kExprIf, kVoidCode
|
|
|
|
#define WASM_LOOP_OP kExprLoop, kVoidCode
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2020-06-26 12:24:26 +00:00
|
|
|
#define EXPECT_OK(result) \
|
|
|
|
do { \
|
|
|
|
if (!result.ok()) { \
|
|
|
|
GTEST_NONFATAL_FAILURE_(result.error().message().c_str()); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
static const byte kCodeGetLocal0[] = {kExprLocalGet, 0};
|
|
|
|
static const byte kCodeGetLocal1[] = {kExprLocalGet, 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
|
|
|
|
2020-06-10 07:22:22 +00:00
|
|
|
static const ValueType kValueTypes[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
|
|
|
|
kWasmExternRef};
|
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)
|
|
|
|
|
2020-06-02 12:07:22 +00:00
|
|
|
constexpr size_t kMaxByteSizedLeb128 = 127;
|
|
|
|
|
2020-06-05 08:45:56 +00:00
|
|
|
using F = std::pair<ValueType, bool>;
|
|
|
|
|
2020-10-13 09:00:00 +00:00
|
|
|
enum MemoryType { kMemory32, kMemory64 };
|
|
|
|
|
2020-06-02 12:07:22 +00:00
|
|
|
// A helper for tests that require a module environment for functions,
|
|
|
|
// globals, or memories.
|
|
|
|
class TestModuleBuilder {
|
|
|
|
public:
|
2020-06-05 08:45:56 +00:00
|
|
|
explicit TestModuleBuilder(ModuleOrigin origin = kWasmOrigin)
|
2020-07-02 17:52:17 +00:00
|
|
|
: allocator(), mod(std::make_unique<Zone>(&allocator, ZONE_NAME)) {
|
2020-06-02 12:07:22 +00:00
|
|
|
mod.origin = origin;
|
|
|
|
}
|
|
|
|
byte AddGlobal(ValueType type, bool mutability = true) {
|
|
|
|
mod.globals.push_back(
|
|
|
|
{type, mutability, WasmInitExpr(), {0}, false, false});
|
|
|
|
CHECK_LE(mod.globals.size(), kMaxByteSizedLeb128);
|
|
|
|
return static_cast<byte>(mod.globals.size() - 1);
|
|
|
|
}
|
|
|
|
byte AddSignature(const FunctionSig* sig) {
|
|
|
|
mod.add_signature(sig);
|
|
|
|
CHECK_LE(mod.types.size(), kMaxByteSizedLeb128);
|
|
|
|
return static_cast<byte>(mod.types.size() - 1);
|
|
|
|
}
|
|
|
|
byte AddFunction(const FunctionSig* sig, bool declared = true) {
|
2020-10-01 05:06:18 +00:00
|
|
|
byte sig_index = AddSignature(sig);
|
|
|
|
mod.functions.push_back(
|
|
|
|
{sig, // sig
|
|
|
|
static_cast<uint32_t>(mod.functions.size()), // func_index
|
|
|
|
sig_index, // sig_index
|
|
|
|
{0, 0}, // code
|
|
|
|
false, // import
|
|
|
|
false, // export
|
|
|
|
declared}); // declared
|
2020-06-02 12:07:22 +00:00
|
|
|
CHECK_LE(mod.functions.size(), kMaxByteSizedLeb128);
|
|
|
|
return static_cast<byte>(mod.functions.size() - 1);
|
|
|
|
}
|
|
|
|
byte AddImport(const FunctionSig* sig) {
|
|
|
|
byte result = AddFunction(sig);
|
|
|
|
mod.functions[result].imported = true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
byte AddException(WasmExceptionSig* sig) {
|
|
|
|
mod.exceptions.emplace_back(sig);
|
|
|
|
CHECK_LE(mod.types.size(), kMaxByteSizedLeb128);
|
|
|
|
return static_cast<byte>(mod.exceptions.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte AddTable(ValueType type, uint32_t initial_size, bool has_maximum_size,
|
|
|
|
uint32_t maximum_size) {
|
2020-09-18 15:22:35 +00:00
|
|
|
CHECK(WasmTable::IsValidTableType(type, &mod));
|
2020-06-02 12:07:22 +00:00
|
|
|
mod.tables.emplace_back();
|
|
|
|
WasmTable& table = mod.tables.back();
|
|
|
|
table.type = type;
|
|
|
|
table.initial_size = initial_size;
|
|
|
|
table.has_maximum_size = has_maximum_size;
|
|
|
|
table.maximum_size = maximum_size;
|
|
|
|
return static_cast<byte>(mod.tables.size() - 1);
|
|
|
|
}
|
|
|
|
|
2020-06-05 08:45:56 +00:00
|
|
|
byte AddStruct(std::initializer_list<F> fields) {
|
|
|
|
StructType::Builder type_builder(mod.signature_zone.get(),
|
|
|
|
static_cast<uint32_t>(fields.size()));
|
|
|
|
for (F field : fields) {
|
|
|
|
type_builder.AddField(field.first, field.second);
|
|
|
|
}
|
|
|
|
mod.add_struct_type(type_builder.Build());
|
|
|
|
return static_cast<byte>(mod.type_kinds.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte AddArray(ValueType type, bool mutability) {
|
2020-07-09 11:51:58 +00:00
|
|
|
ArrayType* array = mod.signature_zone->New<ArrayType>(type, mutability);
|
2020-06-05 08:45:56 +00:00
|
|
|
mod.add_array_type(array);
|
|
|
|
return static_cast<byte>(mod.type_kinds.size() - 1);
|
|
|
|
}
|
|
|
|
|
2020-10-13 09:00:00 +00:00
|
|
|
void InitializeMemory(MemoryType mem_type = kMemory32) {
|
2020-06-02 12:07:22 +00:00
|
|
|
mod.has_memory = true;
|
2020-10-13 09:00:00 +00:00
|
|
|
mod.is_memory64 = mem_type == kMemory64;
|
2020-06-02 12:07:22 +00:00
|
|
|
mod.initial_pages = 1;
|
|
|
|
mod.maximum_pages = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte InitializeTable(wasm::ValueType type) {
|
|
|
|
mod.tables.emplace_back();
|
|
|
|
mod.tables.back().type = type;
|
|
|
|
return static_cast<byte>(mod.tables.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte AddPassiveElementSegment(wasm::ValueType type) {
|
|
|
|
mod.elem_segments.emplace_back(false);
|
|
|
|
auto& init = mod.elem_segments.back();
|
|
|
|
init.type = type;
|
|
|
|
// Add 5 empty elements.
|
|
|
|
for (uint32_t j = 0; j < 5; j++) {
|
|
|
|
init.entries.push_back(WasmElemSegment::kNullIndex);
|
|
|
|
}
|
|
|
|
return static_cast<byte>(mod.elem_segments.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte AddDeclarativeElementSegment() {
|
|
|
|
mod.elem_segments.emplace_back(true);
|
|
|
|
mod.elem_segments.back().entries.push_back(WasmElemSegment::kNullIndex);
|
|
|
|
return static_cast<byte>(mod.elem_segments.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the number of data segments as declared by the DataCount section.
|
|
|
|
void SetDataSegmentCount(uint32_t data_segment_count) {
|
|
|
|
// The Data section occurs after the Code section, so we don't need to
|
|
|
|
// update mod.data_segments, as it is always empty.
|
|
|
|
mod.num_declared_data_segments = data_segment_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
WasmModule* module() { return &mod; }
|
|
|
|
|
|
|
|
private:
|
2020-06-05 08:45:56 +00:00
|
|
|
AccountingAllocator allocator;
|
2020-06-02 12:07:22 +00:00
|
|
|
WasmModule mod;
|
|
|
|
};
|
|
|
|
|
2020-11-17 15:28:08 +00:00
|
|
|
template <class BaseTest>
|
|
|
|
class FunctionBodyDecoderTestBase : public WithZoneMixin<BaseTest> {
|
2015-12-11 12:26:16 +00:00
|
|
|
public:
|
2019-03-29 09:40:26 +00:00
|
|
|
using LocalsDecl = std::pair<uint32_t, ValueType>;
|
2018-08-08 14:54:44 +00:00
|
|
|
// All features are disabled by default and must be activated with
|
|
|
|
// a WASM_FEATURE_SCOPE in individual tests.
|
2019-11-26 16:25:14 +00:00
|
|
|
WasmFeatures enabled_features_ = WasmFeatures::None();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TestSignatures sigs;
|
2020-06-02 12:07:22 +00:00
|
|
|
TestModuleBuilder builder;
|
|
|
|
WasmModule* module = builder.module();
|
2020-11-17 15:28:08 +00:00
|
|
|
LocalDeclEncoder local_decls{this->zone()};
|
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
|
|
|
}
|
|
|
|
|
2017-12-19 15:50:20 +00:00
|
|
|
enum AppendEnd : bool { kAppendEnd, kOmitEnd };
|
|
|
|
|
2018-11-30 09:32:45 +00:00
|
|
|
Vector<const byte> PrepareBytecode(Vector<const byte> code,
|
|
|
|
AppendEnd append_end) {
|
2017-01-15 21:18:53 +00:00
|
|
|
size_t locals_size = local_decls.Size();
|
2018-11-30 09:32:45 +00:00
|
|
|
size_t total_size =
|
|
|
|
code.size() + locals_size + (append_end == kAppendEnd ? 1 : 0);
|
2020-11-17 15:28:08 +00:00
|
|
|
byte* buffer = this->zone()->template NewArray<byte>(total_size);
|
2017-01-15 21:18:53 +00:00
|
|
|
// Prepend the local decls to the code.
|
|
|
|
local_decls.Emit(buffer);
|
|
|
|
// Emit the code.
|
2019-01-25 00:34:59 +00:00
|
|
|
if (code.size() > 0) {
|
2019-04-29 11:06:49 +00:00
|
|
|
memcpy(buffer + locals_size, code.begin(), code.size());
|
2019-01-25 00:34:59 +00:00
|
|
|
}
|
2017-12-19 15:50:20 +00:00
|
|
|
if (append_end == kAppendEnd) {
|
|
|
|
// Append an extra end opcode.
|
|
|
|
buffer[total_size - 1] = kExprEnd;
|
|
|
|
}
|
2017-01-15 21:18:53 +00:00
|
|
|
|
2018-11-30 09:32:45 +00:00
|
|
|
return {buffer, total_size};
|
2017-01-15 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
template <size_t N>
|
|
|
|
Vector<const byte> CodeToVector(const byte (&code)[N]) {
|
|
|
|
return ArrayVector(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<const byte> CodeToVector(
|
|
|
|
const std::initializer_list<const byte>& code) {
|
|
|
|
return VectorOf(&*code.begin(), code.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<const byte> CodeToVector(Vector<const byte> vec) { return vec; }
|
|
|
|
|
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.
|
2019-02-08 10:10:45 +00:00
|
|
|
template <typename Code = std::initializer_list<const byte>>
|
2020-02-25 20:00:50 +00:00
|
|
|
void Validate(bool expected_success, const FunctionSig* sig, Code&& raw_code,
|
2019-02-08 10:10:45 +00:00
|
|
|
AppendEnd append_end = kAppendEnd,
|
|
|
|
const char* message = nullptr) {
|
|
|
|
Vector<const byte> code =
|
|
|
|
PrepareBytecode(CodeToVector(std::forward<Code>(raw_code)), append_end);
|
|
|
|
|
|
|
|
// Validate the code.
|
2019-04-29 11:06:49 +00:00
|
|
|
FunctionBody body(sig, 0, code.begin(), code.end());
|
2019-11-26 16:25:14 +00:00
|
|
|
WasmFeatures unused_detected_features = WasmFeatures::None();
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
DecodeResult result =
|
2020-11-17 15:28:08 +00:00
|
|
|
VerifyWasmCode(this->zone()->allocator(), enabled_features_, module,
|
2018-08-08 14:54:44 +00:00
|
|
|
&unused_detected_features, body);
|
2016-03-07 21:04:07 +00:00
|
|
|
|
2017-07-14 13:40:47 +00:00
|
|
|
std::ostringstream str;
|
2019-01-14 17:51:56 +00:00
|
|
|
if (result.failed()) {
|
|
|
|
str << "Verification failed: pc = +" << result.error().offset()
|
|
|
|
<< ", msg = " << result.error().message();
|
2017-07-14 13:40:47 +00:00
|
|
|
} else {
|
2020-07-04 10:35:16 +00:00
|
|
|
str << "Verification succeeded, expected failure";
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2017-07-14 13:40:47 +00:00
|
|
|
EXPECT_EQ(result.ok(), expected_success) << str.str();
|
2019-01-14 17:51:56 +00:00
|
|
|
if (result.failed() && message) {
|
|
|
|
EXPECT_THAT(result.error().message(), ::testing::HasSubstr(message));
|
2018-12-04 13:59:58 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
template <typename Code = std::initializer_list<const byte>>
|
2020-02-25 20:00:50 +00:00
|
|
|
void ExpectValidates(const FunctionSig* sig, Code&& raw_code,
|
2019-02-08 10:10:45 +00:00
|
|
|
AppendEnd append_end = kAppendEnd,
|
|
|
|
const char* message = nullptr) {
|
|
|
|
Validate(true, sig, std::forward<Code>(raw_code), append_end, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Code = std::initializer_list<const byte>>
|
2020-02-25 20:00:50 +00:00
|
|
|
void ExpectFailure(const FunctionSig* sig, Code&& raw_code,
|
2019-02-08 10:10:45 +00:00
|
|
|
AppendEnd append_end = kAppendEnd,
|
|
|
|
const char* message = nullptr) {
|
|
|
|
Validate(false, sig, std::forward<Code>(raw_code), append_end, message);
|
|
|
|
}
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
void TestBinop(WasmOpcode opcode, const FunctionSig* success) {
|
2015-12-11 12:26:16 +00:00
|
|
|
// 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))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(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);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
void TestUnop(WasmOpcode opcode, const FunctionSig* success) {
|
2015-12-11 12:26:16 +00:00
|
|
|
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);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&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);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-17 15:28:08 +00:00
|
|
|
using FunctionBodyDecoderTest = FunctionBodyDecoderTestBase<::testing::Test>;
|
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Const1) {
|
|
|
|
byte code[] = {kExprI32Const, 0};
|
|
|
|
for (int i = -64; i <= 63; i++) {
|
|
|
|
code[1] = static_cast<byte>(i & 0x7F);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-13 09:45:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, RefFunc) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-05-13 09:45:06 +00:00
|
|
|
|
|
|
|
builder.AddFunction(sigs.v_ii());
|
|
|
|
builder.AddFunction(sigs.ii_v());
|
|
|
|
ExpectValidates(sigs.a_v(), {kExprRefFunc, 1});
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, EmptyFunction) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {});
|
|
|
|
ExpectFailure(sigs.i_i(), {});
|
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};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_I32V_1(0)});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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.
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_I32V(i)});
|
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) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.l_l(),
|
|
|
|
{WASM_I64V((static_cast<uint64_t>(i) << 32) | i)});
|
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};
|
2018-04-13 22:28:05 +00:00
|
|
|
Address ptr = reinterpret_cast<Address>(code + 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int i = 0; i < 30; i++) {
|
2019-06-17 09:26:18 +00:00
|
|
|
base::WriteLittleEndianValue<float>(ptr, i * -7.75f);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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};
|
2018-04-13 22:28:05 +00:00
|
|
|
Address ptr = reinterpret_cast<Address>(code + 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int i = 0; i < 30; i++) {
|
2019-06-17 09:26:18 +00:00
|
|
|
base::WriteLittleEndianValue<double>(ptr, i * 33.45);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2017-12-02 00:30:37 +00:00
|
|
|
byte code[] = {kExprI32Const, 0xAA, 0xBB, 0xCC, 0x44};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-11-30 09:32:45 +00:00
|
|
|
for (size_t size = 1; size <= 4; ++size) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sigs.i_i(), VectorOf(code, size), kAppendEnd);
|
2017-12-19 15:50:20 +00:00
|
|
|
// Should also fail without the trailing 'end' opcode.
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sigs.i_i(), VectorOf(code, size), kOmitEnd);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal0_param) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
for (const FunctionSig* sig : {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}) {
|
|
|
|
ExpectValidates(sig, 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++) {
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.i_v(), {kExprLocalGet, j});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GetLocal0_fail_no_params) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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) {
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {kExprLocalGet});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NumLocalBelowLimit) {
|
2017-02-10 01:16:37 +00:00
|
|
|
AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 1);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_NOP});
|
2016-08-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NumLocalAtLimit) {
|
2017-02-10 01:16:37 +00:00
|
|
|
AddLocals(kWasmI32, kV8MaxWasmFunctionLocals);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_NOP});
|
2016-08-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, NumLocalAboveLimit) {
|
2017-02-10 01:16:37 +00:00
|
|
|
AddLocals(kWasmI32, kV8MaxWasmFunctionLocals + 1);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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) {
|
2017-02-10 01:16:37 +00:00
|
|
|
const int kMaxLocals = kV8MaxWasmFunctionLocals - 1;
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, kMaxLocals);
|
2016-03-07 21:04:07 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_1(66)});
|
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_2(7777)});
|
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_3(8888)});
|
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_4(9999)});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_5(kMaxLocals - 1)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {kExprLocalGet, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_4(kMaxLocals - 1)});
|
|
|
|
ExpectValidates(sigs.i_i(), {kExprLocalGet, U32V_4(kMaxLocals)});
|
|
|
|
ExpectFailure(sigs.i_i(), {kExprLocalGet, U32V_4(kMaxLocals + 1)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectFailure(sigs.i_v(), {kExprLocalGet, U32V_4(kMaxLocals)});
|
|
|
|
ExpectFailure(sigs.i_v(), {kExprLocalGet, 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) {
|
2017-02-10 01:16:37 +00:00
|
|
|
AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 100);
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 100);
|
2016-12-14 17:45:59 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.i_v(), {kExprLocalGet, U32V_1(66)});
|
|
|
|
ExpectFailure(sigs.i_i(), {kExprLocalGet, U32V_1(66)});
|
2016-12-14 17:45:59 +00:00
|
|
|
}
|
|
|
|
|
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];
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), code1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
byte code3[] = {kExprLocalGet, 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];
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), code3);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
byte code4[] = {kExprLocalGet, 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];
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), code4);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock1) {
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_ZERO, kExprBlock, kI32Code, WASM_ZERO,
|
2019-02-08 13:38:33 +00:00
|
|
|
kExprI32Add, kExprEnd});
|
2016-05-09 10:34:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock2) {
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_ZERO, WASM_ZERO, kExprBlock, kI32Code,
|
2019-02-08 13:38:33 +00:00
|
|
|
kExprI32Add, kExprEnd});
|
2016-05-09 10:34:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock3) {
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_ZERO, WASM_ZERO, kExprIf, kI32Code,
|
2019-02-08 13:38:33 +00:00
|
|
|
kExprI32Add, kExprElse, kExprI32Add, kExprEnd});
|
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) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {kExprNop});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SetLocal0_void) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), kCodeSetLocal0);
|
|
|
|
ExpectFailure(sigs.f_ff(), kCodeSetLocal0);
|
|
|
|
ExpectFailure(sigs.d_dd(), kCodeSetLocal0);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TeeLocal0_param) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), kCodeTeeLocal0);
|
|
|
|
ExpectFailure(sigs.f_ff(), kCodeTeeLocal0);
|
|
|
|
ExpectFailure(sigs.d_dd(), kCodeTeeLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SetLocal0_local) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_v(), kCodeSetLocal0);
|
|
|
|
ExpectFailure(sigs.v_v(), kCodeSetLocal0);
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_v(), kCodeSetLocal0);
|
|
|
|
ExpectValidates(sigs.v_v(), kCodeSetLocal0);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_v(), kCodeTeeLocal0);
|
2016-12-21 13:43:00 +00:00
|
|
|
AddLocals(kWasmI32, 1);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_v(), kCodeTeeLocal0);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
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++) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TEE_LOCAL(j, WASM_I32V_1(i))});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_TEE_LOCAL(j, WASM_I32V_1(i))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockN) {
|
2018-11-30 09:32:45 +00:00
|
|
|
constexpr size_t kMaxSize = 200;
|
2016-09-27 20:46:10 +00:00
|
|
|
byte buffer[kMaxSize + 3];
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2018-11-30 09:32:45 +00:00
|
|
|
for (size_t i = 0; i <= kMaxSize; i++) {
|
2016-04-29 09:15:26 +00:00
|
|
|
memset(buffer, kExprNop, sizeof(buffer));
|
|
|
|
buffer[0] = kExprBlock;
|
2020-09-29 07:46:36 +00:00
|
|
|
buffer[1] = kVoidCode;
|
2016-09-27 20:46:10 +00:00
|
|
|
buffer[i + 2] = kExprEnd;
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_i(), VectorOf(buffer, i + 3), kAppendEnd);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 07:46:36 +00:00
|
|
|
#define WASM_EMPTY_BLOCK kExprBlock, kVoidCode, kExprEnd
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_EMPTY_BLOCK});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_EMPTY_BLOCK});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0_fallthru1) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_BLOCK(WASM_EMPTY_BLOCK)});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_BLOCK(WASM_EMPTY_BLOCK)});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0Block0) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block0_end) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_EMPTY_BLOCK, kExprEnd});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef WASM_EMPTY_BLOCK
|
|
|
|
|
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))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.v_i(), code);
|
|
|
|
ExpectFailure(sigs.d_dd(), code);
|
|
|
|
ExpectFailure(sigs.i_f(), code);
|
|
|
|
ExpectFailure(sigs.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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.f_ff(), code);
|
|
|
|
ExpectFailure(sigs.d_dd(), code);
|
|
|
|
ExpectFailure(sigs.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))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), code);
|
|
|
|
ExpectValidates(sigs.f_ff(), code);
|
|
|
|
ExpectFailure(sigs.d_dd(), code);
|
|
|
|
ExpectFailure(sigs.l_ll(), code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block1_continue) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {B1(WASM_BR(0))});
|
|
|
|
ExpectValidates(sigs.v_v(), {B1(WASM_BR(1))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {B2(WASM_NOP, WASM_BR(0))});
|
|
|
|
ExpectValidates(sigs.v_v(), {B2(WASM_BR(0), WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_BLOCK(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_BLOCK_I(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_NOP, WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_ZERO, WASM_NOP)});
|
|
|
|
ExpectFailure(sigs.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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.f_ff(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block2_fallthru) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {B2(WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO)),
|
|
|
|
WASM_I32V_1(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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_I32V_1(11))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Block5) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO)});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO, WASM_ZERO)});
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_i(),
|
|
|
|
{WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_i(), {WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockType) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sigs.l_l(), {WASM_BLOCK_L(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sigs.f_f(), {WASM_BLOCK_F(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sigs.d_d(), {WASM_BLOCK_D(WASM_GET_LOCAL(0))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockType_fail) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_BLOCK_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_BLOCK_F(WASM_F32(0.0))});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_BLOCK_D(WASM_F64(1.1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.l_l(), {WASM_BLOCK_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.l_l(), {WASM_BLOCK_F(WASM_F32(0.0))});
|
|
|
|
ExpectFailure(sigs.l_l(), {WASM_BLOCK_D(WASM_F64(1.1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.f_ff(), {WASM_BLOCK_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.f_ff(), {WASM_BLOCK_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.f_ff(), {WASM_BLOCK_D(WASM_F64(1.1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.d_dd(), {WASM_BLOCK_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.d_dd(), {WASM_BLOCK_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.f_ff(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), code);
|
2016-04-29 09:15:26 +00:00
|
|
|
for (size_t i = 1; i < arraysize(code); i++) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sigs.v_v(), VectorOf(code, i), kAppendEnd);
|
|
|
|
ExpectFailure(sigs.v_v(), VectorOf(code, i), kOmitEnd);
|
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, Block2_continue) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_BR(0))});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_BR(1))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))});
|
|
|
|
ExpectValidates(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))});
|
|
|
|
ExpectValidates(sigs.v_v(), {B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {B1(B1(WASM_RETURN1(WASM_ZERO))), WASM_ZERO});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockBrBinop) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))),
|
|
|
|
WASM_I32V_1(2))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 13:24:00 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, VoidBlockTypeVariants) {
|
|
|
|
// Valid kVoidCode encoded in 2 bytes.
|
|
|
|
ExpectValidates(sigs.v_v(), {kExprBlock, kVoidCode | 0x80, 0x7F, kExprEnd});
|
|
|
|
// Invalid code, whose last 7 bits coincide with kVoidCode.
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprBlock, kVoidCode | 0x80, 0x45, kExprEnd},
|
2020-11-16 17:01:01 +00:00
|
|
|
kAppendEnd, "invalid block type");
|
2020-11-10 13:24:00 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_empty1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd});
|
|
|
|
ExpectFailure(sigs.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};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_incomplete1) {
|
2017-01-09 13:57:26 +00:00
|
|
|
byte code[] = {kExprI32Const, 0, kExprIf};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_incomplete2) {
|
2017-01-09 13:57:26 +00:00
|
|
|
byte code[] = {kExprI32Const, 0, kExprIf, kExprNop};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.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) {
|
2017-01-09 13:57:26 +00:00
|
|
|
byte code[] = {kExprI32Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfEmpty) {
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {kExprLocalGet, 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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))});
|
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd});
|
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_i(),
|
|
|
|
{WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(
|
|
|
|
sigs.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);
|
|
|
|
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(kValueTypes[i] == kWasmI32, &sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 13:59:58 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, OneArmedIfWithArity) {
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte code[] = {WASM_ZERO, kExprIf, kI32Code, WASM_ONE, kExprEnd};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_v(), code, kAppendEnd,
|
|
|
|
"start-arity and end-arity of one-armed if must match");
|
2018-12-04 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfBreak) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))});
|
|
|
|
ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))});
|
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2017-01-09 13:57:26 +00:00
|
|
|
byte code[] = {kExprI32Const, 0, kExprBlock, kExprElse, kExprEnd};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfNop) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 21:18:53 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_end) {
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {kExprLocalGet, 0, WASM_IF_OP, kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_i(), {kExprLocalGet, 0, WASM_IF_OP, kExprEnd, kExprEnd});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If_falloff1) {
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectFailure(sigs.v_i(), {kExprLocalGet, 0, kExprIf});
|
|
|
|
ExpectFailure(sigs.v_i(), {kExprLocalGet, 0, WASM_IF_OP});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_i(),
|
2019-10-08 12:38:48 +00:00
|
|
|
{kExprLocalGet, 0, WASM_IF_OP, kExprNop, kExprElse});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IfElseNop) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0),
|
|
|
|
B2(WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
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, IfBlock2b) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO),
|
|
|
|
WASM_SET_LOCAL(0, WASM_I32V_1(1)))});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop0) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP_OP, kExprEnd});
|
2016-12-21 12:42:06 +00:00
|
|
|
}
|
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))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), code);
|
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.f_ff(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:06:21 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, InfiniteLoop1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_LOOP(WASM_BR(0)), WASM_ZERO});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_LOOP(WASM_BR(0)), WASM_ZERO});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_LOOP_I(WASM_BRV(1, WASM_ZERO))});
|
2017-02-02 23:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, InfiniteLoop2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_LOOP(WASM_BR(0), WASM_ZERO), WASM_ZERO});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_LOOP_I(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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_LOOP_I(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sigs.l_l(), {WASM_LOOP_L(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sigs.f_f(), {WASM_LOOP_F(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_LOOP_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_LOOP_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_LOOP_F(WASM_F32(0.0))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_LOOP_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_LOOP_F(WASM_F32(0.0))});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_LOOP_D(WASM_F64(1.1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.l_l(), {WASM_LOOP_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.l_l(), {WASM_LOOP_F(WASM_F32(0.0))});
|
|
|
|
ExpectFailure(sigs.l_l(), {WASM_LOOP_D(WASM_F64(1.1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.f_ff(), {WASM_LOOP_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.f_ff(), {WASM_LOOP_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.f_ff(), {WASM_LOOP_D(WASM_F64(1.1))});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.d_dd(), {WASM_LOOP_I(WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.d_dd(), {WASM_LOOP_L(WASM_I64V_1(0))});
|
|
|
|
ExpectFailure(sigs.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};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.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))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.i_f(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ReturnVoid3) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {kExprI32Const, 0});
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprI64Const, 0});
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprF32Const, 0, 0, 0, 0});
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprRefNull});
|
2019-05-13 09:45:06 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {kExprRefFunc, 0});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectFailure(sigs.v_i(), {kExprLocalGet, 0});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_UNREACHABLE});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_UNREACHABLE, WASM_ZERO});
|
2017-02-02 23:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {B2(WASM_UNREACHABLE, WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.v_v(), {B2(WASM_BR(0), WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:06:21 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, UnreachableLoop1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_LOOP(WASM_BR(0), WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_UNREACHABLE, WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_BR(0), WASM_NOP)});
|
2017-02-02 23:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable_binop1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:06:21 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable_binop2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_I32_AND(WASM_F32(0.0), WASM_UNREACHABLE)});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_I32_AND(WASM_UNREACHABLE, WASM_F32(0.0))});
|
2017-02-02 23:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable_select1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:06:21 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Unreachable_select2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_SELECT(WASM_F32(0.0), WASM_UNREACHABLE, WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.i_i(),
|
|
|
|
{WASM_SELECT(WASM_UNREACHABLE, WASM_F32(0.0), WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.i_i(),
|
|
|
|
{WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_F32(0.0))});
|
2017-02-02 23:06:21 +00:00
|
|
|
}
|
|
|
|
|
2020-10-01 05:06:18 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
|
|
|
byte function_index = builder.AddFunction(sigs.i_ii());
|
|
|
|
byte struct_index = builder.AddStruct({F(kWasmI32, true), F(kWasmI64, true)});
|
|
|
|
byte array_index = builder.AddArray(kWasmI32, true);
|
|
|
|
|
|
|
|
ValueType struct_type = ValueType::Ref(struct_index, kNonNullable);
|
|
|
|
FunctionSig sig_v_s(0, 1, &struct_type);
|
|
|
|
byte struct_consumer = builder.AddFunction(&sig_v_s);
|
|
|
|
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_BLOCK(WASM_UNREACHABLE, kExprBrOnNull, 0)});
|
|
|
|
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, kExprRefIsNull});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, kExprRefAsNonNull, kExprDrop});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, kExprCallRef, WASM_I32V(1)});
|
|
|
|
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_REF_FUNC(function_index),
|
|
|
|
kExprCallRef});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, kExprReturnCallRef});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_GC_OP(kExprStructNewWithRtt),
|
|
|
|
struct_index, kExprCallFunction, struct_consumer});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
|
|
|
WASM_GC_OP(kExprStructNewWithRtt), struct_index,
|
|
|
|
kExprCallFunction, struct_consumer});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_I64V(42),
|
|
|
|
WASM_RTT_CANON(struct_index),
|
|
|
|
WASM_GC_OP(kExprStructNewWithRtt), struct_index,
|
|
|
|
kExprCallFunction, struct_consumer});
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_GC_OP(kExprStructNewDefault),
|
|
|
|
struct_index, kExprDrop});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
|
|
|
WASM_GC_OP(kExprStructNewDefault), struct_index,
|
|
|
|
kExprCallFunction, struct_consumer});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_GC_OP(kExprArrayNewWithRtt),
|
|
|
|
array_index, kExprDrop});
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_RTT_CANON(array_index),
|
|
|
|
WASM_GC_OP(kExprArrayNewWithRtt), array_index, kExprDrop});
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_I32V(42), WASM_RTT_CANON(array_index),
|
|
|
|
WASM_GC_OP(kExprArrayNewWithRtt), array_index, kExprDrop});
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_GC_OP(kExprArrayNewDefault),
|
|
|
|
array_index, kExprDrop});
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_RTT_CANON(array_index),
|
|
|
|
WASM_GC_OP(kExprArrayNewDefault), array_index, kExprDrop});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTest),
|
|
|
|
struct_index, struct_index});
|
|
|
|
ExpectValidates(sigs.i_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
|
|
|
WASM_GC_OP(kExprRefTest), struct_index, struct_index});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCast),
|
|
|
|
struct_index, struct_index, kExprDrop});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
|
|
|
WASM_GC_OP(kExprRefCast), struct_index,
|
|
|
|
struct_index, kExprDrop});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_UNREACHABLE, WASM_GC_OP(kExprRttSub), array_index,
|
|
|
|
WASM_GC_OP(kExprRttSub), array_index, kExprDrop});
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, If1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9),
|
|
|
|
WASM_I32V_1(8))});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9),
|
|
|
|
WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_i(),
|
|
|
|
{WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I32V_1(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++) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sigs.i_i(), VectorOf(kCode, len), kAppendEnd);
|
|
|
|
ExpectFailure(sigs.i_i(), VectorOf(kCode, len), kOmitEnd);
|
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[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(0), WASM_I32V_1(2))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), kCode);
|
|
|
|
ExpectFailure(sigs.i_f(), kCode);
|
|
|
|
ExpectFailure(sigs.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[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_I32V_1(1), WASM_GET_LOCAL(0), WASM_I32V_1(1))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), kCode);
|
|
|
|
ExpectFailure(sigs.i_f(), kCode);
|
|
|
|
ExpectFailure(sigs.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[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_NOP, WASM_I32V_1(0), WASM_I32V_1(1))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), kCode);
|
|
|
|
ExpectFailure(sigs.i_f(), kCode);
|
|
|
|
ExpectFailure(sigs.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[] = {
|
2017-01-09 13:57:26 +00:00
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I32V_1(1))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), kCode);
|
|
|
|
ExpectFailure(sigs.i_f(), kCode);
|
|
|
|
ExpectFailure(sigs.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
|
2017-01-09 13:57:26 +00:00
|
|
|
static const byte kCode[] = {
|
|
|
|
WASM_IF_ELSE_I(WASM_ZERO, WASM_I32V_1(1), WASM_NOP)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), kCode);
|
|
|
|
ExpectFailure(sigs.i_f(), kCode);
|
|
|
|
ExpectFailure(sigs.i_d(), kCode);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Int64Local_param) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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++) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_SET_LOCAL(0, WASM_I32V_3(87348))});
|
|
|
|
ExpectValidates(
|
|
|
|
sigs.v_i(),
|
|
|
|
{WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24), WASM_I32V_1(40))});
|
|
|
|
ExpectValidates(sigs.v_i(), {WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_NOP});
|
|
|
|
ExpectValidates(sigs.v_v(), {B1(WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {B2(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_v(), {B3(WASM_NOP, WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_LOOP(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectValidates(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))});
|
|
|
|
ExpectValidates(sigs.v_v(), {B3(WASM_NOP, // --
|
|
|
|
B2(WASM_NOP, WASM_NOP), // --
|
|
|
|
B2(WASM_NOP, WASM_NOP))}); // --
|
|
|
|
ExpectValidates(sigs.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);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_ii_v, {WASM_RETURNN(2, WASM_ZERO, WASM_ONE)});
|
|
|
|
ExpectFailure(&sig_ii_v, {WASM_RETURNN(1, WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
FunctionSig sig_iii_v(3, 0, kIntTypes5);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_iii_v,
|
|
|
|
{WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I32V_1(44))});
|
|
|
|
ExpectFailure(&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);
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_ii_v, {WASM_ZERO, WASM_ONE});
|
|
|
|
ExpectFailure(&sig_ii_v, {WASM_ZERO});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
FunctionSig sig_iii_v(3, 0, kIntTypes5);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_iii_v, {WASM_ZERO, WASM_ONE, WASM_I32V_1(44)});
|
|
|
|
ExpectFailure(&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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(12))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(13))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I32V_1(14))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(15))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(16))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(17))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I32V_1(18))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I32V_1(19))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I32V_1(20))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I32V_1(21))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I32V_1(22))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I32V_1(23))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I32V_1(24))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I32V_1(24))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I32V_1(24))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(25))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I32V_1(25))});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I32V_1(26))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I32V_1(27))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I32V_1(28))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I32V_1(29))});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I32V_1(26))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I32V_1(27))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I32V_1(28))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I32V_1(29))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MacrosInt64) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))});
|
|
|
|
ExpectValidates(sigs.l_ll(),
|
|
|
|
{WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))});
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))});
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))});
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))});
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))});
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))});
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))});
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_ll(),
|
|
|
|
{WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))});
|
|
|
|
ExpectValidates(sigs.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) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2015-12-11 12:26:16 +00:00
|
|
|
// Test all simple expressions which are described by a signature.
|
2020-02-25 20:00:50 +00:00
|
|
|
#define DECODE_TEST(name, opcode, sig) \
|
|
|
|
{ \
|
|
|
|
const FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \
|
|
|
|
if (sig->parameter_count() == 1) { \
|
|
|
|
TestUnop(kExpr##name, sig); \
|
|
|
|
} else { \
|
|
|
|
TestBinop(kExpr##name, sig); \
|
|
|
|
} \
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FOREACH_SIMPLE_OPCODE(DECODE_TEST);
|
|
|
|
|
|
|
|
#undef DECODE_TEST
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MemorySize) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2016-10-26 16:56:05 +00:00
|
|
|
byte code[] = {kExprMemorySize, 0};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.f_ff(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoadMemOffset) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2015-12-11 12:26:16 +00:00
|
|
|
for (int offset = 0; offset < 128; offset += 7) {
|
2017-01-09 13:57:26 +00:00
|
|
|
byte code[] = {kExprI32Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT,
|
2016-04-29 09:15:26 +00:00
|
|
|
static_cast<byte>(offset)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
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};
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(alignment <= values[i].maximum_aligment, sigs.v_i(), code);
|
2016-09-02 11:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StoreMemOffset) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2017-04-25 12:03:08 +00:00
|
|
|
for (byte 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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StoreMemOffset_void) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, LoadMemOffset_varint) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
2019-08-09 23:51:05 +00:00
|
|
|
{WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, U32V_1(0x45)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
2019-08-09 23:51:05 +00:00
|
|
|
U32V_2(0x3999)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
2019-08-09 23:51:05 +00:00
|
|
|
U32V_3(0x344445)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
|
2019-08-09 23:51:05 +00:00
|
|
|
U32V_4(0x36666667)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StoreMemOffset_varint) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
|
2019-08-09 23:51:05 +00:00
|
|
|
ZERO_ALIGNMENT, U32V_1(0x33)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
|
2019-08-09 23:51:05 +00:00
|
|
|
ZERO_ALIGNMENT, U32V_2(0x1111)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
|
2019-08-09 23:51:05 +00:00
|
|
|
ZERO_ALIGNMENT, U32V_3(0x222222)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(), {WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
|
2019-08-09 23:51:05 +00:00
|
|
|
ZERO_ALIGNMENT, U32V_4(0x44444444)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
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);
|
2020-03-12 14:29:51 +00:00
|
|
|
Validate(local_type == ValueType::For(mem_type), &sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
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);
|
2020-03-12 14:29:51 +00:00
|
|
|
Validate(local_type == ValueType::For(mem_type), &sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleCalls) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddFunction(sigs.i_v());
|
|
|
|
builder.AddFunction(sigs.i_i());
|
|
|
|
builder.AddFunction(sigs.i_ii());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_CALL_FUNCTION0(0)});
|
|
|
|
ExpectValidates(sig, {WASM_CALL_FUNCTION(1, WASM_I32V_1(27))});
|
|
|
|
ExpectValidates(sig,
|
|
|
|
{WASM_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddFunction(sigs.i_i());
|
|
|
|
builder.AddFunction(sigs.i_ii());
|
|
|
|
builder.AddFunction(sigs.f_ff());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION0(0)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_ZERO)});
|
|
|
|
ExpectFailure(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddFunction(sigs.i_i());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_I64V_1(17))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_F32(17.1))});
|
|
|
|
ExpectFailure(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddFunction(sigs.i_f());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_I32V_1(17))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_I64V_1(27))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(0, WASM_F64(37.2))});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddFunction(sigs.i_d());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_I32V_1(16))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_I64V_1(16))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(1, WASM_F32(17.6))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 22:54:45 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleReturnCalls) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
builder.AddFunction(sigs.i_v());
|
|
|
|
builder.AddFunction(sigs.i_i());
|
|
|
|
builder.AddFunction(sigs.i_ii());
|
|
|
|
|
|
|
|
ExpectValidates(sig, {WASM_RETURN_CALL_FUNCTION0(0)});
|
|
|
|
ExpectValidates(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_I32V_1(27))});
|
|
|
|
ExpectValidates(
|
|
|
|
sig, {WASM_RETURN_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77))});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, ReturnCallsWithTooFewArguments) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
builder.AddFunction(sigs.i_i());
|
|
|
|
builder.AddFunction(sigs.i_ii());
|
|
|
|
builder.AddFunction(sigs.f_ff());
|
|
|
|
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION0(0)});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(2, WASM_GET_LOCAL(0))});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, ReturnCallsWithMismatchedSigs) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
builder.AddFunction(sigs.i_f());
|
|
|
|
builder.AddFunction(sigs.f_f());
|
|
|
|
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(0, WASM_I32V_1(17))});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(0, WASM_I64V_1(27))});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(0, WASM_F64(37.2))});
|
|
|
|
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_F64(37.2))});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_F32(37.2))});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_FUNCTION(1, WASM_I32V_1(17))});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleIndirectReturnCalls) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-07-08 20:23:30 +00:00
|
|
|
builder.AddTable(kWasmFuncRef, 20, true, 30);
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.i_v());
|
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectValidates(sig, {WASM_RETURN_CALL_INDIRECT(sig0, WASM_ZERO)});
|
2019-11-26 12:28:19 +00:00
|
|
|
ExpectValidates(
|
2019-11-28 13:55:59 +00:00
|
|
|
sig, {WASM_RETURN_CALL_INDIRECT(sig1, WASM_I32V_1(22), WASM_ZERO)});
|
|
|
|
ExpectValidates(sig, {WASM_RETURN_CALL_INDIRECT(sig2, WASM_I32V_1(32),
|
|
|
|
WASM_I32V_2(72), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectReturnCallsOutOfBounds) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-07-08 20:23:30 +00:00
|
|
|
builder.AddTable(kWasmFuncRef, 20, false, 20);
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(0, WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
builder.AddSignature(sigs.i_v());
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectValidates(sig, {WASM_RETURN_CALL_INDIRECT(0, WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(1, WASM_I32V_1(22), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
builder.AddSignature(sigs.i_i());
|
|
|
|
ExpectValidates(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(1, WASM_I32V_1(27), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(2, WASM_I32V_1(27), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectReturnCallsWithMismatchedSigs3) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.i_f());
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig0, WASM_I32V_1(17), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig0, WASM_I64V_1(27), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig0, WASM_F64(37.2), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(sig0, WASM_I32V_1(17))});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(sig0, WASM_I64V_1(27))});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(sig0, WASM_F64(37.2))});
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig1 = builder.AddFunction(sigs.i_d());
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig1, WASM_I32V_1(16), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig1, WASM_I64V_1(16), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig1, WASM_F32(17.6), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectReturnCallsWithoutTableCrash) {
|
|
|
|
WASM_FEATURE_SCOPE(return_call);
|
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.i_v());
|
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2019-02-13 22:54:45 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(sig0, WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
ExpectFailure(sig,
|
2019-11-28 13:55:59 +00:00
|
|
|
{WASM_RETURN_CALL_INDIRECT(sig1, WASM_I32V_1(22), WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_RETURN_CALL_INDIRECT(sig2, WASM_I32V_1(32),
|
|
|
|
WASM_I32V_2(72), WASM_ZERO)});
|
2019-02-13 22:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, IncompleteIndirectReturnCall) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2019-02-13 22:54:45 +00:00
|
|
|
|
|
|
|
static byte code[] = {kExprReturnCallIndirect};
|
|
|
|
ExpectFailure(sig, ArrayVector(code), kOmitEnd);
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiReturn) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
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);
|
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddFunction(&sig_v_ii);
|
|
|
|
builder.AddFunction(&sig_ii_v);
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_ii_v, {WASM_CALL_FUNCTION0(1)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_CALL_FUNCTION0(1), kExprCallFunction, 0});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiReturnType) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
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);
|
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
builder.AddFunction(&sig_cd_v);
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_cd_v, {WASM_CALL_FUNCTION0(0)});
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2020-06-12 08:51:09 +00:00
|
|
|
if (IsSubtypeOf(kValueTypes[c], kValueTypes[a], module) &&
|
|
|
|
IsSubtypeOf(kValueTypes[d], kValueTypes[b], module)) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig_ab_v, {WASM_CALL_FUNCTION0(0)});
|
2016-09-27 20:46:10 +00:00
|
|
|
} else {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig_ab_v, {WASM_CALL_FUNCTION0(0)});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleIndirectCalls) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-07-08 20:23:30 +00:00
|
|
|
builder.AddTable(kWasmFuncRef, 20, false, 20);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.i_v());
|
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectValidates(sig, {WASM_CALL_INDIRECT(sig0, WASM_ZERO)});
|
|
|
|
ExpectValidates(sig, {WASM_CALL_INDIRECT(sig1, WASM_I32V_1(22), WASM_ZERO)});
|
|
|
|
ExpectValidates(sig, {WASM_CALL_INDIRECT(sig2, WASM_I32V_1(32),
|
|
|
|
WASM_I32V_2(72), WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2019-07-08 20:23:30 +00:00
|
|
|
builder.AddTable(kWasmFuncRef, 20, false, 20);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(0, WASM_ZERO)});
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddSignature(sigs.i_v());
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectValidates(sig, {WASM_CALL_INDIRECT(0, WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(1, WASM_I32V_1(22), WASM_ZERO)});
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddSignature(sigs.i_i());
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectValidates(sig, {WASM_CALL_INDIRECT(1, WASM_I32V_1(27), WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(2, WASM_I32V_1(27), WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 14:38:49 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs1) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.i_f());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_I32V_1(17), WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_I64V_1(27), WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_F64(37.2), WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_I32V_1(17))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_I64V_1(27))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_F64(37.2))});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig1 = builder.AddFunction(sigs.i_d());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig1, WASM_I32V_1(16), WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig1, WASM_I64V_1(16), WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig1, WASM_F32(17.6), WASM_ZERO)});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 14:38:49 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs2) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
byte table_type_index = builder.AddSignature(sigs.i_i());
|
|
|
|
byte table_index =
|
|
|
|
builder.InitializeTable(ValueType::Ref(table_type_index, kNullable));
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_v(),
|
|
|
|
{WASM_CALL_INDIRECT_TABLE(table_index, table_type_index,
|
|
|
|
WASM_I32V_1(42), WASM_ZERO)});
|
|
|
|
|
|
|
|
byte wrong_type_index = builder.AddSignature(sigs.i_ii());
|
|
|
|
ExpectFailure(sigs.i_v(),
|
|
|
|
{WASM_CALL_INDIRECT_TABLE(table_index, wrong_type_index,
|
|
|
|
WASM_I32V_1(42), WASM_ZERO)},
|
|
|
|
kAppendEnd,
|
|
|
|
"call_indirect: Immediate signature #1 is not a subtype of "
|
|
|
|
"immediate table #0");
|
|
|
|
|
|
|
|
byte non_function_table_index = builder.InitializeTable(kWasmExternRef);
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_v(),
|
|
|
|
{WASM_CALL_INDIRECT_TABLE(non_function_table_index, table_type_index,
|
|
|
|
WASM_I32V_1(42), WASM_ZERO)},
|
|
|
|
kAppendEnd,
|
|
|
|
"call_indirect: immediate table #1 is not of a function type");
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2016-11-09 08:37:05 +00:00
|
|
|
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.i_v());
|
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2016-11-09 08:37:05 +00:00
|
|
|
|
2019-11-28 13:55:59 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig0, WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig1, WASM_I32V_1(22), WASM_ZERO)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_INDIRECT(sig2, WASM_I32V_1(32), WASM_I32V_2(72),
|
|
|
|
WASM_ZERO)});
|
2016-11-09 08:37:05 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 15:50:20 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IncompleteIndirectCall) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2017-12-19 15:50:20 +00:00
|
|
|
|
|
|
|
static byte code[] = {kExprCallIndirect};
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sig, ArrayVector(code), kOmitEnd);
|
2017-12-19 15:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, IncompleteStore) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2017-12-19 15:50:20 +00:00
|
|
|
builder.InitializeMemory();
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2017-12-19 15:50:20 +00:00
|
|
|
|
|
|
|
static byte code[] = {kExprI32StoreMem};
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sig, ArrayVector(code), kOmitEnd);
|
2017-12-19 15:50:20 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 18:08:04 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, IncompleteI8x16Shuffle) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(simd);
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2017-12-19 15:50:20 +00:00
|
|
|
builder.InitializeMemory();
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2017-12-19 15:50:20 +00:00
|
|
|
|
|
|
|
static byte code[] = {kSimdPrefix,
|
2020-09-25 18:08:04 +00:00
|
|
|
static_cast<byte>(kExprI8x16Shuffle & 0xff)};
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sig, ArrayVector(code), kOmitEnd);
|
2017-12-19 15:50:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2016-02-19 14:58:25 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
byte f0 = builder.AddImport(sigs.i_v());
|
|
|
|
byte f1 = builder.AddImport(sigs.i_i());
|
|
|
|
byte f2 = builder.AddImport(sigs.i_ii());
|
2016-02-19 14:58:25 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_CALL_FUNCTION0(f0)});
|
|
|
|
ExpectValidates(sig, {WASM_CALL_FUNCTION(f1, WASM_I32V_1(22))});
|
|
|
|
ExpectValidates(sig,
|
|
|
|
{WASM_CALL_FUNCTION(f2, WASM_I32V_1(32), WASM_I32V_2(72))});
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2016-02-19 14:58:25 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
byte f0 = builder.AddImport(sigs.i_f());
|
2016-02-19 14:58:25 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION0(f0)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(f0, WASM_I32V_1(17))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(f0, WASM_F64(37.2))});
|
2016-02-19 14:58:25 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
byte f1 = builder.AddImport(sigs.i_d());
|
2016-02-19 14:58:25 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION0(f1)});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(f1, WASM_I32V_1(16))});
|
|
|
|
ExpectFailure(sig, {WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))});
|
|
|
|
ExpectFailure(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddGlobal(kWasmI32);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_GET_GLOBAL(0)});
|
|
|
|
ExpectFailure(sig, {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))});
|
|
|
|
ExpectValidates(sig, {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.v_v();
|
2016-09-27 20:46:10 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
uint32_t g0 = builder.AddGlobal(kWasmI32, true);
|
|
|
|
uint32_t g1 = builder.AddGlobal(kWasmI32, false);
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_SET_GLOBAL(g0, WASM_ZERO)});
|
|
|
|
ExpectFailure(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.i_i();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddGlobal(kWasmI64);
|
|
|
|
builder.AddGlobal(kWasmI64);
|
|
|
|
builder.AddGlobal(kWasmF32);
|
|
|
|
builder.AddGlobal(kWasmF64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_GET_GLOBAL(0)});
|
|
|
|
ExpectFailure(sig, {WASM_GET_GLOBAL(1)});
|
|
|
|
ExpectFailure(sig, {WASM_GET_GLOBAL(2)});
|
|
|
|
ExpectFailure(sig, {WASM_GET_GLOBAL(3)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sig, {WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO});
|
|
|
|
ExpectFailure(sig, {WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO});
|
|
|
|
ExpectFailure(sig, {WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO});
|
|
|
|
ExpectFailure(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.l_l();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddGlobal(kWasmI64);
|
|
|
|
builder.AddGlobal(kWasmI64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_GET_GLOBAL(0)});
|
|
|
|
ExpectValidates(sig, {WASM_GET_GLOBAL(1)});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig,
|
|
|
|
{WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_GET_LOCAL(0)});
|
|
|
|
ExpectValidates(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.f_ff();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddGlobal(kWasmF32);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_GET_GLOBAL(0)});
|
|
|
|
ExpectValidates(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) {
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = sigs.d_dd();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.AddGlobal(kWasmF64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, {WASM_GET_GLOBAL(0)});
|
|
|
|
ExpectValidates(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);
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
builder.AddGlobal(global_type);
|
2020-06-12 08:51:09 +00:00
|
|
|
Validate(IsSubtypeOf(global_type, local_type, module), &sig,
|
2020-06-05 07:27:10 +00:00
|
|
|
{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);
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
builder.AddGlobal(global_type);
|
2020-06-12 08:51:09 +00:00
|
|
|
Validate(IsSubtypeOf(local_type, global_type, module), &sig,
|
2019-02-08 13:38:33 +00:00
|
|
|
{WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 11:49:58 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableSet) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-09-21 14:38:49 +00:00
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
|
|
|
|
byte tab_type = builder.AddSignature(sigs.i_i());
|
2020-06-09 15:54:14 +00:00
|
|
|
byte tab_ref1 = builder.AddTable(kWasmExternRef, 10, true, 20);
|
2019-07-08 20:23:30 +00:00
|
|
|
byte tab_func1 = builder.AddTable(kWasmFuncRef, 20, true, 30);
|
|
|
|
byte tab_func2 = builder.AddTable(kWasmFuncRef, 10, false, 20);
|
2020-06-09 15:54:14 +00:00
|
|
|
byte tab_ref2 = builder.AddTable(kWasmExternRef, 10, false, 20);
|
2020-09-21 14:38:49 +00:00
|
|
|
byte tab_typed_func =
|
|
|
|
builder.AddTable(ValueType::Ref(tab_type, kNullable), 10, false, 20);
|
|
|
|
|
|
|
|
ValueType sig_types[]{kWasmExternRef, kWasmFuncRef, kWasmI32,
|
|
|
|
ValueType::Ref(tab_type, kNonNullable)};
|
|
|
|
FunctionSig sig(0, 4, sig_types);
|
2019-02-07 13:46:00 +00:00
|
|
|
byte local_ref = 0;
|
|
|
|
byte local_func = 1;
|
2020-05-29 15:23:27 +00:00
|
|
|
byte local_int = 2;
|
2020-09-21 14:38:49 +00:00
|
|
|
byte local_typed_func = 3;
|
|
|
|
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectValidates(&sig, {WASM_TABLE_SET(tab_ref1, WASM_I32V(6),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_ref))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectValidates(&sig, {WASM_TABLE_SET(tab_func1, WASM_I32V(5),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_func))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectValidates(&sig, {WASM_TABLE_SET(tab_func2, WASM_I32V(7),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_func))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectValidates(&sig, {WASM_TABLE_SET(tab_ref2, WASM_I32V(8),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_ref))});
|
2020-09-21 14:38:49 +00:00
|
|
|
ExpectValidates(&sig, {WASM_TABLE_SET(tab_typed_func, WASM_I32V(8),
|
|
|
|
WASM_GET_LOCAL(local_typed_func))});
|
|
|
|
ExpectValidates(&sig, {WASM_TABLE_SET(tab_func1, WASM_I32V(8),
|
|
|
|
WASM_GET_LOCAL(local_typed_func))});
|
2019-02-07 13:46:00 +00:00
|
|
|
|
2020-05-29 15:23:27 +00:00
|
|
|
// Only values of the correct type can be set to a table.
|
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_ref1, WASM_I32V(4),
|
|
|
|
WASM_GET_LOCAL(local_func))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_func1, WASM_I32V(9),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_ref))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_func2, WASM_I32V(3),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_ref))});
|
2020-05-29 15:23:27 +00:00
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_ref2, WASM_I32V(2),
|
|
|
|
WASM_GET_LOCAL(local_func))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_ref1, WASM_I32V(9),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_int))});
|
2019-07-08 11:49:58 +00:00
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_func1, WASM_I32V(3),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_int))});
|
2020-09-21 14:38:49 +00:00
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(tab_typed_func, WASM_I32V(3),
|
|
|
|
WASM_GET_LOCAL(local_func))});
|
2020-01-15 11:55:19 +00:00
|
|
|
|
2019-02-07 13:46:00 +00:00
|
|
|
// Out-of-bounds table index should fail.
|
|
|
|
byte oob_tab = 37;
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
2019-07-08 11:49:58 +00:00
|
|
|
&sig, {WASM_TABLE_SET(oob_tab, WASM_I32V(9), WASM_GET_LOCAL(local_ref))});
|
|
|
|
ExpectFailure(&sig, {WASM_TABLE_SET(oob_tab, WASM_I32V(3),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(local_func))});
|
2019-02-07 13:46:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 11:49:58 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableGet) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-09-21 14:38:49 +00:00
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
|
|
|
|
byte tab_type = builder.AddSignature(sigs.i_i());
|
2020-06-09 15:54:14 +00:00
|
|
|
byte tab_ref1 = builder.AddTable(kWasmExternRef, 10, true, 20);
|
2019-07-08 20:23:30 +00:00
|
|
|
byte tab_func1 = builder.AddTable(kWasmFuncRef, 20, true, 30);
|
|
|
|
byte tab_func2 = builder.AddTable(kWasmFuncRef, 10, false, 20);
|
2020-06-09 15:54:14 +00:00
|
|
|
byte tab_ref2 = builder.AddTable(kWasmExternRef, 10, false, 20);
|
2020-09-21 14:38:49 +00:00
|
|
|
byte tab_typed_func =
|
|
|
|
builder.AddTable(ValueType::Ref(tab_type, kNullable), 10, false, 20);
|
|
|
|
|
|
|
|
ValueType sig_types[]{kWasmExternRef, kWasmFuncRef, kWasmI32,
|
|
|
|
ValueType::Ref(tab_type, kNullable)};
|
|
|
|
FunctionSig sig(0, 4, sig_types);
|
2019-02-07 13:46:00 +00:00
|
|
|
byte local_ref = 0;
|
|
|
|
byte local_func = 1;
|
|
|
|
byte local_int = 2;
|
2020-09-21 14:38:49 +00:00
|
|
|
byte local_typed_func = 3;
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
2019-02-07 13:46:00 +00:00
|
|
|
&sig,
|
2019-07-08 11:49:58 +00:00
|
|
|
{WASM_SET_LOCAL(local_ref, WASM_TABLE_GET(tab_ref1, WASM_I32V(6)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
2019-02-07 13:46:00 +00:00
|
|
|
&sig,
|
2019-07-08 11:49:58 +00:00
|
|
|
{WASM_SET_LOCAL(local_ref, WASM_TABLE_GET(tab_ref2, WASM_I32V(8)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
&sig,
|
2019-07-08 11:49:58 +00:00
|
|
|
{WASM_SET_LOCAL(local_func, WASM_TABLE_GET(tab_func1, WASM_I32V(5)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
&sig,
|
2019-07-08 11:49:58 +00:00
|
|
|
{WASM_SET_LOCAL(local_func, WASM_TABLE_GET(tab_func2, WASM_I32V(7)))});
|
2019-08-09 23:42:22 +00:00
|
|
|
ExpectValidates(
|
|
|
|
&sig, {WASM_SET_LOCAL(local_ref, WASM_SEQ(WASM_I32V(6), kExprTableGet,
|
|
|
|
U32V_2(tab_ref1)))});
|
2020-09-21 14:38:49 +00:00
|
|
|
ExpectValidates(
|
|
|
|
&sig, {WASM_SET_LOCAL(local_func,
|
|
|
|
WASM_TABLE_GET(tab_typed_func, WASM_I32V(7)))});
|
|
|
|
ExpectValidates(
|
|
|
|
&sig, {WASM_SET_LOCAL(local_typed_func,
|
|
|
|
WASM_TABLE_GET(tab_typed_func, WASM_I32V(7)))});
|
2019-02-07 13:46:00 +00:00
|
|
|
|
2020-05-29 15:23:27 +00:00
|
|
|
// We cannot store references as any other type.
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(local_func,
|
2019-07-08 11:49:58 +00:00
|
|
|
WASM_TABLE_GET(tab_ref1, WASM_I32V(4)))});
|
2020-05-29 15:23:27 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(
|
|
|
|
local_ref, WASM_TABLE_GET(tab_func1, WASM_I32V(9)))});
|
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(
|
|
|
|
local_ref, WASM_TABLE_GET(tab_func2, WASM_I32V(3)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(local_func,
|
2019-07-08 11:49:58 +00:00
|
|
|
WASM_TABLE_GET(tab_ref2, WASM_I32V(2)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
|
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(local_int,
|
2019-07-08 11:49:58 +00:00
|
|
|
WASM_TABLE_GET(tab_ref1, WASM_I32V(9)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(
|
2019-07-08 11:49:58 +00:00
|
|
|
local_int, WASM_TABLE_GET(tab_func1, WASM_I32V(3)))});
|
2020-09-21 14:38:49 +00:00
|
|
|
ExpectFailure(&sig,
|
|
|
|
{WASM_SET_LOCAL(local_typed_func,
|
|
|
|
WASM_TABLE_GET(tab_func1, WASM_I32V(3)))});
|
|
|
|
|
2019-02-07 13:46:00 +00:00
|
|
|
// Out-of-bounds table index should fail.
|
|
|
|
byte oob_tab = 37;
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
2019-07-08 11:49:58 +00:00
|
|
|
&sig, {WASM_SET_LOCAL(local_ref, WASM_TABLE_GET(oob_tab, WASM_I32V(9)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SET_LOCAL(local_func,
|
2019-07-08 11:49:58 +00:00
|
|
|
WASM_TABLE_GET(oob_tab, WASM_I32V(3)))});
|
2019-02-07 13:46:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 08:07:46 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiTableCallIndirect) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
byte tab_ref = builder.AddTable(kWasmExternRef, 10, true, 20);
|
2019-07-08 20:23:30 +00:00
|
|
|
byte tab_func = builder.AddTable(kWasmFuncRef, 20, true, 30);
|
2019-03-21 08:07:46 +00:00
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
ValueType sig_types[]{kWasmExternRef, kWasmFuncRef, kWasmI32};
|
2019-03-21 08:07:46 +00:00
|
|
|
FunctionSig sig(0, 3, sig_types);
|
|
|
|
byte sig_index = builder.AddSignature(sigs.i_v());
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
// We can store funcref values as externref, but not the other way around.
|
2019-03-21 08:07:46 +00:00
|
|
|
ExpectValidates(sigs.i_v(),
|
|
|
|
{kExprI32Const, 0, kExprCallIndirect, sig_index, tab_func});
|
|
|
|
|
|
|
|
ExpectFailure(sigs.i_v(),
|
|
|
|
{kExprI32Const, 0, kExprCallIndirect, sig_index, tab_ref});
|
|
|
|
}
|
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, WasmMemoryGrow) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2016-09-12 10:16:06 +00:00
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
byte code[] = {WASM_GET_LOCAL(0), kExprMemoryGrow, 0};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.i_d(), code);
|
2016-09-12 10:16:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, AsmJsMemoryGrow) {
|
2020-06-02 12:07:22 +00:00
|
|
|
module->origin = kAsmJsSloppyOrigin;
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
builder.InitializeMemory();
|
2016-09-12 10:16:06 +00:00
|
|
|
|
2018-10-26 17:28:37 +00:00
|
|
|
byte code[] = {WASM_GET_LOCAL(0), kExprMemoryGrow, 0};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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;
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig;
|
2016-09-12 10:16:06 +00:00
|
|
|
} 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},
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2019-07-19 11:10:49 +00:00
|
|
|
TestModuleBuilder builder(kAsmJsSloppyOrigin);
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
module = builder.module();
|
|
|
|
builder.InitializeMemory();
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
builder.InitializeMemory();
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(AsmJsBinOps[i].sig,
|
|
|
|
{WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(1))});
|
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;
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig;
|
2016-09-12 10:16:06 +00:00
|
|
|
} 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()}};
|
|
|
|
{
|
2019-07-19 11:10:49 +00:00
|
|
|
TestModuleBuilder builder(kAsmJsSloppyOrigin);
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
module = builder.module();
|
|
|
|
builder.InitializeMemory();
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
builder.InitializeMemory();
|
2016-11-10 12:50:51 +00:00
|
|
|
for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(AsmJsUnOps[i].sig,
|
|
|
|
{WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))});
|
2016-09-12 10:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakEnd) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_i(),
|
|
|
|
{WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))});
|
|
|
|
ExpectValidates(
|
|
|
|
sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_BLOCK_I(WASM_I32_ADD(
|
|
|
|
WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_BLOCK_I(WASM_I32_ADD(
|
|
|
|
WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))});
|
|
|
|
ExpectValidates(
|
2016-09-27 20:46:10 +00:00
|
|
|
sigs.f_ff(),
|
2019-02-08 10:10:45 +00:00
|
|
|
{WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIfBinop_fail) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
2016-09-27 20:46:10 +00:00
|
|
|
sigs.f_ff(),
|
2019-02-08 10:10:45 +00:00
|
|
|
{WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))});
|
|
|
|
ExpectFailure(
|
2016-09-27 20:46:10 +00:00
|
|
|
sigs.i_i(),
|
2019-02-08 10:10:45 +00:00
|
|
|
{WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))});
|
2016-04-29 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 09:56:09 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIfUnrNarrow) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
2017-08-30 09:56:09 +00:00
|
|
|
sigs.f_ff(),
|
2019-02-08 10:10:45 +00:00
|
|
|
{WASM_BLOCK_I(WASM_BRV_IF(0, WASM_UNREACHABLE, WASM_UNREACHABLE),
|
|
|
|
WASM_RETURN0),
|
|
|
|
WASM_F32(0.0)});
|
2017-08-30 09:56:09 +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)),
|
2017-01-09 13:57:26 +00:00
|
|
|
WASM_SET_LOCAL(0, WASM_I32V_1(1))),
|
2016-09-27 20:46:10 +00:00
|
|
|
WASM_ZERO)};
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(i < 3, sigs.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))};
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(i <= 3, sigs.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)))))};
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(i < 4, sigs.v_v(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(),
|
|
|
|
{B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)), WASM_F32(7.7))});
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))});
|
|
|
|
ExpectFailure(sigs.i_i(), {B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(8)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_I32V_1(0)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))});
|
|
|
|
ExpectFailure(sigs.i_i(), {B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(9)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
|
|
|
|
WASM_BRV_IF_ZERO(0, WASM_I32V_1(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;
|
2017-01-09 15:20:13 +00:00
|
|
|
for (size_t pos = 0; pos < sizeof(code) - 1; pos++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
if (code[pos] != kExprBlock) continue;
|
|
|
|
if (m & 1) {
|
|
|
|
code[pos] = kExprLoop;
|
2020-09-29 07:46:36 +00:00
|
|
|
code[pos + 1] = kVoidCode;
|
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
|
|
|
}
|
|
|
|
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(i <= depth, sigs.v_v(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheck) {
|
2020-02-25 20:00:50 +00:00
|
|
|
for (const FunctionSig* sig :
|
|
|
|
{sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}) {
|
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))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// unify i32 and f32 => fail
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.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
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.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) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
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
|
|
|
|
2020-06-12 08:51:09 +00:00
|
|
|
Validate(IsSubtypeOf(kValueTypes[j], kValueTypes[i], module), &sig, code);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
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))};
|
|
|
|
|
2020-06-12 08:51:09 +00:00
|
|
|
Validate(IsSubtypeOf(kValueTypes[j], kValueTypes[i], module), &sig, code);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
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
|
|
|
|
2020-06-12 08:51:09 +00:00
|
|
|
Validate(IsSubtypeOf(kValueTypes[j], kValueTypes[i], module), &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
|
|
|
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(type == kWasmI32, &sig, code1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
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
|
|
|
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(types[2] == kWasmI32, &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) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
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
|
|
|
|
2020-06-12 08:51:09 +00:00
|
|
|
Validate(IsSubtypeOf(kValueTypes[j], kValueTypes[i], module), &sig, code);
|
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
|
|
|
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(type == kWasmI32, &sig, code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable0) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {kExprBrTable, 0, BR_TARGET(0)});
|
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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.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)};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable1a) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{B1(WASM_BR_TABLE(WASM_I32V_2(67), 0, BR_TARGET(0)))});
|
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)))};
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), code);
|
|
|
|
ExpectFailure(sigs.i_i(), code);
|
|
|
|
ExpectFailure(sigs.f_ff(), code);
|
|
|
|
ExpectFailure(sigs.d_dd(), code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable2a) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.v_v(),
|
|
|
|
{B1(WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(0)))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable2b) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_BLOCK(WASM_BLOCK(WASM_BR_TABLE(
|
|
|
|
WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))});
|
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++) {
|
2019-02-08 13:38:33 +00:00
|
|
|
ExpectFailure(sigs.i_i(), VectorOf(code, len), kAppendEnd);
|
|
|
|
ExpectFailure(sigs.i_i(), VectorOf(code, len), kOmitEnd);
|
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)))};
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(depth <= 1, sigs.v_i(), code);
|
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)))};
|
2019-02-08 13:38:33 +00:00
|
|
|
Validate(depth < 2, sigs.v_i(), code);
|
2016-03-04 23:48:00 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 16:00:32 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_BLOCK(WASM_BLOCK_I(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_BLOCK_I(WASM_BLOCK(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch_loop1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_LOOP(WASM_BLOCK_I(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_arity_mismatch_loop2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_BLOCK_I(WASM_LOOP(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_loop_block) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_LOOP(WASM_BLOCK(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_block_loop) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_LOOP(WASM_BLOCK(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_type_mismatch1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_BLOCK_I(WASM_BLOCK_F(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_type_mismatch2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_BLOCK_F(WASM_BLOCK_I(
|
|
|
|
WASM_ONE, WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrTable_type_mismatch_unreachable) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_BLOCK_F(WASM_BLOCK_I(
|
|
|
|
WASM_UNREACHABLE,
|
|
|
|
WASM_BR_TABLE(WASM_ONE, 1, BR_TARGET(0), BR_TARGET(1))))});
|
2017-09-20 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:06:21 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrUnreachable1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0)});
|
2017-02-02 23:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BrUnreachable2) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_i(),
|
|
|
|
{WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0), WASM_NOP});
|
|
|
|
ExpectFailure(sigs.v_i(),
|
|
|
|
{WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0), WASM_ZERO});
|
2017-01-20 14:32:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Brv1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))});
|
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_BLOCK_I(WASM_LOOP_I(WASM_BRV(2, WASM_ZERO)))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Brv1_type) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectValidates(sigs.l_ll(), {WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectValidates(sigs.f_ff(), {WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectValidates(sigs.d_dd(), {WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Brv1_type_n) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_f(), {WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectFailure(sigs.i_d(), {WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrvIf1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_v(), {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrvIf1_type) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(),
|
|
|
|
{WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectValidates(sigs.l_l(),
|
|
|
|
{WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectValidates(sigs.f_ff(),
|
|
|
|
{WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectValidates(sigs.d_dd(),
|
|
|
|
{WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrvIf1_type_n) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_f(),
|
|
|
|
{WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))});
|
|
|
|
ExpectFailure(sigs.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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
|
|
|
WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.f_ff(),
|
|
|
|
{WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.d_dd(),
|
|
|
|
{WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.l_l(),
|
|
|
|
{WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)});
|
2016-02-05 13:34:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 10:06:42 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Select_needs_value_type) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.e_e(),
|
2019-05-28 10:06:42 +00:00
|
|
|
{WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)});
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.c_c(),
|
2019-05-28 10:06:42 +00:00
|
|
|
{WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)});
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Select_fail1) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0),
|
|
|
|
WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(sigs.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;
|
2019-05-28 10:06:42 +00:00
|
|
|
// Select without specified type is only allowed for number types.
|
2020-06-10 07:22:22 +00:00
|
|
|
if (type == kWasmExternRef) 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);
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(&sig, {WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1),
|
|
|
|
WASM_GET_LOCAL(0))});
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(0))});
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&sig, {WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
|
|
|
WASM_GET_LOCAL(0))});
|
2016-02-05 13:34:41 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(&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) {
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(0))});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25),
|
|
|
|
WASM_GET_LOCAL(0))});
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0),
|
|
|
|
WASM_I64V_1(0))});
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 10:06:42 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, SelectWithType) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-05-28 10:06:42 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_SELECT_I(WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(0), WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.f_ff(),
|
|
|
|
{WASM_SELECT_F(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.d_dd(),
|
|
|
|
{WASM_SELECT_D(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.l_l(),
|
|
|
|
{WASM_SELECT_L(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)});
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectValidates(sigs.e_e(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_SELECT_R(WASM_REF_NULL(kExternRefCode),
|
|
|
|
WASM_REF_NULL(kExternRefCode), WASM_ZERO)});
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectValidates(sigs.c_c(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_SELECT_A(WASM_REF_NULL(kFuncRefCode),
|
|
|
|
WASM_REF_NULL(kFuncRefCode), WASM_ZERO)});
|
2019-05-28 10:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, SelectWithType_fail) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-05-28 10:06:42 +00:00
|
|
|
ExpectFailure(sigs.i_i(), {WASM_SELECT_F(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
|
|
|
WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.f_ff(),
|
|
|
|
{WASM_SELECT_D(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.d_dd(),
|
|
|
|
{WASM_SELECT_L(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.l_l(),
|
|
|
|
{WASM_SELECT_I(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)});
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Throw) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-08-29 12:43:06 +00:00
|
|
|
byte ex1 = builder.AddException(sigs.v_v());
|
|
|
|
byte ex2 = builder.AddException(sigs.v_i());
|
|
|
|
byte ex3 = builder.AddException(sigs.v_ii());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {kExprThrow, ex1});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_I32V(0), kExprThrow, ex2});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_F32(0.0), kExprThrow, ex2});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_I32V(0), WASM_I32V(0), kExprThrow, ex3});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_F32(0.0), WASM_I32V(0), kExprThrow, ex3});
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprThrow, 99});
|
2016-08-11 13:14:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 14:32:38 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ThrowUnreachable) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-08-29 12:43:06 +00:00
|
|
|
byte ex1 = builder.AddException(sigs.v_v());
|
|
|
|
byte ex2 = builder.AddException(sigs.v_i());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_i(), {WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_NOP});
|
|
|
|
ExpectValidates(sigs.v_i(), {WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_NOP});
|
|
|
|
ExpectValidates(sigs.i_i(), {WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_ZERO});
|
|
|
|
ExpectFailure(sigs.v_i(), {WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_ZERO});
|
|
|
|
ExpectFailure(sigs.i_i(),
|
|
|
|
{WASM_GET_LOCAL(0), kExprThrow, ex1, WASM_F32(0.0)});
|
|
|
|
ExpectFailure(sigs.v_i(),
|
|
|
|
{WASM_GET_LOCAL(0), kExprThrow, ex2, WASM_F32(0.0)});
|
2017-01-20 14:32:38 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 07:46:36 +00:00
|
|
|
#define WASM_TRY_OP kExprTry, kVoidCode
|
2019-01-15 13:44:03 +00:00
|
|
|
#define WASM_BR_ON_EXN(depth, index) \
|
|
|
|
kExprBrOnExn, static_cast<byte>(depth), static_cast<byte>(index)
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TryCatch) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, kExprDrop, kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch, kExprCatch, kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprEnd}); // Missing catch.
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch}); // Missing end.
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprCatch, kExprEnd}); // Missing try.
|
2018-10-08 12:21:14 +00:00
|
|
|
}
|
2016-08-11 13:14:51 +00:00
|
|
|
|
2019-01-15 13:44:03 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Rethrow) {
|
2018-10-08 12:21:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_TRY_OP, kExprCatch, kExprRethrow, kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprRethrow, kExprCatch, kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_BLOCK(kExprRethrow)});
|
|
|
|
ExpectFailure(sigs.v_v(), {kExprRethrow});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 13:44:03 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrOnExn) {
|
2018-10-11 10:58:24 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
byte ex1 = builder.AddException(sigs.v_v());
|
2019-01-15 13:44:03 +00:00
|
|
|
byte ex2 = builder.AddException(sigs.v_i());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1),
|
|
|
|
kExprDrop, kExprEnd});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex1),
|
|
|
|
kExprDrop, kExprEnd});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1),
|
|
|
|
WASM_BR_ON_EXN(0, ex1), kExprDrop, kExprEnd});
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_BLOCK(WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex1),
|
|
|
|
kExprDrop, kExprEnd)});
|
|
|
|
ExpectValidates(sigs.i_v(),
|
|
|
|
{WASM_BLOCK_I(WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(1, ex2),
|
|
|
|
kExprDrop, kExprEnd, kExprI32Const, 0)});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(2, ex1),
|
|
|
|
kExprDrop, kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TRY_OP, kExprCatch, kExprDrop,
|
|
|
|
WASM_BR_ON_EXN(0, ex1), kExprEnd});
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_TRY_OP, kExprCatch, WASM_BR_ON_EXN(0, ex1), kExprEnd});
|
2018-10-11 10:58:24 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 13:44:03 +00:00
|
|
|
#undef WASM_BR_ON_EXN
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef WASM_TRY_OP
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValBlock1) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.ii_v());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(sig0, WASM_NOP), kExprI32Add});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0)), kExprI32Add});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(0)),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprF32Add});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:42:06 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValBlock2) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.ii_v());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
2019-11-26 12:28:19 +00:00
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(sig0, WASM_NOP),
|
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(0)),
|
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_F32_ADD(WASM_NOP, WASM_NOP)});
|
2017-10-11 13:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValBlockBr) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.ii_v());
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0), WASM_BR(0)),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_BLOCK_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(1), WASM_BR(0)),
|
|
|
|
kExprI32Add});
|
2017-10-10 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 13:01:17 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValLoop1) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.ii_v());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_LOOP_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(sig0, WASM_NOP), kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
|
|
|
{WASM_LOOP_X(sig0, WASM_GET_LOCAL(0)), kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_LOOP_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprF32Add});
|
2017-10-11 13:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, MultiValIf) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig0 = builder.AddSignature(sigs.ii_v());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0), WASM_NOP,
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_NOP),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_GET_LOCAL(1)),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
|
|
|
WASM_GET_LOCAL(1)),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_ii(),
|
|
|
|
{WASM_IF_ELSE_X(
|
2019-11-26 12:28:19 +00:00
|
|
|
sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
|
|
|
|
WASM_GET_LOCAL(0)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1),
|
|
|
|
WASM_GET_LOCAL(1))),
|
|
|
|
kExprI32Add});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_IF_ELSE_X(sig0, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
|
|
|
|
WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
|
|
|
|
kExprF32Add});
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-24 10:47:09 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BlockParam) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_BLOCK_X(sig1, WASM_GET_LOCAL(1),
|
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_BLOCK_X(sig2, WASM_I32_ADD(WASM_NOP, WASM_NOP))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_BLOCK_X(sig1, WASM_NOP),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
2019-11-26 12:28:19 +00:00
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(sig1, WASM_NOP),
|
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_BLOCK_X(sig1, WASM_GET_LOCAL(0)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_BLOCK_X(sig2, WASM_I32_ADD(WASM_NOP, WASM_NOP)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_BLOCK_X(sig1, WASM_F32_NEG(WASM_NOP)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
2017-10-24 10:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, LoopParam) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_LOOP_X(sig1, WASM_GET_LOCAL(1),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP))});
|
|
|
|
ExpectValidates(sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_LOOP_X(sig2, WASM_I32_ADD(WASM_NOP, WASM_NOP))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_LOOP_X(sig1, WASM_NOP),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_LOOP_X(sig1, WASM_NOP), WASM_RETURN1(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_LOOP_X(sig1, WASM_GET_LOCAL(0)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
2019-11-26 12:28:19 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_LOOP_X(sig2, WASM_I32_ADD(WASM_NOP, WASM_NOP)),
|
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_LOOP_X(sig1, WASM_F32_NEG(WASM_NOP)),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
2017-10-24 10:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, LoopParamBr) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_LOOP_X(sig1, WASM_BR(0))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_LOOP_X(sig1, WASM_BRV(0, WASM_GET_LOCAL(1)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_LOOP_X(sig2, WASM_BR(0))});
|
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_LOOP_X(sig1, WASM_BLOCK_X(sig1, WASM_BR(1)))});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.i_ii(),
|
2019-11-26 12:28:19 +00:00
|
|
|
{WASM_GET_LOCAL(0), WASM_LOOP_X(sig1, WASM_BLOCK(WASM_BR(1))),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
|
|
|
ExpectFailure(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_LOOP_X(sig2, WASM_BLOCK_X(sig1, WASM_BR(1))),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_RETURN1(WASM_GET_LOCAL(0))});
|
2017-10-24 10:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, IfParam) {
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2019-11-26 12:28:19 +00:00
|
|
|
byte sig1 = builder.AddSignature(sigs.i_i());
|
|
|
|
byte sig2 = builder.AddSignature(sigs.i_ii());
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_IF_X(sig1, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_GET_LOCAL(1)))});
|
|
|
|
ExpectValidates(sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_IF_ELSE_X(sig1, WASM_GET_LOCAL(0),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_GET_LOCAL(1)),
|
|
|
|
WASM_I32_EQZ(WASM_NOP))});
|
|
|
|
ExpectValidates(
|
|
|
|
sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_IF_ELSE_X(sig2, WASM_GET_LOCAL(0), WASM_I32_ADD(WASM_NOP, WASM_NOP),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_MUL(WASM_NOP, WASM_NOP))});
|
|
|
|
ExpectValidates(sigs.i_ii(), {WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
2019-11-26 12:28:19 +00:00
|
|
|
WASM_IF_X(sig1, WASM_GET_LOCAL(0), WASM_NOP),
|
2019-02-08 10:10:45 +00:00
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
2019-11-26 12:28:19 +00:00
|
|
|
ExpectValidates(sigs.i_ii(),
|
|
|
|
{WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
|
|
|
|
WASM_IF_ELSE_X(sig1, WASM_GET_LOCAL(0), WASM_NOP,
|
|
|
|
WASM_I32_EQZ(WASM_NOP)),
|
|
|
|
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
|
2017-10-24 10:47:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 13:28:34 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, Regression709741) {
|
|
|
|
AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 1);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_NOP});
|
2018-11-30 09:32:45 +00:00
|
|
|
byte code[] = {WASM_NOP, WASM_END};
|
2017-04-10 13:28:34 +00:00
|
|
|
|
2018-11-30 09:32:45 +00:00
|
|
|
for (size_t i = 0; i < arraysize(code); ++i) {
|
|
|
|
FunctionBody body(sigs.v_v(), 0, code, code + i);
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmFeatures unused_detected_features;
|
2017-04-10 13:28:34 +00:00
|
|
|
DecodeResult result =
|
2020-11-17 15:28:08 +00:00
|
|
|
VerifyWasmCode(this->zone()->allocator(), WasmFeatures::All(), nullptr,
|
2018-08-08 14:54:44 +00:00
|
|
|
&unused_detected_features, body);
|
2017-04-10 13:28:34 +00:00
|
|
|
if (result.ok()) {
|
|
|
|
std::ostringstream str;
|
|
|
|
str << "Expected verification to fail";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MemoryInit) {
|
|
|
|
builder.InitializeMemory();
|
2018-11-29 23:14:42 +00:00
|
|
|
builder.SetDataSegmentCount(1);
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.v_v(),
|
2019-07-11 16:56:29 +00:00
|
|
|
{WASM_TABLE_INIT(0, 1, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 23:32:46 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MemoryInitInvalid) {
|
|
|
|
builder.InitializeMemory();
|
2018-11-29 23:14:42 +00:00
|
|
|
builder.SetDataSegmentCount(1);
|
2018-11-27 23:32:46 +00:00
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
|
|
|
byte code[] = {WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO),
|
|
|
|
WASM_END};
|
|
|
|
for (size_t i = 0; i <= arraysize(code); ++i) {
|
2019-02-08 10:10:45 +00:00
|
|
|
Validate(i == arraysize(code), sigs.v_v(), VectorOf(code, i), kOmitEnd);
|
2018-11-27 23:32:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 18:45:51 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, DataDrop) {
|
2018-11-29 23:14:42 +00:00
|
|
|
builder.InitializeMemory();
|
|
|
|
builder.SetDataSegmentCount(1);
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_DATA_DROP(0)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_DATA_DROP(0)});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_DATA_DROP(1)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 22:37:02 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, DataSegmentIndexUnsigned) {
|
|
|
|
builder.InitializeMemory();
|
|
|
|
builder.SetDataSegmentCount(65);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
|
|
|
// Make sure that the index is interpreted as an unsigned number; 64 is
|
|
|
|
// interpreted as -64 when decoded as a signed LEB.
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_INIT(64, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_DATA_DROP(64)});
|
|
|
|
}
|
|
|
|
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, MemoryCopy) {
|
|
|
|
builder.InitializeMemory();
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, MemoryFill) {
|
|
|
|
builder.InitializeMemory();
|
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, BulkMemoryOpsWithoutMemory) {
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_INIT(0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_COPY(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_MEMORY_FILL(WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, TableInit) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmFuncRef);
|
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
2019-07-11 16:56:29 +00:00
|
|
|
{WASM_TABLE_INIT(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
2019-07-11 16:56:29 +00:00
|
|
|
{WASM_TABLE_INIT(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
2019-07-11 16:56:29 +00:00
|
|
|
{WASM_TABLE_INIT(0, 1, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 17:37:42 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableInitWrongType) {
|
|
|
|
uint32_t table_index = builder.InitializeTable(wasm::kWasmFuncRef);
|
2020-06-09 15:54:14 +00:00
|
|
|
uint32_t element_index =
|
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmExternRef);
|
2020-02-25 17:37:42 +00:00
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-25 17:37:42 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TABLE_INIT(table_index, element_index,
|
|
|
|
WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
}
|
|
|
|
|
2018-11-27 23:32:46 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableInitInvalid) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmFuncRef);
|
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
2018-11-27 23:32:46 +00:00
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-07-11 16:56:29 +00:00
|
|
|
byte code[] = {WASM_TABLE_INIT(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO),
|
|
|
|
WASM_END};
|
2018-11-27 23:32:46 +00:00
|
|
|
for (size_t i = 0; i <= arraysize(code); ++i) {
|
2019-02-08 10:10:45 +00:00
|
|
|
Validate(i == arraysize(code), sigs.v_v(), VectorOf(code, i), kOmitEnd);
|
2018-11-27 23:32:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 18:45:51 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ElemDrop) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmFuncRef);
|
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(0)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_ELEM_DROP(0)});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(1)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 16:21:02 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableInitDeclarativeElem) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmFuncRef);
|
2020-02-17 16:21:02 +00:00
|
|
|
builder.AddDeclarativeElementSegment();
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-17 16:21:02 +00:00
|
|
|
byte code[] = {WASM_TABLE_INIT(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO),
|
|
|
|
WASM_END};
|
|
|
|
for (size_t i = 0; i <= arraysize(code); ++i) {
|
|
|
|
Validate(i == arraysize(code), sigs.v_v(), VectorOf(code, i), kOmitEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, DeclarativeElemDrop) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmFuncRef);
|
2020-02-17 16:21:02 +00:00
|
|
|
builder.AddDeclarativeElementSegment();
|
|
|
|
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(0)});
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-17 16:21:02 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_ELEM_DROP(0)});
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_ELEM_DROP(1)});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, RefFuncDeclared) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2020-02-17 16:21:02 +00:00
|
|
|
byte function_index = builder.AddFunction(sigs.v_i());
|
|
|
|
|
|
|
|
ExpectFailure(sigs.a_v(), {WASM_REF_FUNC(function_index)});
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-17 16:21:02 +00:00
|
|
|
ExpectValidates(sigs.a_v(), {WASM_REF_FUNC(function_index)});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, RefFuncUndeclared) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
2020-02-17 16:21:02 +00:00
|
|
|
byte function_index = builder.AddFunction(sigs.v_i(), false);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-17 16:21:02 +00:00
|
|
|
ExpectFailure(sigs.a_v(), {WASM_REF_FUNC(function_index)});
|
|
|
|
}
|
|
|
|
|
2020-01-22 22:37:02 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, ElemSegmentIndexUnsigned) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmFuncRef);
|
2020-01-22 22:37:02 +00:00
|
|
|
for (int i = 0; i < 65; ++i) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
2020-01-22 22:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
|
|
|
// Make sure that the index is interpreted as an unsigned number; 64 is
|
|
|
|
// interpreted as -64 when decoded as a signed LEB.
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_TABLE_INIT(0, 64, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_ELEM_DROP(64)});
|
|
|
|
}
|
|
|
|
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableCopy) {
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.InitializeTable(wasm::kWasmStmt);
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
|
2019-07-11 16:59:34 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_TABLE_COPY(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2019-02-08 10:10:45 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
2019-07-11 16:59:34 +00:00
|
|
|
{WASM_TABLE_COPY(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 17:37:42 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableCopyWrongType) {
|
|
|
|
uint32_t dst_table_index = builder.InitializeTable(wasm::kWasmFuncRef);
|
2020-06-09 15:54:14 +00:00
|
|
|
uint32_t src_table_index = builder.InitializeTable(wasm::kWasmExternRef);
|
2020-02-25 17:37:42 +00:00
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-25 17:37:42 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TABLE_COPY(dst_table_index, src_table_index,
|
|
|
|
WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
}
|
|
|
|
|
2019-05-03 08:06:10 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableGrow) {
|
2019-07-08 20:23:30 +00:00
|
|
|
byte tab_func = builder.AddTable(kWasmFuncRef, 10, true, 20);
|
2020-06-09 15:54:14 +00:00
|
|
|
byte tab_ref = builder.AddTable(kWasmExternRef, 10, true, 20);
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
|
2020-06-03 12:48:16 +00:00
|
|
|
ExpectFailure(
|
2020-06-19 03:50:08 +00:00
|
|
|
sigs.i_c(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_TABLE_GROW(tab_func, WASM_REF_NULL(kFuncRefCode), WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-06-03 12:48:16 +00:00
|
|
|
ExpectValidates(
|
2020-06-19 03:50:08 +00:00
|
|
|
sigs.i_c(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_TABLE_GROW(tab_func, WASM_REF_NULL(kFuncRefCode), WASM_ONE)});
|
2020-06-03 12:48:16 +00:00
|
|
|
ExpectValidates(
|
2020-06-19 03:50:08 +00:00
|
|
|
sigs.i_e(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_TABLE_GROW(tab_ref, WASM_REF_NULL(kExternRefCode), WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
// FuncRef table cannot be initialized with an ExternRef value.
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.i_e(),
|
2019-05-03 08:06:10 +00:00
|
|
|
{WASM_TABLE_GROW(tab_func, WASM_GET_LOCAL(0), WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
// ExternRef table cannot be initialized with a FuncRef value.
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.i_c(),
|
2020-05-29 15:23:27 +00:00
|
|
|
{WASM_TABLE_GROW(tab_ref, WASM_GET_LOCAL(0), WASM_ONE)});
|
2019-05-03 08:06:10 +00:00
|
|
|
// Check that the table index gets verified.
|
2020-06-03 12:48:16 +00:00
|
|
|
ExpectFailure(
|
2020-06-19 03:50:08 +00:00
|
|
|
sigs.i_e(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_TABLE_GROW(tab_ref + 2, WASM_REF_NULL(kExternRefCode), WASM_ONE)});
|
2019-05-03 08:06:10 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:12:32 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableSize) {
|
2019-07-08 20:23:30 +00:00
|
|
|
int tab = builder.AddTable(kWasmFuncRef, 10, true, 20);
|
2019-05-03 08:12:32 +00:00
|
|
|
|
|
|
|
ExpectFailure(sigs.i_v(), {WASM_TABLE_SIZE(tab)});
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-05-03 08:12:32 +00:00
|
|
|
ExpectValidates(sigs.i_v(), {WASM_TABLE_SIZE(tab)});
|
|
|
|
ExpectFailure(sigs.i_v(), {WASM_TABLE_SIZE(tab + 2)});
|
|
|
|
}
|
|
|
|
|
2019-05-07 11:00:04 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableFill) {
|
2019-07-08 20:23:30 +00:00
|
|
|
byte tab_func = builder.AddTable(kWasmFuncRef, 10, true, 20);
|
2020-06-09 15:54:14 +00:00
|
|
|
byte tab_ref = builder.AddTable(kWasmExternRef, 10, true, 20);
|
2019-05-07 11:00:04 +00:00
|
|
|
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.v_c(),
|
2020-06-03 12:48:16 +00:00
|
|
|
{WASM_TABLE_FILL(tab_func, WASM_ONE,
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_REF_NULL(kFuncRefCode), WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectValidates(sigs.v_c(),
|
2020-06-03 12:48:16 +00:00
|
|
|
{WASM_TABLE_FILL(tab_func, WASM_ONE,
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_REF_NULL(kFuncRefCode), WASM_ONE)});
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectValidates(sigs.v_e(),
|
2020-06-03 12:48:16 +00:00
|
|
|
{WASM_TABLE_FILL(tab_ref, WASM_ONE,
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_REF_NULL(kExternRefCode), WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
// FuncRef table cannot be initialized with an ExternRef value.
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.v_e(), {WASM_TABLE_FILL(tab_func, WASM_ONE,
|
2019-05-07 11:00:04 +00:00
|
|
|
WASM_GET_LOCAL(0), WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
// ExternRef table cannot be initialized with a FuncRef value.
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.v_c(), {WASM_TABLE_FILL(tab_ref, WASM_ONE,
|
2020-05-29 15:23:27 +00:00
|
|
|
WASM_GET_LOCAL(0), WASM_ONE)});
|
2019-05-07 11:00:04 +00:00
|
|
|
// Check that the table index gets verified.
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.v_e(),
|
2020-06-03 12:48:16 +00:00
|
|
|
{WASM_TABLE_FILL(tab_ref + 2, WASM_ONE,
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_REF_NULL(kExternRefCode), WASM_ONE)});
|
2019-05-07 11:00:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 08:06:10 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableOpsWithoutTable) {
|
|
|
|
{
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectFailure(sigs.i_v(), {WASM_TABLE_GROW(0, WASM_REF_NULL(kExternRefCode),
|
|
|
|
WASM_ONE)});
|
2020-06-09 15:54:14 +00:00
|
|
|
ExpectFailure(sigs.i_v(), {WASM_TABLE_SIZE(0)});
|
2020-06-19 03:50:08 +00:00
|
|
|
ExpectFailure(sigs.i_e(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_TABLE_FILL(0, WASM_ONE, WASM_REF_NULL(kExternRefCode),
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_ONE)});
|
2019-05-03 08:06:10 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
2019-05-03 08:06:10 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
2019-07-11 16:56:29 +00:00
|
|
|
{WASM_TABLE_INIT(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
2019-05-03 08:06:10 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
2019-07-11 16:59:34 +00:00
|
|
|
{WASM_TABLE_COPY(0, 0, WASM_ZERO, WASM_ZERO, WASM_ZERO)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, TableCopyMultiTable) {
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-07-11 16:59:34 +00:00
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
2020-06-09 15:54:14 +00:00
|
|
|
builder.AddTable(kWasmExternRef, 10, true, 20);
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
2019-07-11 16:59:34 +00:00
|
|
|
module = builder.module();
|
|
|
|
// We added one table, therefore table.copy on table 0 should work.
|
|
|
|
int table_src = 0;
|
|
|
|
int table_dst = 0;
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_TABLE_COPY(table_dst, table_src, WASM_ZERO, WASM_ZERO,
|
|
|
|
WASM_ZERO)});
|
|
|
|
// There is only one table, so table.copy on table 1 should fail.
|
|
|
|
table_src = 0;
|
|
|
|
table_dst = 1;
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TABLE_COPY(table_dst, table_src, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
|
|
|
table_src = 1;
|
|
|
|
table_dst = 0;
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TABLE_COPY(table_dst, table_src, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
2020-06-09 15:54:14 +00:00
|
|
|
builder.AddTable(kWasmExternRef, 10, true, 20);
|
|
|
|
builder.AddTable(kWasmExternRef, 10, true, 20);
|
2020-02-25 17:37:42 +00:00
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmFuncRef);
|
2019-07-11 16:59:34 +00:00
|
|
|
module = builder.module();
|
|
|
|
// We added two tables, therefore table.copy on table 0 should work.
|
|
|
|
int table_src = 0;
|
|
|
|
int table_dst = 0;
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_TABLE_COPY(table_dst, table_src, WASM_ZERO, WASM_ZERO,
|
|
|
|
WASM_ZERO)});
|
|
|
|
// Also table.copy on table 1 should work now.
|
|
|
|
table_src = 1;
|
|
|
|
table_dst = 0;
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_TABLE_COPY(table_dst, table_src, WASM_ZERO, WASM_ZERO,
|
|
|
|
WASM_ZERO)});
|
|
|
|
table_src = 0;
|
|
|
|
table_dst = 1;
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_TABLE_COPY(table_dst, table_src, WASM_ZERO, WASM_ZERO,
|
|
|
|
WASM_ZERO)});
|
2019-05-03 08:06:10 +00:00
|
|
|
}
|
[wasm] Decode bulk memory instructions
These instructions aren't implemented yet in TF or in Liftoff, but they
are properly decoded.
The table instructions (i.e. `table.{init,drop,copy}`) are validated,
since the table and element sections occur before the code section. The
memory instructions (i.e. `memory.{init,drop,copy,fill}`) are not
validated because the data section occurs after the code section, so it
can't be verified in one pass (without throwing a validation error
later).
There is currently a discussion about whether to add a new section
(similar to `func`) that predefines the number of expected data
segments. If we add this, then we can validate in one pass. For now,
we'll leave it unimplemented.
Bug: v8:7747
Change-Id: I839edf51721105a47a1fa8dd5e5e1bd855e72447
Reviewed-on: https://chromium-review.googlesource.com/c/1339241
Commit-Queue: Ben Smith <binji@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57622}
2018-11-19 19:30:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 16:56:29 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, TableInitMultiTable) {
|
|
|
|
WASM_FEATURE_SCOPE(bulk_memory);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-07-11 16:56:29 +00:00
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
2020-06-09 15:54:14 +00:00
|
|
|
builder.AddTable(kWasmExternRef, 10, true, 20);
|
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmExternRef);
|
2019-07-11 16:56:29 +00:00
|
|
|
module = builder.module();
|
|
|
|
// We added one table, therefore table.init on table 0 should work.
|
|
|
|
int table_index = 0;
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TABLE_INIT(table_index, 0, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
|
|
|
// There is only one table, so table.init on table 1 should fail.
|
|
|
|
table_index = 1;
|
|
|
|
ExpectFailure(sigs.v_v(), {WASM_TABLE_INIT(table_index, 0, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
2020-06-09 15:54:14 +00:00
|
|
|
builder.AddTable(kWasmExternRef, 10, true, 20);
|
|
|
|
builder.AddTable(kWasmExternRef, 10, true, 20);
|
|
|
|
builder.AddPassiveElementSegment(wasm::kWasmExternRef);
|
2019-07-11 16:56:29 +00:00
|
|
|
module = builder.module();
|
|
|
|
// We added two tables, therefore table.init on table 0 should work.
|
|
|
|
int table_index = 0;
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TABLE_INIT(table_index, 0, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
|
|
|
// Also table.init on table 1 should work now.
|
|
|
|
table_index = 1;
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_TABLE_INIT(table_index, 0, WASM_ZERO,
|
|
|
|
WASM_ZERO, WASM_ZERO)});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 08:45:56 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, UnpackPackedTypes) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-07-21 09:03:20 +00:00
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
2020-06-05 08:45:56 +00:00
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
byte type_index = builder.AddStruct({F(kWasmI8, true), F(kWasmI16, false)});
|
|
|
|
module = builder.module();
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectValidates(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_STRUCT_SET(
|
|
|
|
type_index, 0,
|
|
|
|
WASM_STRUCT_NEW_WITH_RTT(type_index, WASM_I32V(1), WASM_I32V(42),
|
|
|
|
WASM_RTT_CANON(type_index)),
|
|
|
|
WASM_I32V(-1))});
|
2020-06-05 08:45:56 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
byte type_index = builder.AddArray(kWasmI8, true);
|
|
|
|
module = builder.module();
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_ARRAY_SET(type_index,
|
|
|
|
WASM_ARRAY_NEW_WITH_RTT(
|
|
|
|
type_index, WASM_I32V(10), WASM_I32V(5),
|
|
|
|
WASM_RTT_CANON(type_index)),
|
|
|
|
WASM_I32V(3), WASM_I32V(12345678))});
|
2020-06-05 08:45:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-04 10:35:16 +00:00
|
|
|
ValueType ref(byte type_index) {
|
|
|
|
return ValueType::Ref(type_index, kNonNullable);
|
|
|
|
}
|
|
|
|
ValueType optref(byte type_index) {
|
|
|
|
return ValueType::Ref(type_index, kNullable);
|
|
|
|
}
|
|
|
|
|
2020-08-07 13:14:23 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, StructNewDefault) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
byte type_index = builder.AddStruct({F(kWasmI32, true)});
|
|
|
|
byte bad_type_index = builder.AddStruct({F(ref(type_index), true)});
|
|
|
|
module = builder.module();
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_STRUCT_NEW_DEFAULT(
|
|
|
|
type_index, WASM_RTT_CANON(type_index)),
|
|
|
|
WASM_DROP});
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_STRUCT_NEW_DEFAULT(bad_type_index,
|
|
|
|
WASM_RTT_CANON(bad_type_index)),
|
|
|
|
WASM_DROP});
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
byte type_index = builder.AddArray(kWasmI32, true);
|
|
|
|
byte bad_type_index = builder.AddArray(ref(type_index), true);
|
|
|
|
module = builder.module();
|
|
|
|
ExpectValidates(sigs.v_v(),
|
|
|
|
{WASM_ARRAY_NEW_DEFAULT(type_index, WASM_I32V(3),
|
|
|
|
WASM_RTT_CANON(type_index)),
|
|
|
|
WASM_DROP});
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_ARRAY_NEW_DEFAULT(bad_type_index, WASM_I32V(3),
|
|
|
|
WASM_RTT_CANON(bad_type_index)),
|
|
|
|
WASM_DROP});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 04:41:33 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, DefaultableLocal) {
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
AddLocals(kWasmExternRef, 1);
|
|
|
|
ExpectValidates(sigs.v_v(), {});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, NonDefaultableLocal) {
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
AddLocals(ValueType::Ref(HeapType::kExtern, kNonNullable), 1);
|
2020-09-23 08:01:45 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {}, kAppendEnd,
|
|
|
|
"Cannot define function-level local of non-defaultable type");
|
2020-07-06 04:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, RefEq) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(simd);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
|
2020-07-16 12:20:56 +00:00
|
|
|
ValueType eqref_subtypes[] = {kWasmEqRef,
|
2020-07-06 04:41:33 +00:00
|
|
|
kWasmI31Ref,
|
|
|
|
ValueType::Ref(HeapType::kEq, kNonNullable),
|
|
|
|
ValueType::Ref(HeapType::kI31, kNullable),
|
|
|
|
ref(struct_type_index),
|
|
|
|
optref(struct_type_index)};
|
|
|
|
ValueType non_eqref_subtypes[] = {
|
|
|
|
kWasmI32,
|
|
|
|
kWasmI64,
|
|
|
|
kWasmF32,
|
|
|
|
kWasmF64,
|
|
|
|
kWasmS128,
|
2020-07-16 12:20:56 +00:00
|
|
|
kWasmExnRef,
|
|
|
|
kWasmExternRef,
|
2020-07-06 04:41:33 +00:00
|
|
|
kWasmFuncRef,
|
2020-11-19 14:51:14 +00:00
|
|
|
kWasmAnyRef,
|
2020-07-16 12:20:56 +00:00
|
|
|
ValueType::Ref(HeapType::kExn, kNonNullable),
|
|
|
|
ValueType::Ref(HeapType::kExtern, kNonNullable),
|
2020-07-06 04:41:33 +00:00
|
|
|
ValueType::Ref(HeapType::kFunc, kNonNullable)};
|
|
|
|
|
|
|
|
for (ValueType type1 : eqref_subtypes) {
|
|
|
|
for (ValueType type2 : eqref_subtypes) {
|
|
|
|
ValueType reps[] = {kWasmI32, type1, type2};
|
|
|
|
FunctionSig sig(1, 2, reps);
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_REF_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ValueType type1 : eqref_subtypes) {
|
|
|
|
for (ValueType type2 : non_eqref_subtypes) {
|
|
|
|
ValueType reps[] = {kWasmI32, type1, type2};
|
|
|
|
FunctionSig sig(1, 2, reps);
|
|
|
|
ExpectFailure(&sig, {WASM_REF_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))},
|
|
|
|
kAppendEnd, "expected type eqref, found local.get of type");
|
|
|
|
ExpectFailure(&sig, {WASM_REF_EQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd, "expected type eqref, found local.get of type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-04 10:35:16 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, RefAsNonNull) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(simd);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
|
|
|
|
byte array_type_index = builder.AddArray(kWasmI32, true);
|
|
|
|
uint32_t heap_types[] = {
|
|
|
|
struct_type_index, array_type_index, HeapType::kExn, HeapType::kFunc,
|
2020-11-19 14:51:14 +00:00
|
|
|
HeapType::kEq, HeapType::kExtern, HeapType::kI31, HeapType::kAny};
|
2020-07-04 10:35:16 +00:00
|
|
|
|
|
|
|
ValueType non_compatible_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
|
|
|
|
kWasmS128};
|
|
|
|
|
|
|
|
// It works with nullable types.
|
|
|
|
for (uint32_t heap_type : heap_types) {
|
|
|
|
ValueType reprs[] = {ValueType::Ref(heap_type, kNonNullable),
|
|
|
|
ValueType::Ref(heap_type, kNullable)};
|
|
|
|
FunctionSig sig(1, 1, reprs);
|
|
|
|
ExpectValidates(&sig, {WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0))});
|
|
|
|
}
|
|
|
|
|
|
|
|
// It works with non-nullable types.
|
|
|
|
for (uint32_t heap_type : heap_types) {
|
|
|
|
ValueType reprs[] = {ValueType::Ref(heap_type, kNonNullable),
|
|
|
|
ValueType::Ref(heap_type, kNonNullable)};
|
|
|
|
FunctionSig sig(1, 1, reprs);
|
|
|
|
ExpectValidates(&sig, {WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0))});
|
|
|
|
}
|
|
|
|
|
|
|
|
// It fails with other types.
|
|
|
|
for (ValueType type : non_compatible_types) {
|
|
|
|
FunctionSig sig(0, 1, &type);
|
|
|
|
ExpectFailure(
|
|
|
|
&sig, {WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)), kExprDrop}, kAppendEnd,
|
|
|
|
"invalid agrument type to ref.as_non_null: Expected reference type, "
|
|
|
|
"got");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, RefNull) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
|
|
|
|
byte array_type_index = builder.AddArray(kWasmI32, true);
|
|
|
|
uint32_t type_reprs[] = {
|
|
|
|
struct_type_index, array_type_index, HeapType::kExn, HeapType::kFunc,
|
2020-11-19 14:51:14 +00:00
|
|
|
HeapType::kEq, HeapType::kExtern, HeapType::kI31, HeapType::kAny};
|
2020-07-04 10:35:16 +00:00
|
|
|
// It works with heap types.
|
|
|
|
for (uint32_t type_repr : type_reprs) {
|
|
|
|
const ValueType type = ValueType::Ref(type_repr, kNullable);
|
|
|
|
const FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectValidates(&sig, {WASM_REF_NULL(WASM_HEAP_TYPE(HeapType(type_repr)))});
|
|
|
|
}
|
|
|
|
// It fails for undeclared types.
|
2020-08-05 11:12:29 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {WASM_REF_NULL(42), kExprDrop}, kAppendEnd,
|
|
|
|
"Type index 42 is out of bounds");
|
2020-07-04 10:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, RefIsNull) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
ExpectValidates(sigs.i_i(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_REF_IS_NULL(WASM_REF_NULL(kExternRefCode))});
|
2020-07-04 10:35:16 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.i_i(), {WASM_REF_IS_NULL(WASM_GET_LOCAL(0))}, kAppendEnd,
|
|
|
|
"invalid argument type to ref.is_null. Expected reference type, got i32");
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
|
|
|
|
byte array_type_index = builder.AddArray(kWasmI32, true);
|
|
|
|
uint32_t heap_types[] = {
|
|
|
|
struct_type_index, array_type_index, HeapType::kExn, HeapType::kFunc,
|
2020-11-19 14:51:14 +00:00
|
|
|
HeapType::kEq, HeapType::kExtern, HeapType::kI31, HeapType::kAny};
|
2020-07-04 10:35:16 +00:00
|
|
|
|
|
|
|
for (uint32_t heap_type : heap_types) {
|
|
|
|
const ValueType types[] = {kWasmI32, ValueType::Ref(heap_type, kNullable)};
|
|
|
|
const FunctionSig sig(1, 1, types);
|
|
|
|
// It works for nullable references.
|
|
|
|
ExpectValidates(&sig, {WASM_REF_IS_NULL(WASM_GET_LOCAL(0))});
|
|
|
|
// It works for non-nullable references.
|
|
|
|
ExpectValidates(
|
|
|
|
&sig, {WASM_REF_IS_NULL(WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)))});
|
|
|
|
}
|
|
|
|
|
|
|
|
// It fails if the argument type is not a reference type.
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(), {WASM_REF_IS_NULL(WASM_I32V(0)), kExprDrop}, kAppendEnd,
|
|
|
|
"invalid argument type to ref.is_null. Expected reference type, got ");
|
|
|
|
}
|
|
|
|
|
2020-07-06 04:41:33 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, BrOnNull) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
const ValueType reps[] = {ValueType::Ref(HeapType::kFunc, kNonNullable),
|
|
|
|
ValueType::Ref(HeapType::kFunc, kNullable)};
|
|
|
|
const FunctionSig sig(1, 1, reps);
|
|
|
|
ExpectValidates(
|
|
|
|
&sig, {WASM_BLOCK_R(reps[0], WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)),
|
|
|
|
WASM_BR_ON_NULL(0, WASM_GET_LOCAL(0)), WASM_I32V(0),
|
|
|
|
kExprSelectWithType, 1, WASM_REF_TYPE(reps[0]))});
|
|
|
|
|
|
|
|
// Should have block return value on stack before calling br_on_null.
|
|
|
|
ExpectFailure(&sig,
|
|
|
|
{WASM_BLOCK_R(reps[0], WASM_BR_ON_NULL(0, WASM_GET_LOCAL(0)),
|
|
|
|
WASM_I32V(0), kExprSelectWithType, 1,
|
|
|
|
WASM_REF_TYPE(reps[0]))},
|
|
|
|
kAppendEnd,
|
|
|
|
"expected 1 elements on the stack for br to @1, found 0");
|
|
|
|
}
|
|
|
|
|
2020-07-06 10:55:46 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GCStruct) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI32, true)});
|
|
|
|
byte array_type_index = builder.AddArray(kWasmI32, true);
|
|
|
|
byte immutable_struct_type_index = builder.AddStruct({F(kWasmI32, false)});
|
|
|
|
byte field_index = 0;
|
|
|
|
|
|
|
|
ValueType struct_type = ValueType::Ref(struct_type_index, kNonNullable);
|
|
|
|
ValueType reps_i_r[] = {kWasmI32, struct_type};
|
|
|
|
ValueType reps_f_r[] = {kWasmF32, struct_type};
|
|
|
|
const FunctionSig sig_i_r(1, 1, reps_i_r);
|
|
|
|
const FunctionSig sig_v_r(0, 1, &struct_type);
|
|
|
|
const FunctionSig sig_r_v(1, 0, &struct_type);
|
|
|
|
const FunctionSig sig_f_r(1, 1, reps_f_r);
|
|
|
|
|
2020-07-21 09:03:20 +00:00
|
|
|
/** struct.new_with_rtt **/
|
|
|
|
ExpectValidates(
|
|
|
|
&sig_r_v, {WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0),
|
|
|
|
WASM_RTT_CANON(struct_type_index))});
|
2020-07-06 10:55:46 +00:00
|
|
|
// Too few arguments.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectFailure(&sig_r_v,
|
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index,
|
|
|
|
WASM_RTT_CANON(struct_type_index))},
|
|
|
|
kAppendEnd,
|
|
|
|
"not enough arguments on the stack for struct.new_with_rtt, "
|
|
|
|
"expected 1 more");
|
2020-07-06 10:55:46 +00:00
|
|
|
// Too many arguments.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_r_v,
|
2020-07-21 09:03:20 +00:00
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0), WASM_I32V(1),
|
|
|
|
WASM_RTT_CANON(struct_type_index))},
|
2020-07-06 10:55:46 +00:00
|
|
|
kAppendEnd,
|
|
|
|
"expected 1 elements on the stack for fallthru to @1, found 2");
|
|
|
|
// Mistyped arguments.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectFailure(&sig_v_r,
|
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_GET_LOCAL(0),
|
|
|
|
WASM_RTT_CANON(struct_type_index))},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.new_with_rtt[0] expected type i32, found local.get of "
|
|
|
|
"type (ref 0)");
|
2020-07-06 10:55:46 +00:00
|
|
|
// Wrongly typed index.
|
|
|
|
ExpectFailure(sigs.v_v(),
|
2020-07-21 09:03:20 +00:00
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(array_type_index, WASM_I32V(0),
|
|
|
|
WASM_RTT_CANON(struct_type_index)),
|
|
|
|
kExprDrop},
|
2020-07-06 10:55:46 +00:00
|
|
|
kAppendEnd, "invalid struct index: 1");
|
2020-07-21 09:03:20 +00:00
|
|
|
// Wrongly typed rtt.
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0),
|
|
|
|
WASM_RTT_CANON(array_type_index)),
|
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.new_with_rtt expected rtt for type 0, found rtt for type 1");
|
2020-07-06 10:55:46 +00:00
|
|
|
// Out-of-bounds index.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(42, WASM_I32V(0),
|
|
|
|
WASM_RTT_CANON(struct_type_index)),
|
|
|
|
kExprDrop},
|
2020-07-06 10:55:46 +00:00
|
|
|
kAppendEnd, "invalid struct index: 42");
|
|
|
|
|
|
|
|
/** struct.get **/
|
|
|
|
ExpectValidates(&sig_i_r, {WASM_STRUCT_GET(struct_type_index, field_index,
|
|
|
|
WASM_GET_LOCAL(0))});
|
|
|
|
// With non-nullable struct.
|
|
|
|
ExpectValidates(&sig_i_r,
|
|
|
|
{WASM_STRUCT_GET(struct_type_index, field_index,
|
|
|
|
WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)))});
|
|
|
|
// Wrong index.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_v_r,
|
|
|
|
{WASM_STRUCT_GET(struct_type_index, field_index + 1, WASM_GET_LOCAL(0)),
|
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd, "invalid field index: 1");
|
|
|
|
// Mistyped expected type.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_f_r,
|
|
|
|
{WASM_STRUCT_GET(struct_type_index, field_index, WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd, "type error in merge[0] (expected f32, got i32)");
|
|
|
|
|
|
|
|
/** struct.set **/
|
|
|
|
ExpectValidates(&sig_v_r, {WASM_STRUCT_SET(struct_type_index, field_index,
|
|
|
|
WASM_GET_LOCAL(0), WASM_I32V(0))});
|
|
|
|
// Non-nullable struct.
|
|
|
|
ExpectValidates(
|
|
|
|
&sig_v_r,
|
|
|
|
{WASM_STRUCT_SET(struct_type_index, field_index,
|
|
|
|
WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)), WASM_I32V(0))});
|
|
|
|
// Wrong index.
|
|
|
|
ExpectFailure(&sig_v_r,
|
|
|
|
{WASM_STRUCT_SET(struct_type_index, field_index + 1,
|
|
|
|
WASM_GET_LOCAL(0), WASM_I32V(0))},
|
|
|
|
kAppendEnd, "invalid field index: 1");
|
|
|
|
// Mistyped input.
|
|
|
|
ExpectFailure(&sig_v_r,
|
|
|
|
{WASM_STRUCT_SET(struct_type_index, field_index,
|
|
|
|
WASM_GET_LOCAL(0), WASM_I64V(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.set[1] expected type i32, found i64.const of type i64");
|
|
|
|
// Expecting output.
|
|
|
|
ExpectFailure(&sig_i_r,
|
|
|
|
{WASM_STRUCT_SET(struct_type_index, field_index,
|
|
|
|
WASM_GET_LOCAL(0), WASM_I32V(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"expected 1 elements on the stack for fallthru to @1, found 0");
|
|
|
|
// Setting immutable field.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_STRUCT_SET(
|
|
|
|
immutable_struct_type_index, field_index,
|
|
|
|
WASM_STRUCT_NEW_WITH_RTT(immutable_struct_type_index, WASM_I32V(42),
|
|
|
|
WASM_RTT_CANON(immutable_struct_type_index)),
|
|
|
|
WASM_I32V(0))},
|
|
|
|
kAppendEnd, "setting immutable struct field");
|
2020-07-06 10:55:46 +00:00
|
|
|
|
|
|
|
// struct.get_s/u fail
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_i_r,
|
|
|
|
{WASM_STRUCT_GET_S(struct_type_index, field_index, WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.get_s is only valid for packed struct fields. Use struct.get "
|
|
|
|
"instead.");
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_i_r,
|
|
|
|
{WASM_STRUCT_GET_U(struct_type_index, field_index, WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.get_u is only valid for packed struct fields. Use struct.get "
|
|
|
|
"instead.");
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:03:20 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, GCArray) {
|
2020-07-06 13:39:30 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte array_type_index = builder.AddArray(kWasmFuncRef, true);
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI32, false)});
|
|
|
|
|
|
|
|
ValueType array_type = ValueType::Ref(array_type_index, kNonNullable);
|
|
|
|
ValueType reps_c_r[] = {kWasmFuncRef, array_type};
|
|
|
|
ValueType reps_f_r[] = {kWasmF32, array_type};
|
|
|
|
ValueType reps_i_r[] = {kWasmI32, array_type};
|
|
|
|
const FunctionSig sig_c_r(1, 1, reps_c_r);
|
|
|
|
const FunctionSig sig_v_r(0, 1, &array_type);
|
|
|
|
const FunctionSig sig_r_v(1, 0, &array_type);
|
|
|
|
const FunctionSig sig_f_r(1, 1, reps_f_r);
|
|
|
|
const FunctionSig sig_v_cr(0, 2, reps_c_r);
|
|
|
|
const FunctionSig sig_i_r(1, 1, reps_i_r);
|
|
|
|
|
2020-07-21 09:03:20 +00:00
|
|
|
/** array.new_with_rtt **/
|
|
|
|
ExpectValidates(&sig_r_v,
|
|
|
|
{WASM_ARRAY_NEW_WITH_RTT(
|
2020-09-29 07:46:36 +00:00
|
|
|
array_type_index, WASM_REF_NULL(kFuncRefCode),
|
2020-07-21 09:03:20 +00:00
|
|
|
WASM_I32V(10), WASM_RTT_CANON(array_type_index))});
|
2020-07-06 13:39:30 +00:00
|
|
|
// Too few arguments.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectFailure(&sig_r_v,
|
|
|
|
{WASM_I32V(10), WASM_RTT_CANON(array_type_index),
|
|
|
|
WASM_GC_OP(kExprArrayNewWithRtt), array_type_index},
|
|
|
|
kAppendEnd,
|
|
|
|
"not enough arguments on the stack for array.new_with_rtt, "
|
|
|
|
"expected 1 more");
|
|
|
|
// Mistyped initializer.
|
|
|
|
ExpectFailure(&sig_r_v,
|
|
|
|
{WASM_ARRAY_NEW_WITH_RTT(
|
2020-09-29 07:46:36 +00:00
|
|
|
array_type_index, WASM_REF_NULL(kExternRefCode),
|
2020-07-21 09:03:20 +00:00
|
|
|
WASM_I32V(10), WASM_RTT_CANON(array_type_index))},
|
|
|
|
kAppendEnd,
|
|
|
|
"array.new_with_rtt[0] expected type funcref, found ref.null "
|
|
|
|
"of type externref");
|
|
|
|
// Mistyped length.
|
2020-07-06 13:39:30 +00:00
|
|
|
ExpectFailure(
|
2020-07-21 09:03:20 +00:00
|
|
|
&sig_r_v,
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_ARRAY_NEW_WITH_RTT(array_type_index, WASM_REF_NULL(kFuncRefCode),
|
2020-07-21 09:03:20 +00:00
|
|
|
WASM_I64V(5), WASM_RTT_CANON(array_type_index))},
|
2020-07-06 13:39:30 +00:00
|
|
|
kAppendEnd,
|
2020-07-21 09:03:20 +00:00
|
|
|
"array.new_with_rtt[1] expected type i32, found i64.const of type i64");
|
|
|
|
// Mistyped rtt.
|
2020-07-06 13:39:30 +00:00
|
|
|
ExpectFailure(
|
|
|
|
&sig_r_v,
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_ARRAY_NEW_WITH_RTT(array_type_index, WASM_REF_NULL(kFuncRefCode),
|
2020-07-21 09:03:20 +00:00
|
|
|
WASM_I32V(5),
|
|
|
|
WASM_RTT_CANON(struct_type_index))},
|
2020-07-06 13:39:30 +00:00
|
|
|
kAppendEnd,
|
2020-07-21 09:03:20 +00:00
|
|
|
"array.new_with_rtt expected rtt for type 0, found rtt for type 1");
|
2020-07-06 13:39:30 +00:00
|
|
|
// Wrong type index.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_ARRAY_NEW_WITH_RTT(struct_type_index, WASM_REF_NULL(kFuncRefCode),
|
2020-07-21 09:03:20 +00:00
|
|
|
WASM_I32V(10), WASM_RTT_CANON(array_type_index)),
|
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd, "invalid array index: 1");
|
2020-07-06 13:39:30 +00:00
|
|
|
|
|
|
|
/** array.get **/
|
|
|
|
ExpectValidates(&sig_c_r, {WASM_ARRAY_GET(array_type_index, WASM_GET_LOCAL(0),
|
|
|
|
WASM_I32V(5))});
|
|
|
|
// With non-nullable array type.
|
|
|
|
ExpectValidates(
|
|
|
|
&sig_c_r,
|
|
|
|
{WASM_ARRAY_GET(array_type_index, WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)),
|
|
|
|
WASM_I32V(5))});
|
|
|
|
// Wrongly typed index.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_v_r,
|
|
|
|
{WASM_ARRAY_GET(array_type_index, WASM_GET_LOCAL(0), WASM_I64V(5)),
|
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd,
|
|
|
|
"array.get[1] expected type i32, found i64.const of type i64");
|
|
|
|
// Mistyped expected type.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_f_r,
|
|
|
|
{WASM_ARRAY_GET(array_type_index, WASM_GET_LOCAL(0), WASM_I32V(5))},
|
|
|
|
kAppendEnd, "type error in merge[0] (expected f32, got funcref)");
|
|
|
|
|
|
|
|
// array.get_s/u fail.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_c_r,
|
|
|
|
{WASM_ARRAY_GET_S(array_type_index, WASM_GET_LOCAL(0), WASM_I32V(5))},
|
|
|
|
kAppendEnd,
|
2020-07-07 04:01:50 +00:00
|
|
|
"array.get_s is only valid for packed arrays. Use array.get instead.");
|
2020-07-06 13:39:30 +00:00
|
|
|
ExpectFailure(
|
|
|
|
&sig_c_r,
|
|
|
|
{WASM_ARRAY_GET_U(array_type_index, WASM_GET_LOCAL(0), WASM_I32V(5))},
|
|
|
|
kAppendEnd,
|
2020-07-07 04:01:50 +00:00
|
|
|
"array.get_u is only valid for packed arrays. Use array.get instead.");
|
2020-07-06 13:39:30 +00:00
|
|
|
|
|
|
|
/** array.set **/
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectValidates(&sig_v_r,
|
|
|
|
{WASM_ARRAY_SET(array_type_index, WASM_GET_LOCAL(0),
|
|
|
|
WASM_I32V(42), WASM_REF_NULL(kFuncRefCode))});
|
2020-07-06 13:39:30 +00:00
|
|
|
// With non-nullable array type.
|
|
|
|
ExpectValidates(
|
|
|
|
&sig_v_cr,
|
|
|
|
{WASM_ARRAY_SET(array_type_index, WASM_GET_LOCAL(1), WASM_I32V(42),
|
|
|
|
WASM_REF_AS_NON_NULL(WASM_GET_LOCAL(0)))});
|
|
|
|
// Non-array type index.
|
|
|
|
ExpectFailure(&sig_v_cr,
|
|
|
|
{WASM_ARRAY_SET(struct_type_index, WASM_GET_LOCAL(1),
|
|
|
|
WASM_I32V(42), WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd, "invalid array index: 1");
|
|
|
|
// Wrongly typed index.
|
|
|
|
ExpectFailure(&sig_v_cr,
|
|
|
|
{WASM_ARRAY_SET(array_type_index, WASM_GET_LOCAL(1),
|
|
|
|
WASM_I64V(42), WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"array.set[1] expected type i32, found i64.const of type i64");
|
|
|
|
// Wrongly typed value.
|
|
|
|
ExpectFailure(
|
|
|
|
&sig_v_cr,
|
|
|
|
{WASM_ARRAY_SET(array_type_index, WASM_GET_LOCAL(1), WASM_I32V(42),
|
|
|
|
WASM_I64V(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"array.set[2] expected type funcref, found i64.const of type i64");
|
|
|
|
|
|
|
|
/** array.len **/
|
|
|
|
ExpectValidates(&sig_i_r,
|
|
|
|
{WASM_ARRAY_LEN(array_type_index, WASM_GET_LOCAL(0))});
|
|
|
|
// Wrong return type.
|
|
|
|
ExpectFailure(&sig_f_r, {WASM_ARRAY_LEN(array_type_index, WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd, "type error in merge[0] (expected f32, got i32)");
|
|
|
|
// Non-array type index.
|
|
|
|
ExpectFailure(&sig_i_r,
|
|
|
|
{WASM_ARRAY_LEN(struct_type_index, WASM_GET_LOCAL(0))},
|
|
|
|
kAppendEnd, "invalid array index: 1");
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:37:26 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, PackedFields) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
byte array_type_index = builder.AddArray(kWasmI8, true);
|
|
|
|
byte struct_type_index = builder.AddStruct({F(kWasmI16, true)});
|
|
|
|
byte field_index = 0;
|
|
|
|
|
|
|
|
// *.new with packed fields works.
|
2020-07-21 09:03:20 +00:00
|
|
|
ExpectValidates(sigs.v_v(), {WASM_ARRAY_NEW_WITH_RTT(
|
|
|
|
array_type_index, WASM_I32V(0), WASM_I32V(5),
|
|
|
|
WASM_RTT_CANON(array_type_index)),
|
|
|
|
kExprDrop});
|
2020-07-06 15:37:26 +00:00
|
|
|
ExpectValidates(sigs.v_v(),
|
2020-07-21 09:03:20 +00:00
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(42),
|
|
|
|
WASM_RTT_CANON(struct_type_index)),
|
2020-07-06 15:37:26 +00:00
|
|
|
kExprDrop});
|
|
|
|
// It can't unpack types other that i32.
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
2020-07-21 09:03:20 +00:00
|
|
|
{WASM_ARRAY_NEW_WITH_RTT(array_type_index, WASM_I64V(0), WASM_I32V(5),
|
|
|
|
WASM_RTT_CANON(array_type_index)),
|
|
|
|
kExprDrop},
|
2020-07-06 15:37:26 +00:00
|
|
|
kAppendEnd,
|
2020-07-21 09:03:20 +00:00
|
|
|
"array.new_with_rtt[0] expected type i32, found i64.const of type i64");
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I64V(42),
|
|
|
|
WASM_RTT_CANON(struct_type_index)),
|
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.new_with_rtt[0] expected type i32, found i64.const of type i64");
|
2020-07-06 15:37:26 +00:00
|
|
|
|
|
|
|
// *.set with packed fields works.
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_ARRAY_SET(array_type_index,
|
|
|
|
WASM_REF_NULL(array_type_index),
|
|
|
|
WASM_I32V(0), WASM_I32V(5))});
|
|
|
|
ExpectValidates(sigs.v_v(), {WASM_STRUCT_SET(struct_type_index, field_index,
|
|
|
|
WASM_REF_NULL(struct_type_index),
|
|
|
|
WASM_I32V(42))});
|
|
|
|
// It can't unpack into types other that i32.
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_ARRAY_SET(array_type_index, WASM_REF_NULL(array_type_index),
|
|
|
|
WASM_I32V(0), WASM_I64V(5))},
|
|
|
|
kAppendEnd,
|
|
|
|
"array.set[2] expected type i32, found i64.const of type i64");
|
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
2020-07-21 09:03:20 +00:00
|
|
|
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, field_index,
|
|
|
|
WASM_REF_NULL(struct_type_index), WASM_I64V(42),
|
|
|
|
WASM_RTT_CANON(struct_type_index))},
|
2020-07-06 15:37:26 +00:00
|
|
|
kAppendEnd,
|
2020-07-21 09:03:20 +00:00
|
|
|
"struct.new_with_rtt[0] expected type i32, found i64.const of type i64");
|
2020-07-06 15:37:26 +00:00
|
|
|
|
|
|
|
// *.get_s/u works.
|
|
|
|
ExpectValidates(sigs.i_v(), {WASM_ARRAY_GET_S(array_type_index,
|
|
|
|
WASM_REF_NULL(array_type_index),
|
|
|
|
WASM_I32V(0))});
|
|
|
|
ExpectValidates(sigs.i_v(), {WASM_ARRAY_GET_U(array_type_index,
|
|
|
|
WASM_REF_NULL(array_type_index),
|
|
|
|
WASM_I32V(0))});
|
|
|
|
ExpectValidates(sigs.i_v(),
|
|
|
|
{WASM_STRUCT_GET_S(struct_type_index, field_index,
|
|
|
|
WASM_REF_NULL(struct_type_index))});
|
|
|
|
ExpectValidates(sigs.i_v(),
|
|
|
|
{WASM_STRUCT_GET_U(struct_type_index, field_index,
|
|
|
|
WASM_REF_NULL(struct_type_index))});
|
|
|
|
|
|
|
|
// *.get fails.
|
|
|
|
ExpectFailure(sigs.i_v(),
|
|
|
|
{WASM_ARRAY_GET(array_type_index,
|
|
|
|
WASM_REF_NULL(array_type_index), WASM_I32V(0))},
|
|
|
|
kAppendEnd,
|
|
|
|
"array.get used with a field of packed type. Use array.get_s "
|
|
|
|
"or array.get_u instead.");
|
|
|
|
ExpectFailure(sigs.i_v(),
|
|
|
|
{WASM_STRUCT_GET(struct_type_index, field_index,
|
|
|
|
WASM_REF_NULL(struct_type_index))},
|
|
|
|
kAppendEnd,
|
|
|
|
"struct.get used with a field of packed type. Use struct.get_s "
|
|
|
|
"or struct.get_u instead.");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, PackedTypesAsLocals) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
AddLocals(kWasmI8, 1);
|
2020-11-16 17:01:01 +00:00
|
|
|
ExpectFailure(sigs.v_v(), {}, kAppendEnd, "invalid value type");
|
2020-07-06 15:37:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 11:28:21 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, RttCanon) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
uint8_t array_type_index = builder.AddArray(kWasmI32, true);
|
|
|
|
uint8_t struct_type_index = builder.AddStruct({F(kWasmI64, true)});
|
|
|
|
|
|
|
|
for (HeapType::Representation heap :
|
|
|
|
{HeapType::kExtern, HeapType::kEq, HeapType::kExn, HeapType::kI31,
|
2020-11-19 14:51:14 +00:00
|
|
|
HeapType::kAny, static_cast<HeapType::Representation>(array_type_index),
|
2020-07-23 11:28:21 +00:00
|
|
|
static_cast<HeapType::Representation>(struct_type_index)}) {
|
2020-11-19 14:51:14 +00:00
|
|
|
ValueType rtt1 =
|
|
|
|
ValueType::Rtt(HeapType(heap), heap == HeapType::kAny ? 0 : 1);
|
2020-07-23 11:28:21 +00:00
|
|
|
FunctionSig sig1(1, 0, &rtt1);
|
|
|
|
ExpectValidates(&sig1, {WASM_RTT_CANON(rtt1.heap_type().code() & 0x7F)});
|
|
|
|
|
2020-11-19 14:51:14 +00:00
|
|
|
// rtt.canon should fail for incorrect depth.
|
|
|
|
ValueType rtt2 =
|
|
|
|
ValueType::Rtt(HeapType(heap), heap == HeapType::kAny ? 1 : 2);
|
2020-07-23 11:28:21 +00:00
|
|
|
FunctionSig sig2(1, 0, &rtt2);
|
|
|
|
ExpectFailure(&sig2, {WASM_RTT_CANON(rtt2.heap_type().code() & 0x7F)},
|
|
|
|
kAppendEnd, "type error in merge[0]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FunctionBodyDecoderTest, RttSub) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
uint8_t array_type_index = builder.AddArray(kWasmI8, true);
|
|
|
|
uint8_t super_struct_type_index = builder.AddStruct({F(kWasmI16, true)});
|
|
|
|
uint8_t sub_struct_type_index =
|
|
|
|
builder.AddStruct({F(kWasmI16, true), F(kWasmI32, false)});
|
|
|
|
|
|
|
|
{
|
|
|
|
// Can build an rtt.sub with self type for a generic heap type.
|
|
|
|
ValueType type = ValueType::Rtt(HeapType::kFunc, 2);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(kFuncRefCode, WASM_RTT_CANON(kFuncRefCode))});
|
2020-07-23 11:28:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 14:51:14 +00:00
|
|
|
{
|
|
|
|
// Can build an rtt.sub from a generic type with itself.
|
|
|
|
ValueType type = ValueType::Rtt(HeapType::kAny, 1);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(kAnyRefCode, WASM_RTT_CANON(kAnyRefCode))});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can build an rtt.sub between related generic types.
|
|
|
|
{
|
|
|
|
ValueType type = ValueType::Rtt(HeapType::kFunc, 1);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(kFuncRefCode, WASM_RTT_CANON(kAnyRefCode))});
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ValueType type = ValueType::Rtt(HeapType::kEq, 1);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(kEqRefCode, WASM_RTT_CANON(kAnyRefCode))});
|
|
|
|
}
|
|
|
|
{
|
|
|
|
ValueType type = ValueType::Rtt(HeapType::kI31, 2);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(kI31RefCode, WASM_RTT_CANON(kEqRefCode))});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cannot build an rtt.sub between unrelated generic types.
|
|
|
|
{
|
|
|
|
ValueType type = ValueType::Rtt(HeapType::kFunc, 2);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectFailure(&sig,
|
|
|
|
{WASM_RTT_SUB(kFuncRefCode, WASM_RTT_CANON(kI31RefCode))},
|
|
|
|
kAppendEnd, "rtt.sub requires a supertype rtt on stack");
|
|
|
|
}
|
|
|
|
|
2020-07-23 11:28:21 +00:00
|
|
|
// Trivial type error.
|
|
|
|
ExpectFailure(sigs.v_v(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_RTT_SUB(kFuncRefCode, WASM_I32V(42)), kExprDrop},
|
2020-07-23 11:28:21 +00:00
|
|
|
kAppendEnd, "rtt.sub requires a supertype rtt on stack");
|
|
|
|
|
|
|
|
{
|
|
|
|
ValueType type = ValueType::Rtt(array_type_index, 2);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
// Can build an rtt.sub with self type for an array type.
|
|
|
|
ExpectValidates(&sig, {WASM_RTT_SUB(array_type_index,
|
|
|
|
WASM_RTT_CANON(array_type_index))});
|
|
|
|
// Can build an rtt.sub for an array from eqref.
|
|
|
|
ExpectValidates(
|
2020-09-29 07:46:36 +00:00
|
|
|
&sig, {WASM_RTT_SUB(array_type_index, WASM_RTT_CANON(kEqRefCode))});
|
2020-07-23 11:28:21 +00:00
|
|
|
// Fails when argument to rtt.sub is not a supertype.
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectFailure(
|
|
|
|
sigs.v_v(),
|
|
|
|
{WASM_RTT_SUB(kEqRefCode, WASM_RTT_CANON(array_type_index)), kExprDrop},
|
|
|
|
kAppendEnd, "rtt.sub requires a supertype rtt on stack");
|
2020-07-23 11:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ValueType type = ValueType::Rtt(super_struct_type_index, 2);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
// Can build an rtt.sub with self type for a struct type.
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(super_struct_type_index,
|
|
|
|
WASM_RTT_CANON(super_struct_type_index))});
|
|
|
|
// Can build an rtt.sub for a struct from eqref.
|
|
|
|
ExpectValidates(&sig, {WASM_RTT_SUB(super_struct_type_index,
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_RTT_CANON(kEqRefCode))});
|
2020-07-23 11:28:21 +00:00
|
|
|
// Fails when argument to rtt.sub is not a supertype.
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_RTT_SUB(super_struct_type_index,
|
|
|
|
WASM_RTT_CANON(array_type_index))},
|
|
|
|
kAppendEnd, "rtt.sub requires a supertype rtt on stack");
|
|
|
|
ExpectFailure(sigs.v_v(),
|
|
|
|
{WASM_RTT_SUB(super_struct_type_index,
|
|
|
|
WASM_RTT_CANON(sub_struct_type_index))},
|
|
|
|
kAppendEnd, "rtt.sub requires a supertype rtt on stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Can build an rtt from a stuct supertype.
|
|
|
|
ValueType type = ValueType::Rtt(sub_struct_type_index, 2);
|
|
|
|
FunctionSig sig(1, 0, &type);
|
|
|
|
ExpectValidates(&sig,
|
|
|
|
{WASM_RTT_SUB(sub_struct_type_index,
|
|
|
|
WASM_RTT_CANON(super_struct_type_index))});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 09:13:30 +00:00
|
|
|
TEST_F(FunctionBodyDecoderTest, RefTestCast) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
|
|
|
|
TestModuleBuilder builder;
|
|
|
|
module = builder.module();
|
|
|
|
HeapType::Representation array_heap =
|
|
|
|
static_cast<HeapType::Representation>(builder.AddArray(kWasmI8, true));
|
|
|
|
HeapType::Representation super_struct_heap =
|
|
|
|
static_cast<HeapType::Representation>(
|
|
|
|
builder.AddStruct({F(kWasmI16, true)}));
|
|
|
|
|
|
|
|
HeapType::Representation sub_struct_heap =
|
|
|
|
static_cast<HeapType::Representation>(
|
|
|
|
builder.AddStruct({F(kWasmI16, true), F(kWasmI32, false)}));
|
|
|
|
|
|
|
|
// Passing/failing tests due to static subtyping.
|
|
|
|
std::pair<HeapType::Representation, HeapType::Representation> valid_pairs[] =
|
2020-11-19 14:51:14 +00:00
|
|
|
{{HeapType::kAny, HeapType::kI31}, {HeapType::kAny, HeapType::kFunc},
|
|
|
|
{HeapType::kAny, array_heap}, {HeapType::kAny, super_struct_heap},
|
|
|
|
{HeapType::kEq, HeapType::kI31}, {HeapType::kFunc, HeapType::kFunc},
|
|
|
|
{HeapType::kEq, array_heap}, {HeapType::kEq, super_struct_heap},
|
2020-08-04 09:13:30 +00:00
|
|
|
{super_struct_heap, sub_struct_heap}};
|
|
|
|
|
|
|
|
for (auto pair : valid_pairs) {
|
|
|
|
HeapType from_heap = HeapType(pair.first);
|
|
|
|
HeapType to_heap = HeapType(pair.second);
|
|
|
|
ValueType test_reps[] = {kWasmI32, ValueType::Ref(from_heap, kNullable)};
|
|
|
|
FunctionSig test_sig(1, 1, test_reps);
|
|
|
|
ValueType cast_reps[] = {ValueType::Ref(to_heap, kNonNullable),
|
|
|
|
ValueType::Ref(from_heap, kNullable)};
|
|
|
|
FunctionSig cast_sig(1, 1, cast_reps);
|
|
|
|
ExpectValidates(&test_sig,
|
|
|
|
{WASM_REF_TEST(WASM_HEAP_TYPE(from_heap),
|
|
|
|
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
|
|
|
|
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
|
|
|
|
ExpectValidates(&cast_sig,
|
|
|
|
{WASM_REF_CAST(WASM_HEAP_TYPE(from_heap),
|
|
|
|
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
|
|
|
|
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<HeapType::Representation, HeapType::Representation>
|
2020-11-19 14:51:14 +00:00
|
|
|
invalid_pairs[] = {
|
|
|
|
{array_heap, HeapType::kAny}, {HeapType::kEq, HeapType::kAny},
|
|
|
|
{HeapType::kI31, HeapType::kEq}, {array_heap, super_struct_heap},
|
|
|
|
{array_heap, HeapType::kEq}, {HeapType::kExtern, HeapType::kExn}};
|
2020-08-04 09:13:30 +00:00
|
|
|
|
|
|
|
for (auto pair : invalid_pairs) {
|
|
|
|
HeapType from_heap = HeapType(pair.first);
|
|
|
|
HeapType to_heap = HeapType(pair.second);
|
|
|
|
ValueType test_reps[] = {kWasmI32, ValueType::Ref(from_heap, kNullable)};
|
|
|
|
FunctionSig test_sig(1, 1, test_reps);
|
|
|
|
ValueType cast_reps[] = {ValueType::Ref(to_heap, kNonNullable),
|
|
|
|
ValueType::Ref(from_heap, kNullable)};
|
|
|
|
FunctionSig cast_sig(1, 1, cast_reps);
|
|
|
|
ExpectFailure(&test_sig,
|
|
|
|
{WASM_REF_TEST(WASM_HEAP_TYPE(from_heap),
|
|
|
|
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
|
|
|
|
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
|
|
|
|
kAppendEnd,
|
|
|
|
"ref.test: rtt type must be subtype of object type");
|
|
|
|
ExpectFailure(&cast_sig,
|
|
|
|
{WASM_REF_CAST(WASM_HEAP_TYPE(from_heap),
|
|
|
|
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
|
|
|
|
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
|
|
|
|
kAppendEnd,
|
|
|
|
"ref.cast: rtt type must be subtype of object type");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trivial type error.
|
|
|
|
ExpectFailure(sigs.v_v(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_REF_TEST(kEqRefCode, kI31RefCode, WASM_I32V(1),
|
|
|
|
WASM_RTT_CANON(kI31RefCode)),
|
2020-08-04 09:13:30 +00:00
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd,
|
|
|
|
"ref.test[0] expected type eqref, found i32.const of type i32");
|
|
|
|
ExpectFailure(sigs.v_v(),
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_REF_CAST(kEqRefCode, kI31RefCode, WASM_I32V(1),
|
|
|
|
WASM_RTT_CANON(kI31RefCode)),
|
2020-08-04 09:13:30 +00:00
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd,
|
|
|
|
"ref.cast[0] expected type eqref, found i32.const of type i32");
|
|
|
|
|
|
|
|
// Mismached object heap immediate.
|
|
|
|
{
|
|
|
|
ValueType arg_type = ValueType::Ref(HeapType::kEq, kNonNullable);
|
|
|
|
FunctionSig sig(0, 1, &arg_type);
|
|
|
|
ExpectFailure(
|
|
|
|
&sig,
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_REF_TEST(kEqRefCode, static_cast<byte>(array_heap),
|
|
|
|
WASM_GET_LOCAL(0), WASM_RTT_CANON(kI31RefCode)),
|
2020-08-04 09:13:30 +00:00
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd, "ref.test: expected rtt for type 0 but got (rtt 1 i31)");
|
|
|
|
ExpectFailure(
|
|
|
|
&sig,
|
2020-09-29 07:46:36 +00:00
|
|
|
{WASM_REF_CAST(kEqRefCode, static_cast<byte>(array_heap),
|
|
|
|
WASM_GET_LOCAL(0), WASM_RTT_CANON(kI31RefCode)),
|
2020-08-04 09:13:30 +00:00
|
|
|
kExprDrop},
|
|
|
|
kAppendEnd, "ref.cast: expected rtt for type 0 but got (rtt 1 i31)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
class BranchTableIteratorTest : public TestWithZone {
|
|
|
|
public:
|
|
|
|
BranchTableIteratorTest() : TestWithZone() {}
|
|
|
|
void CheckBrTableSize(const byte* start, const byte* end) {
|
|
|
|
Decoder decoder(start, end);
|
2020-09-30 09:37:50 +00:00
|
|
|
BranchTableImmediate<Decoder::kFullValidation> operand(&decoder, start + 1);
|
|
|
|
BranchTableIterator<Decoder::kFullValidation> iterator(&decoder, operand);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(end - start - 1u, iterator.length());
|
2020-06-26 12:24:26 +00:00
|
|
|
EXPECT_OK(decoder);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
void CheckBrTableError(const byte* start, const byte* end) {
|
|
|
|
Decoder decoder(start, end);
|
2020-09-30 09:37:50 +00:00
|
|
|
BranchTableImmediate<Decoder::kFullValidation> operand(&decoder, start + 1);
|
|
|
|
BranchTableIterator<Decoder::kFullValidation> iterator(&decoder, operand);
|
2016-09-27 20:46:10 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef CHECK_BR_TABLE_LENGTH
|
|
|
|
#undef CHECK_BR_TABLE_ERROR
|
|
|
|
|
2019-02-14 15:16:41 +00:00
|
|
|
struct PrintOpcodes {
|
|
|
|
const byte* start;
|
|
|
|
const byte* end;
|
|
|
|
};
|
|
|
|
std::ostream& operator<<(std::ostream& out, const PrintOpcodes& range) {
|
|
|
|
out << "First opcode: \""
|
|
|
|
<< WasmOpcodes::OpcodeName(static_cast<WasmOpcode>(*range.start))
|
|
|
|
<< "\"\nall bytes: [";
|
|
|
|
for (const byte* b = range.start; b < range.end; ++b) {
|
|
|
|
out << (b == range.start ? "" : ", ") << uint32_t{*b} << "/"
|
|
|
|
<< AsHex(*b, 2, true);
|
|
|
|
}
|
|
|
|
return out << "]";
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
class WasmOpcodeLengthTest : public TestWithZone {
|
|
|
|
public:
|
|
|
|
WasmOpcodeLengthTest() : TestWithZone() {}
|
|
|
|
|
2019-02-14 15:16:41 +00:00
|
|
|
template <typename... Bytes>
|
|
|
|
void ExpectLength(unsigned expected, Bytes... bytes) {
|
|
|
|
const byte code[] = {bytes..., 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code)))
|
|
|
|
<< PrintOpcodes{code, code + sizeof...(bytes)};
|
2016-03-11 18:01:49 +00:00
|
|
|
}
|
[wasm] Fix wasm decoder for multi-byte opcodes
SIMD opcodes consist of the prefix byte, then an LEB128 encoded int. We
were decoding this incorrectly as a fixed uint8. This fixes the decoder
to properly handle multi bytes.
In some cases, the multi byte logic is applied to all prefixed opcodes.
This is not a problem, since for values < 0x80, the LEB encoding is a
single byte, and decodes to the same int. If the prefix opcode has
instructions with index >= 0x80, it would be required to be LEB128
encoded anyway.
There are a bunch of trivial changes to test-run-wasm-simd, to change
the macro from BUILD to BUILD_V, the former only works for single byte
opcodes, the latter is a new template-based macro that correct handles
multi-byte opcodes. The only unchanged test is the shuffle fuzzer test,
which builds its own sequence of bytes without using the BUILD macro.
Bug: v8:10258
Change-Id: Ie7377e899a7eab97ecf28176fd908babc08d0f19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2118476
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67186}
2020-04-15 19:03:00 +00:00
|
|
|
|
|
|
|
// Helper to check for prefixed opcodes, which can have multiple bytes.
|
|
|
|
void ExpectLengthPrefixed(unsigned operands, WasmOpcode opcode) {
|
|
|
|
uint8_t prefix = (opcode >> 8) & 0xff;
|
|
|
|
DCHECK(WasmOpcodes::IsPrefixOpcode(static_cast<WasmOpcode>(prefix)));
|
|
|
|
uint8_t index = opcode & 0xff;
|
|
|
|
uint8_t encoded[2] = {0, 0};
|
|
|
|
uint8_t* p = encoded;
|
|
|
|
unsigned len = static_cast<unsigned>(LEBHelper::sizeof_u32v(index));
|
|
|
|
DCHECK_GE(2, len);
|
|
|
|
LEBHelper::write_u32v(&p, index);
|
|
|
|
// length of index, + number of operands + prefix bye
|
|
|
|
ExpectLength(len + operands + 1, prefix, encoded[0], encoded[1]);
|
|
|
|
}
|
2020-05-29 12:03:26 +00:00
|
|
|
|
|
|
|
template <typename... Bytes>
|
|
|
|
void ExpectFailure(Bytes... bytes) {
|
|
|
|
const byte code[] = {bytes..., 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
WasmFeatures no_features = WasmFeatures::None();
|
2020-09-30 09:37:50 +00:00
|
|
|
WasmDecoder<Decoder::kFullValidation> decoder(
|
|
|
|
this->zone(), nullptr, no_features, &no_features, nullptr, code,
|
|
|
|
code + sizeof(code), 0);
|
|
|
|
WasmDecoder<Decoder::kFullValidation>::OpcodeLength(&decoder, code);
|
2020-05-29 12:03:26 +00:00
|
|
|
EXPECT_EQ(decoder.failed(), true);
|
|
|
|
}
|
2019-02-14 15:16:41 +00:00
|
|
|
};
|
2016-03-11 18:01:49 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, Statements) {
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(1, kExprNop);
|
|
|
|
ExpectLength(1, kExprElse);
|
|
|
|
ExpectLength(1, kExprEnd);
|
|
|
|
ExpectLength(1, kExprSelect);
|
|
|
|
ExpectLength(1, kExprCatch);
|
|
|
|
ExpectLength(1, kExprRethrow);
|
|
|
|
ExpectLength(2, kExprBr);
|
|
|
|
ExpectLength(2, kExprBrIf);
|
|
|
|
ExpectLength(2, kExprThrow);
|
|
|
|
ExpectLength(3, kExprBrOnExn);
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectLength(2, kExprBlock, kI32Code);
|
|
|
|
ExpectLength(2, kExprLoop, kI32Code);
|
|
|
|
ExpectLength(2, kExprIf, kI32Code);
|
|
|
|
ExpectLength(2, kExprTry, kI32Code);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(5, kExprF32Const);
|
|
|
|
ExpectLength(9, kExprF64Const);
|
2020-06-03 12:48:16 +00:00
|
|
|
ExpectLength(2, kExprRefNull);
|
2019-10-08 12:38:48 +00:00
|
|
|
ExpectLength(2, kExprLocalGet);
|
|
|
|
ExpectLength(2, kExprLocalSet);
|
2019-10-08 13:16:30 +00:00
|
|
|
ExpectLength(2, kExprGlobalGet);
|
|
|
|
ExpectLength(2, kExprGlobalSet);
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(2, kExprCallFunction);
|
|
|
|
ExpectLength(3, kExprCallIndirect);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 18:01:49 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, I32Const) {
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(2, kExprI32Const, U32V_1(1));
|
|
|
|
ExpectLength(3, kExprI32Const, U32V_2(999));
|
|
|
|
ExpectLength(4, kExprI32Const, U32V_3(9999));
|
|
|
|
ExpectLength(5, kExprI32Const, U32V_4(999999));
|
|
|
|
ExpectLength(6, kExprI32Const, U32V_5(99999999));
|
2016-03-11 18:01:49 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-11 18:01:49 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, I64Const) {
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(2, kExprI64Const, U32V_1(1));
|
|
|
|
ExpectLength(3, kExprI64Const, U32V_2(99));
|
|
|
|
ExpectLength(4, kExprI64Const, U32V_3(9999));
|
|
|
|
ExpectLength(5, kExprI64Const, U32V_4(99999));
|
|
|
|
ExpectLength(6, kExprI64Const, U32V_5(9999999));
|
|
|
|
ExpectLength(7, WASM_I64V_6(777777));
|
|
|
|
ExpectLength(8, WASM_I64V_7(7777777));
|
|
|
|
ExpectLength(9, WASM_I64V_8(77777777));
|
|
|
|
ExpectLength(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) {
|
2019-10-08 13:16:30 +00:00
|
|
|
ExpectLength(2, kExprGlobalGet, U32V_1(1));
|
|
|
|
ExpectLength(3, kExprGlobalGet, U32V_2(33));
|
|
|
|
ExpectLength(4, kExprGlobalGet, U32V_3(44));
|
|
|
|
ExpectLength(5, kExprGlobalGet, U32V_4(66));
|
|
|
|
ExpectLength(6, kExprGlobalGet, U32V_5(77));
|
2019-05-13 09:45:06 +00:00
|
|
|
|
|
|
|
ExpectLength(2, kExprRefFunc, U32V_1(1));
|
|
|
|
ExpectLength(3, kExprRefFunc, U32V_2(33));
|
|
|
|
ExpectLength(4, kExprRefFunc, U32V_3(44));
|
|
|
|
ExpectLength(5, kExprRefFunc, U32V_4(66));
|
|
|
|
ExpectLength(6, kExprRefFunc, U32V_5(77));
|
2019-08-26 14:54:14 +00:00
|
|
|
|
|
|
|
ExpectLength(2, kExprTableGet, U32V_1(1));
|
|
|
|
ExpectLength(3, kExprTableGet, U32V_2(33));
|
|
|
|
ExpectLength(4, kExprTableGet, U32V_3(44));
|
|
|
|
ExpectLength(5, kExprTableGet, U32V_4(66));
|
|
|
|
ExpectLength(6, kExprTableGet, U32V_5(77));
|
|
|
|
|
|
|
|
ExpectLength(2, kExprTableSet, U32V_1(1));
|
|
|
|
ExpectLength(3, kExprTableSet, U32V_2(33));
|
|
|
|
ExpectLength(4, kExprTableSet, U32V_3(44));
|
|
|
|
ExpectLength(5, kExprTableSet, U32V_4(66));
|
|
|
|
ExpectLength(6, kExprTableSet, U32V_5(77));
|
|
|
|
|
|
|
|
ExpectLength(3, kExprCallIndirect, U32V_1(1), U32V_1(1));
|
|
|
|
ExpectLength(4, kExprCallIndirect, U32V_1(1), U32V_2(33));
|
|
|
|
ExpectLength(5, kExprCallIndirect, U32V_1(1), U32V_3(44));
|
|
|
|
ExpectLength(6, kExprCallIndirect, U32V_1(1), U32V_4(66));
|
|
|
|
ExpectLength(7, kExprCallIndirect, U32V_1(1), U32V_5(77));
|
2016-03-11 18:01:49 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, LoadsAndStores) {
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(3, kExprI32LoadMem8S);
|
|
|
|
ExpectLength(3, kExprI32LoadMem8U);
|
|
|
|
ExpectLength(3, kExprI32LoadMem16S);
|
|
|
|
ExpectLength(3, kExprI32LoadMem16U);
|
|
|
|
ExpectLength(3, kExprI32LoadMem);
|
|
|
|
ExpectLength(3, kExprI64LoadMem8S);
|
|
|
|
ExpectLength(3, kExprI64LoadMem8U);
|
|
|
|
ExpectLength(3, kExprI64LoadMem16S);
|
|
|
|
ExpectLength(3, kExprI64LoadMem16U);
|
|
|
|
ExpectLength(3, kExprI64LoadMem32S);
|
|
|
|
ExpectLength(3, kExprI64LoadMem32U);
|
|
|
|
ExpectLength(3, kExprI64LoadMem);
|
|
|
|
ExpectLength(3, kExprF32LoadMem);
|
|
|
|
ExpectLength(3, kExprF64LoadMem);
|
|
|
|
|
|
|
|
ExpectLength(3, kExprI32StoreMem8);
|
|
|
|
ExpectLength(3, kExprI32StoreMem16);
|
|
|
|
ExpectLength(3, kExprI32StoreMem);
|
|
|
|
ExpectLength(3, kExprI64StoreMem8);
|
|
|
|
ExpectLength(3, kExprI64StoreMem16);
|
|
|
|
ExpectLength(3, kExprI64StoreMem32);
|
|
|
|
ExpectLength(3, kExprI64StoreMem);
|
|
|
|
ExpectLength(3, kExprF32StoreMem);
|
|
|
|
ExpectLength(3, kExprF64StoreMem);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, MiscMemExpressions) {
|
2019-02-14 15:16:41 +00:00
|
|
|
ExpectLength(2, kExprMemorySize);
|
|
|
|
ExpectLength(2, kExprMemoryGrow);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmOpcodeLengthTest, SimpleExpressions) {
|
2019-02-14 15:16:41 +00:00
|
|
|
#define SIMPLE_OPCODE(name, byte, sig) byte,
|
|
|
|
static constexpr uint8_t kSimpleOpcodes[] = {
|
|
|
|
FOREACH_SIMPLE_OPCODE(SIMPLE_OPCODE)};
|
|
|
|
#undef SIMPLE_OPCODE
|
|
|
|
for (uint8_t simple_opcode : kSimpleOpcodes) {
|
|
|
|
ExpectLength(1, simple_opcode);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 22:03:17 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, SimdExpressions) {
|
[wasm] Fix wasm decoder for multi-byte opcodes
SIMD opcodes consist of the prefix byte, then an LEB128 encoded int. We
were decoding this incorrectly as a fixed uint8. This fixes the decoder
to properly handle multi bytes.
In some cases, the multi byte logic is applied to all prefixed opcodes.
This is not a problem, since for values < 0x80, the LEB encoding is a
single byte, and decodes to the same int. If the prefix opcode has
instructions with index >= 0x80, it would be required to be LEB128
encoded anyway.
There are a bunch of trivial changes to test-run-wasm-simd, to change
the macro from BUILD to BUILD_V, the former only works for single byte
opcodes, the latter is a new template-based macro that correct handles
multi-byte opcodes. The only unchanged test is the shuffle fuzzer test,
which builds its own sequence of bytes without using the BUILD macro.
Bug: v8:10258
Change-Id: Ie7377e899a7eab97ecf28176fd908babc08d0f19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2118476
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67186}
2020-04-15 19:03:00 +00:00
|
|
|
#define TEST_SIMD(name, opcode, sig) ExpectLengthPrefixed(0, kExpr##name);
|
2016-10-25 22:03:17 +00:00
|
|
|
FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD)
|
|
|
|
#undef TEST_SIMD
|
[wasm] Fix wasm decoder for multi-byte opcodes
SIMD opcodes consist of the prefix byte, then an LEB128 encoded int. We
were decoding this incorrectly as a fixed uint8. This fixes the decoder
to properly handle multi bytes.
In some cases, the multi byte logic is applied to all prefixed opcodes.
This is not a problem, since for values < 0x80, the LEB encoding is a
single byte, and decodes to the same int. If the prefix opcode has
instructions with index >= 0x80, it would be required to be LEB128
encoded anyway.
There are a bunch of trivial changes to test-run-wasm-simd, to change
the macro from BUILD to BUILD_V, the former only works for single byte
opcodes, the latter is a new template-based macro that correct handles
multi-byte opcodes. The only unchanged test is the shuffle fuzzer test,
which builds its own sequence of bytes without using the BUILD macro.
Bug: v8:10258
Change-Id: Ie7377e899a7eab97ecf28176fd908babc08d0f19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2118476
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67186}
2020-04-15 19:03:00 +00:00
|
|
|
#define TEST_SIMD(name, opcode, sig) ExpectLengthPrefixed(1, kExpr##name);
|
2016-10-25 22:03:17 +00:00
|
|
|
FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD)
|
2017-05-04 16:50:51 +00:00
|
|
|
#undef TEST_SIMD
|
2020-09-25 18:08:04 +00:00
|
|
|
ExpectLengthPrefixed(16, kExprI8x16Shuffle);
|
[wasm] Fix wasm decoder for multi-byte opcodes
SIMD opcodes consist of the prefix byte, then an LEB128 encoded int. We
were decoding this incorrectly as a fixed uint8. This fixes the decoder
to properly handle multi bytes.
In some cases, the multi byte logic is applied to all prefixed opcodes.
This is not a problem, since for values < 0x80, the LEB encoding is a
single byte, and decodes to the same int. If the prefix opcode has
instructions with index >= 0x80, it would be required to be LEB128
encoded anyway.
There are a bunch of trivial changes to test-run-wasm-simd, to change
the macro from BUILD to BUILD_V, the former only works for single byte
opcodes, the latter is a new template-based macro that correct handles
multi-byte opcodes. The only unchanged test is the shuffle fuzzer test,
which builds its own sequence of bytes without using the BUILD macro.
Bug: v8:10258
Change-Id: Ie7377e899a7eab97ecf28176fd908babc08d0f19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2118476
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67186}
2020-04-15 19:03:00 +00:00
|
|
|
// test for bad simd opcode, 0xFF is encoded in two bytes.
|
|
|
|
ExpectLength(3, kSimdPrefix, 0xFF, 0x1);
|
2016-10-25 22:03:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 12:03:26 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, IllegalRefIndices) {
|
2020-09-29 07:46:36 +00:00
|
|
|
ExpectFailure(kExprBlock, kOptRefCode, U32V_3(kV8MaxWasmTypes + 1));
|
|
|
|
ExpectFailure(kExprBlock, kOptRefCode, U32V_4(0x01000000));
|
2020-05-29 12:03:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:20:42 +00:00
|
|
|
TEST_F(WasmOpcodeLengthTest, PrefixedOpcodesLEB) {
|
|
|
|
// kExprI32New with a 4-byte LEB-encoded opcode.
|
|
|
|
ExpectLength(5, 0xfb, 0xa0, 0x80, 0x80, 0x00);
|
|
|
|
|
|
|
|
// kExprI8x16Splat with a 3-byte LEB-encoded opcode.
|
|
|
|
ExpectLength(4, 0xfd, 0x8f, 0x80, 0x00);
|
|
|
|
|
|
|
|
// kExprI32SConvertSatF32 with a 4-byte LEB-encoded opcode.
|
|
|
|
ExpectLength(5, 0xfc, 0x80, 0x80, 0x80, 0x00);
|
|
|
|
|
|
|
|
// kExprAtomicNotify with a 2-byte LEB-encoded opcode, and 2 i32 imm for
|
|
|
|
// memarg.
|
|
|
|
ExpectLength(5, 0xfe, 0x80, 0x00, 0x00, 0x00);
|
|
|
|
}
|
|
|
|
|
2020-11-10 13:24:00 +00:00
|
|
|
class TypeReaderTest : public TestWithZone {
|
|
|
|
public:
|
|
|
|
ValueType DecodeValueType(const byte* start, const byte* end) {
|
|
|
|
Decoder decoder(start, end);
|
|
|
|
uint32_t length;
|
|
|
|
return value_type_reader::read_value_type<Decoder::kFullValidation>(
|
|
|
|
&decoder, start, &length, enabled_features_);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapType DecodeHeapType(const byte* start, const byte* end) {
|
|
|
|
Decoder decoder(start, end);
|
|
|
|
uint32_t length;
|
|
|
|
return value_type_reader::read_heap_type<Decoder::kFullValidation>(
|
|
|
|
&decoder, start, &length, enabled_features_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This variable is modified by WASM_FEATURE_SCOPE.
|
|
|
|
WasmFeatures enabled_features_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(TypeReaderTest, HeapTypeDecodingTest) {
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
|
|
|
|
HeapType heap_func = HeapType(HeapType::kFunc);
|
|
|
|
HeapType heap_bottom = HeapType(HeapType::kBottom);
|
|
|
|
|
|
|
|
// 1- to 5-byte representation of kFuncRefCode.
|
|
|
|
{
|
|
|
|
const byte data[] = {kFuncRefCode};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result == heap_func);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const byte data[] = {kFuncRefCode | 0x80, 0x7F};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_EQ(result, heap_func);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const byte data[] = {kFuncRefCode | 0x80, 0xFF, 0x7F};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_EQ(result, heap_func);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const byte data[] = {kFuncRefCode | 0x80, 0xFF, 0xFF, 0x7F};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_EQ(result, heap_func);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const byte data[] = {kFuncRefCode | 0x80, 0xFF, 0xFF, 0xFF, 0x7F};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_EQ(result, heap_func);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Some negative number.
|
|
|
|
const byte data[] = {0xB4, 0x7F};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_EQ(result, heap_bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// This differs from kFuncRefCode by one bit outside the 1-byte LEB128
|
|
|
|
// range. This should therefore NOT be decoded as HeapType::kFunc and
|
|
|
|
// instead fail.
|
|
|
|
const byte data[] = {kFuncRefCode | 0x80, 0x6F};
|
|
|
|
HeapType result = DecodeHeapType(data, data + sizeof(data));
|
|
|
|
EXPECT_EQ(result, heap_bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 09:40:26 +00:00
|
|
|
using TypesOfLocals = ZoneVector<ValueType>;
|
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;
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmFeatures enabled_features_;
|
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;
|
|
|
|
}
|
2018-08-08 14:54:44 +00:00
|
|
|
|
|
|
|
bool DecodeLocalDecls(BodyLocalDecls* decls, const byte* start,
|
|
|
|
const byte* end) {
|
|
|
|
return i::wasm::DecodeLocalDecls(enabled_features_, decls, start, end);
|
|
|
|
}
|
2016-03-07 21:04:07 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-16 12:47:46 +00:00
|
|
|
TEST_F(LocalDeclDecoderTest, WrongLocalDeclsCount1) {
|
|
|
|
static const byte data[] = {1};
|
|
|
|
BodyLocalDecls decls(zone());
|
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LocalDeclDecoderTest, WrongLocalDeclsCount2) {
|
|
|
|
static const byte data[] = {2, 1,
|
|
|
|
static_cast<byte>(kWasmI32.value_type_code())};
|
|
|
|
BodyLocalDecls decls(zone());
|
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result);
|
|
|
|
}
|
|
|
|
|
2016-03-07 21:04:07 +00:00
|
|
|
TEST_F(LocalDeclDecoderTest, OneLocal) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
2020-03-12 14:29:51 +00:00
|
|
|
const byte data[] = {1, 1, static_cast<byte>(type.value_type_code())};
|
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) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueType type = kValueTypes[i];
|
2020-03-12 14:29:51 +00:00
|
|
|
const byte data[] = {1, 5, static_cast<byte>(type.value_type_code())};
|
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++) {
|
2020-09-29 07:46:36 +00:00
|
|
|
const byte data[] = {4, a, kI32Code, b, kI64Code,
|
|
|
|
c, kF32Code, d, kF64Code};
|
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
|
|
|
}
|
|
|
|
|
2019-07-15 08:24:37 +00:00
|
|
|
TEST_F(LocalDeclDecoderTest, ExnRef) {
|
2018-08-30 12:46:48 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2019-07-15 08:24:37 +00:00
|
|
|
ValueType type = kWasmExnRef;
|
2020-03-12 14:29:51 +00:00
|
|
|
const byte data[] = {1, 1, static_cast<byte>(type.value_type_code())};
|
2018-08-30 12:46:48 +00:00
|
|
|
BodyLocalDecls decls(zone());
|
|
|
|
bool result = DecodeLocalDecls(&decls, data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result);
|
|
|
|
EXPECT_EQ(1u, decls.type_list.size());
|
|
|
|
|
|
|
|
TypesOfLocals map = decls.type_list;
|
|
|
|
EXPECT_EQ(type, map[0]);
|
|
|
|
}
|
|
|
|
|
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));
|
2017-01-09 13:57:26 +00:00
|
|
|
WasmOpcode expected[] = {kExprI32Const, kExprIf, kExprI32Const,
|
|
|
|
kExprElse, kExprI32Const, kExprEnd};
|
2016-07-11 12:57:22 +00:00
|
|
|
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) {
|
2020-09-29 07:46:36 +00:00
|
|
|
byte code[] = {1, 1, kI32Code, WASM_I32V_1(9), WASM_I32V_1(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());
|
2017-01-09 13:57:26 +00:00
|
|
|
EXPECT_EQ(kExprI32Const, iter.current());
|
2016-07-11 12:57:22 +00:00
|
|
|
iter.next();
|
|
|
|
EXPECT_TRUE(iter.has_next());
|
2017-01-09 13:57:26 +00:00
|
|
|
EXPECT_EQ(kExprI32Const, iter.current());
|
2016-07-11 12:57:22 +00:00
|
|
|
iter.next();
|
|
|
|
EXPECT_FALSE(iter.has_next());
|
|
|
|
}
|
2017-09-01 12:57:34 +00:00
|
|
|
|
2020-10-13 09:00:00 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Memory64 tests
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-11-24 19:09:36 +00:00
|
|
|
using FunctionBodyDecoderTestOnBothMemoryTypes =
|
|
|
|
FunctionBodyDecoderTestBase<::testing::TestWithParam<MemoryType>>;
|
2020-11-17 15:28:08 +00:00
|
|
|
|
|
|
|
std::string PrintMemoryType(::testing::TestParamInfo<MemoryType> info) {
|
|
|
|
switch (info.param) {
|
|
|
|
case kMemory32:
|
|
|
|
return "kMemory32";
|
|
|
|
case kMemory64:
|
|
|
|
return "kMemory64";
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(MemoryTypes, FunctionBodyDecoderTestOnBothMemoryTypes,
|
|
|
|
::testing::Values(kMemory32, kMemory64),
|
|
|
|
PrintMemoryType);
|
|
|
|
|
|
|
|
TEST_P(FunctionBodyDecoderTestOnBothMemoryTypes, IndexTypes) {
|
|
|
|
builder.InitializeMemory(GetParam());
|
2020-11-24 19:09:36 +00:00
|
|
|
const bool is_memory64 = GetParam() == kMemory64;
|
|
|
|
Validate(!is_memory64, sigs.i_v(),
|
2020-11-17 15:28:08 +00:00
|
|
|
{WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)});
|
2020-11-24 19:09:36 +00:00
|
|
|
Validate(is_memory64, sigs.i_v(),
|
2020-11-17 15:28:08 +00:00
|
|
|
{WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO64)});
|
2020-11-24 19:09:36 +00:00
|
|
|
Validate(!is_memory64, sigs.v_v(),
|
2020-11-17 15:28:08 +00:00
|
|
|
{WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_ZERO)});
|
2020-11-24 19:09:36 +00:00
|
|
|
Validate(is_memory64, sigs.v_v(),
|
2020-11-17 15:28:08 +00:00
|
|
|
{WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO64, WASM_ZERO)});
|
2020-10-13 09:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef B1
|
|
|
|
#undef B2
|
|
|
|
#undef B3
|
|
|
|
#undef WASM_IF_OP
|
|
|
|
#undef WASM_LOOP_OP
|
|
|
|
#undef WASM_BRV_IF_ZERO
|
2020-06-26 12:24:26 +00:00
|
|
|
#undef EXPECT_OK
|
2017-09-08 13:59:05 +00:00
|
|
|
|
2017-09-28 17:55:52 +00:00
|
|
|
} // namespace function_body_decoder_unittest
|
2017-09-01 12:57:34 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|