Skip to content

Commit 0e8c99f

Browse files
committed
Improve struct RMW validation
Add missing validation rules checking that accessed fields have allowed types. Copy the proposed upstream spec tests for this validation from WebAssembly/shared-everything-threads#85 with minor changes to account for differences in supported text format and to comment out unsupported tests.
1 parent 98129d1 commit 0e8c99f

File tree

3 files changed

+605
-104
lines changed

3 files changed

+605
-104
lines changed

src/wasm/wasm-validator.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,12 +3096,26 @@ void FunctionValidator::visitStructRMW(StructRMW* curr) {
30963096
return;
30973097
}
30983098
auto& field = fields[curr->index];
3099+
shouldBeEqual(
3100+
field.mutable_, Mutable, curr, "struct.atomic.rmw field must be mutable");
3101+
shouldBeFalse(
3102+
field.isPacked(), curr, "struct.atomic.rmw field must not be packed");
3103+
bool isAny =
3104+
field.type.isRef() &&
3105+
Type::isSubType(
3106+
field.type,
3107+
Type(HeapTypes::any.getBasic(field.type.getHeapType().getShared()),
3108+
Nullable));
3109+
if (!shouldBeTrue(field.type == Type::i32 || field.type == Type::i64 ||
3110+
(isAny && curr->op == RMWXchg),
3111+
curr,
3112+
"struct.atomic.rmw field type invalid for operation")) {
3113+
return;
3114+
}
30993115
shouldBeSubType(curr->value->type,
31003116
field.type,
31013117
curr,
31023118
"struct.atomic.rmw value must have the proper type");
3103-
shouldBeEqual(
3104-
field.mutable_, Mutable, curr, "struct.atomic.rmw field must be mutable");
31053119
}
31063120

31073121
void FunctionValidator::visitStructCmpxchg(StructCmpxchg* curr) {
@@ -3134,6 +3148,21 @@ void FunctionValidator::visitStructCmpxchg(StructCmpxchg* curr) {
31343148
return;
31353149
}
31363150
auto& field = fields[curr->index];
3151+
shouldBeEqual(
3152+
field.mutable_, Mutable, curr, "struct.atomic.rmw field must be mutable");
3153+
shouldBeFalse(
3154+
field.isPacked(), curr, "struct.atomic.rmw field must not be packed");
3155+
bool isEq =
3156+
field.type.isRef() &&
3157+
Type::isSubType(
3158+
field.type,
3159+
Type(HeapTypes::eq.getBasic(field.type.getHeapType().getShared()),
3160+
Nullable));
3161+
if (!shouldBeTrue(field.type == Type::i32 || field.type == Type::i64 || isEq,
3162+
curr,
3163+
"struct.atomic.rmw field type invalid for operation")) {
3164+
return;
3165+
}
31373166
shouldBeSubType(
31383167
curr->expected->type,
31393168
field.type,
@@ -3144,8 +3173,6 @@ void FunctionValidator::visitStructCmpxchg(StructCmpxchg* curr) {
31443173
field.type,
31453174
curr,
31463175
"struct.atomic.rmw.cmpxchg replacement value must have the proper type");
3147-
shouldBeEqual(
3148-
field.mutable_, Mutable, curr, "struct.atomic.rmw field must be mutable");
31493176
}
31503177

31513178
void FunctionValidator::visitArrayNew(ArrayNew* curr) {

test/spec/shared-struct.wast

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)