summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-validator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r--src/wasm/wasm-validator.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index b032e6bad..758ae158e 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -469,6 +469,7 @@ public:
void visitTableGrow(TableGrow* curr);
void visitTableFill(TableFill* curr);
void visitTableCopy(TableCopy* curr);
+ void visitTableInit(TableInit* curr);
void noteDelegate(Name name, Expression* curr);
void noteRethrow(Name name, Expression* curr);
void visitTry(Try* curr);
@@ -2443,12 +2444,41 @@ void FunctionValidator::visitTableCopy(TableCopy* curr) {
curr,
"table.copy source must have right type for dest");
}
+ shouldBeEqualOrFirstIsUnreachable(curr->dest->type,
+ destTable->indexType,
+ curr,
+ "table.copy dest must be valid");
+ shouldBeEqualOrFirstIsUnreachable(curr->source->type,
+ sourceTable->indexType,
+ curr,
+ "table.copy source must be valid");
+ Type sizeType =
+ sourceTable->is64() && destTable->is64() ? Type::i64 : Type::i32;
shouldBeEqualOrFirstIsUnreachable(
- curr->dest->type, Type(Type::i32), curr, "table.copy dest must be i32");
+ curr->size->type, sizeType, curr, "table.copy size must be valid");
+}
+
+void FunctionValidator::visitTableInit(TableInit* curr) {
+ shouldBeTrue(getModule()->features.hasBulkMemory(),
+ curr,
+ "table.init requires bulk-memory [--enable-bulk-memory]");
+ auto* segment = getModule()->getElementSegment(curr->segment);
+ auto* table = getModule()->getTableOrNull(curr->table);
+ if (shouldBeTrue(!!segment, curr, "table.init segment must exist") &&
+ shouldBeTrue(!!table, curr, "table.init table must exist")) {
+ shouldBeSubType(segment->type,
+ table->type,
+ curr,
+ "table.init source must have right type for dest");
+ }
shouldBeEqualOrFirstIsUnreachable(
- curr->source->type, Type(Type::i32), curr, "table.copy source must be i32");
+ curr->dest->type, table->indexType, curr, "table.init dest must be valid");
+ shouldBeEqualOrFirstIsUnreachable(curr->offset->type,
+ Type(Type::i32),
+ curr,
+ "table.init offset must be valid");
shouldBeEqualOrFirstIsUnreachable(
- curr->size->type, Type(Type::i32), curr, "table.copy size must be i32");
+ curr->size->type, Type(Type::i32), curr, "table.init size must be valid");
}
void FunctionValidator::noteDelegate(Name name, Expression* curr) {