Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,6 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
void validateCallParamsAndResult(T* curr, HeapType sigType) {
validateCallParamsAndResult(curr, sigType, curr);
}

Type indexType(Name memoryName) {
auto memory = getModule()->getMemory(memoryName);
return memory->indexType;
}
};

void FunctionValidator::noteLabelName(Name name) {
Expand Down Expand Up @@ -1056,7 +1051,7 @@ void FunctionValidator::visitLoad(Load* curr) {
validateAlignment(curr->align, curr->type, curr->bytes, curr->isAtomic, curr);
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"load pointer type must match memory index type");
if (curr->isAtomic) {
Expand Down Expand Up @@ -1088,7 +1083,7 @@ void FunctionValidator::visitStore(Store* curr) {
curr->align, curr->valueType, curr->bytes, curr->isAtomic, curr);
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"store pointer must match memory index type");
shouldBeUnequal(curr->value->type,
Expand All @@ -1112,7 +1107,7 @@ void FunctionValidator::visitAtomicRMW(AtomicRMW* curr) {
validateMemBytes(curr->bytes, curr->type, curr);
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"AtomicRMW pointer type must match memory index type");
shouldBeEqualOrFirstIsUnreachable(curr->type,
Expand All @@ -1132,7 +1127,7 @@ void FunctionValidator::visitAtomicCmpxchg(AtomicCmpxchg* curr) {
validateMemBytes(curr->bytes, curr->type, curr);
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"cmpxchg pointer must match memory index type");
if (curr->expected->type != Type::unreachable &&
Expand Down Expand Up @@ -1166,7 +1161,7 @@ void FunctionValidator::visitAtomicWait(AtomicWait* curr) {
curr->type, Type(Type::i32), curr, "AtomicWait must have type i32");
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"AtomicWait pointer must match memory index type");
shouldBeIntOrUnreachable(
Expand All @@ -1192,7 +1187,7 @@ void FunctionValidator::visitAtomicNotify(AtomicNotify* curr) {
curr->type, Type(Type::i32), curr, "AtomicNotify must have type i32");
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"AtomicNotify pointer must match memory index type");
shouldBeEqualOrFirstIsUnreachable(
Expand Down Expand Up @@ -1354,7 +1349,7 @@ void FunctionValidator::visitSIMDLoad(SIMDLoad* curr) {
curr->type, Type(Type::v128), curr, "load_splat must have type v128");
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"load_splat address must match memory index type");
Type memAlignType = Type::none;
Expand Down Expand Up @@ -1395,7 +1390,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
}
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
indexType(curr->memory),
memory->indexType,
curr,
"loadX_lane or storeX_lane address must match memory index type");
shouldBeEqualOrFirstIsUnreachable(
Expand Down Expand Up @@ -1435,6 +1430,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
}

void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
auto* memory = getModule()->getMemoryOrNull(curr->memory);
shouldBeTrue(
getModule()->features.hasBulkMemory(),
curr,
Expand All @@ -1443,7 +1439,7 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
curr->type, Type(Type::none), curr, "memory.init must have type none");
shouldBeEqualOrFirstIsUnreachable(
curr->dest->type,
indexType(curr->memory),
memory->indexType,
curr,
"memory.init dest must match memory index type");
shouldBeEqualOrFirstIsUnreachable(curr->offset->type,
Expand All @@ -1452,7 +1448,6 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
"memory.init offset must be an i32");
shouldBeEqualOrFirstIsUnreachable(
curr->size->type, Type(Type::i32), curr, "memory.init size must be an i32");
auto* memory = getModule()->getMemoryOrNull(curr->memory);
if (!shouldBeTrue(!!memory, curr, "memory.init memory must exist")) {
return;
}
Expand Down Expand Up @@ -1486,27 +1481,28 @@ void FunctionValidator::visitMemoryCopy(MemoryCopy* curr) {
shouldBeTrue(!!sourceMemory, curr, "memory.copy sourceMemory must exist");
shouldBeEqualOrFirstIsUnreachable(
curr->dest->type,
indexType(curr->destMemory),
destMemory->indexType,
curr,
"memory.copy dest must match destMemory index type");
shouldBeEqualOrFirstIsUnreachable(
curr->source->type,
indexType(curr->sourceMemory),
sourceMemory->indexType,
curr,
"memory.copy source must match sourceMemory index type");
shouldBeEqualOrFirstIsUnreachable(
curr->size->type,
indexType(curr->destMemory),
destMemory->indexType,
curr,
"memory.copy size must match destMemory index type");
shouldBeEqualOrFirstIsUnreachable(
curr->size->type,
indexType(curr->sourceMemory),
sourceMemory->indexType,
curr,
"memory.copy size must match destMemory index type");
}

void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
auto* memory = getModule()->getMemoryOrNull(curr->memory);
shouldBeTrue(
getModule()->features.hasBulkMemory(),
curr,
Expand All @@ -1515,7 +1511,7 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
curr->type, Type(Type::none), curr, "memory.fill must have type none");
shouldBeEqualOrFirstIsUnreachable(
curr->dest->type,
indexType(curr->memory),
memory->indexType,
curr,
"memory.fill dest must match memory index type");
shouldBeEqualOrFirstIsUnreachable(curr->value->type,
Expand All @@ -1524,10 +1520,9 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
"memory.fill value must be an i32");
shouldBeEqualOrFirstIsUnreachable(
curr->size->type,
indexType(curr->memory),
memory->indexType,
curr,
"memory.fill size must match memory index type");
auto* memory = getModule()->getMemoryOrNull(curr->memory);
shouldBeTrue(!!memory, curr, "memory.fill memory must exist");
}

Expand Down Expand Up @@ -2162,7 +2157,7 @@ void FunctionValidator::visitMemoryGrow(MemoryGrow* curr) {
auto* memory = getModule()->getMemoryOrNull(curr->memory);
shouldBeTrue(!!memory, curr, "memory.grow memory must exist");
shouldBeEqualOrFirstIsUnreachable(curr->delta->type,
indexType(curr->memory),
memory->indexType,
curr,
"memory.grow must match memory index type");
}
Expand Down