[wasm] Improve init. expr. testing code
- Add an expected type argument in DecodeWasmInitExprForTesting. This eliminates the need to check for kWasmVoid in consume_init_expr. - Invoke StartDecoding() to initialize module in DecodeWasmInitExprForTesting. - Pass the current module to DecodeInitExprForTesting. - Adjust tests. Bug: v8:11895 Change-Id: I13b71b68a2011bf08742701cb9dd986afd6e55f8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972907 Commit-Queue: Manos Koukoutos <manoskouk@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#75292}
This commit is contained in:
parent
e29b2ae48a
commit
0ec7f85f37
@ -1385,8 +1385,8 @@ class ModuleDecoderImpl : public Decoder {
|
||||
return ok() ? result : nullptr;
|
||||
}
|
||||
|
||||
WasmInitExpr DecodeInitExprForTesting() {
|
||||
return consume_init_expr(nullptr, kWasmVoid, 0);
|
||||
WasmInitExpr DecodeInitExprForTesting(ValueType expected) {
|
||||
return consume_init_expr(module_.get(), expected, 0);
|
||||
}
|
||||
|
||||
const std::shared_ptr<WasmModule>& shared_module() const { return module_; }
|
||||
@ -2009,7 +2009,7 @@ class ModuleDecoderImpl : public Decoder {
|
||||
}
|
||||
|
||||
WasmInitExpr expr = std::move(stack.back());
|
||||
if (expected != kWasmVoid && !IsSubtypeOf(TypeOf(expr), expected, module)) {
|
||||
if (!IsSubtypeOf(TypeOf(expr), expected, module)) {
|
||||
errorf(pc(), "type error in init expression, expected %s, got %s",
|
||||
expected.name().c_str(), TypeOf(expr).name().c_str());
|
||||
}
|
||||
@ -2449,10 +2449,12 @@ const FunctionSig* DecodeWasmSignatureForTesting(const WasmFeatures& enabled,
|
||||
}
|
||||
|
||||
WasmInitExpr DecodeWasmInitExprForTesting(const WasmFeatures& enabled,
|
||||
const byte* start, const byte* end) {
|
||||
AccountingAllocator allocator;
|
||||
const byte* start, const byte* end,
|
||||
ValueType expected) {
|
||||
ModuleDecoderImpl decoder(enabled, start, end, kWasmOrigin);
|
||||
return decoder.DecodeInitExprForTesting();
|
||||
AccountingAllocator allocator;
|
||||
decoder.StartDecoding(nullptr, &allocator);
|
||||
return decoder.DecodeInitExprForTesting(expected);
|
||||
}
|
||||
|
||||
FunctionResult DecodeWasmFunctionForTesting(
|
||||
|
@ -171,8 +171,9 @@ V8_EXPORT_PRIVATE FunctionResult DecodeWasmFunctionForTesting(
|
||||
const WasmModule* module, const byte* function_start,
|
||||
const byte* function_end, Counters* counters);
|
||||
|
||||
V8_EXPORT_PRIVATE WasmInitExpr DecodeWasmInitExprForTesting(
|
||||
const WasmFeatures& enabled, const byte* start, const byte* end);
|
||||
V8_EXPORT_PRIVATE WasmInitExpr
|
||||
DecodeWasmInitExprForTesting(const WasmFeatures& enabled, const byte* start,
|
||||
const byte* end, ValueType expected);
|
||||
|
||||
struct CustomSectionOffset {
|
||||
WireBytesRef section;
|
||||
|
@ -3199,24 +3199,27 @@ class WasmInitExprDecodeTest : public TestWithZone {
|
||||
|
||||
WasmFeatures enabled_features_;
|
||||
|
||||
WasmInitExpr DecodeInitExpr(const byte* start, const byte* end) {
|
||||
return DecodeWasmInitExprForTesting(enabled_features_, start, end);
|
||||
WasmInitExpr DecodeInitExpr(const byte* start, const byte* end,
|
||||
ValueType expected) {
|
||||
return DecodeWasmInitExprForTesting(enabled_features_, start, end,
|
||||
expected);
|
||||
}
|
||||
};
|
||||
|
||||
#define EXPECT_INIT_EXPR(Type, type, value, ...) \
|
||||
{ \
|
||||
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
||||
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
|
||||
EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind()); \
|
||||
EXPECT_EQ(value, expr.immediate().type##_const); \
|
||||
#define EXPECT_INIT_EXPR(Type, type, value, ...) \
|
||||
{ \
|
||||
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
||||
WasmInitExpr expr = \
|
||||
DecodeInitExpr(data, data + sizeof(data), kWasm##Type); \
|
||||
EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind()); \
|
||||
EXPECT_EQ(value, expr.immediate().type##_const); \
|
||||
}
|
||||
|
||||
#define EXPECT_INIT_EXPR_FAIL(...) \
|
||||
{ \
|
||||
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
||||
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
|
||||
EXPECT_EQ(WasmInitExpr::kNone, expr.kind()); \
|
||||
#define EXPECT_INIT_EXPR_FAIL(value_type, ...) \
|
||||
{ \
|
||||
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
||||
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data), value_type); \
|
||||
EXPECT_EQ(WasmInitExpr::kNone, expr.kind()); \
|
||||
}
|
||||
|
||||
TEST_F(WasmInitExprDecodeTest, InitExpr_i32) {
|
||||
@ -3250,16 +3253,17 @@ TEST_F(WasmInitExprDecodeTest, InitExpr_f64) {
|
||||
TEST_F(WasmInitExprDecodeTest, InitExpr_ExternRef) {
|
||||
WASM_FEATURE_SCOPE(reftypes);
|
||||
static const byte data[] = {kExprRefNull, kExternRefCode, kExprEnd};
|
||||
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data));
|
||||
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data), kWasmExternRef);
|
||||
EXPECT_EQ(WasmInitExpr::kRefNullConst, expr.kind());
|
||||
}
|
||||
|
||||
TEST_F(WasmInitExprDecodeTest, InitExpr_illegal) {
|
||||
EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0));
|
||||
EXPECT_INIT_EXPR_FAIL(WASM_LOCAL_GET(0));
|
||||
EXPECT_INIT_EXPR_FAIL(WASM_LOCAL_SET(0, WASM_I32V_1(0)));
|
||||
EXPECT_INIT_EXPR_FAIL(WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0)));
|
||||
EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
||||
EXPECT_INIT_EXPR_FAIL(kWasmI32, WASM_I32V_1(0), WASM_I32V_1(0));
|
||||
EXPECT_INIT_EXPR_FAIL(kWasmI32, WASM_LOCAL_GET(0));
|
||||
EXPECT_INIT_EXPR_FAIL(kWasmVoid, WASM_LOCAL_SET(0, WASM_I32V_1(0)));
|
||||
EXPECT_INIT_EXPR_FAIL(kWasmI32, WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0)));
|
||||
EXPECT_INIT_EXPR_FAIL(kWasmI32,
|
||||
WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
||||
}
|
||||
|
||||
TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) {
|
||||
|
Loading…
Reference in New Issue
Block a user