Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,10 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
VISIT(expected, curr->expected)
VISIT(timeout, curr->timeout)

if (!curr->ref->type.getHeapType().isShared()) {
trap("cannot struct.wait a non-shared object");
}

auto data = ref.getSingleValue().getGCData();
if (!data) {
trap("null ref");
Expand Down
15 changes: 14 additions & 1 deletion test/spec/waitqueue.wast
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
)

(module
(type $t (struct (field (mut waitqueue))))
(type $t (shared (struct (field (mut waitqueue)))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to at least add a TODO for adding a test for the trap-on-unshared behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a full spec test and removed the exec test.


(global $g (mut (ref null $t)) (struct.new $t (i32.const 0)))

Expand Down Expand Up @@ -117,3 +117,16 @@

(assert_trap (invoke "struct.wait" (i32.const 0) (i64.const 0)) "null ref")
(assert_trap (invoke "struct.notify" (i32.const 0)) "null ref")

;; Waiting on a non-shared struct should trap.
(module
(type $t (struct (field (mut waitqueue))))

(global $g (mut (ref null $t)) (struct.new $t (i32.const 0)))

(func (export "struct.wait") (param $expected i32) (param $timeout i64) (result i32)
(struct.wait $t 0 (global.get $g) (local.get $expected) (local.get $timeout))
)
)
(assert_trap (invoke "struct.wait" (i32.const 0) (i64.const 100)) "not shared")

Loading