Skip to content

Commit fcea593

Browse files
authored
[GC][Threads] Atomic GC operations require --enable-threads (#7185)
Without this, it is invalid to lower them to simpler atomic operations like atomic.fence (as some passes do) or linear memory atomics (as a future lowering pass might do). Fixes #7184
1 parent 1faa606 commit fcea593

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717

18+
- `struct.atomic.get`/`struct.atomic.set` now require the threads feature,
19+
`--enable-threads`. (#7185)
20+
1821
v121
1922
----
2023

src/wasm/wasm-validator.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,11 +2989,15 @@ void FunctionValidator::visitStructGet(StructGet* curr) {
29892989
shouldBeTrue(getModule()->features.hasGC(),
29902990
curr,
29912991
"struct.get requires gc [--enable-gc]");
2992-
shouldBeTrue(curr->order == MemoryOrder::Unordered ||
2993-
getModule()->features.hasSharedEverything(),
2994-
curr,
2995-
"struct.atomic.get requires shared-everything "
2996-
"[--enable-shared-everything]");
2992+
if (curr->order != MemoryOrder::Unordered) {
2993+
shouldBeTrue(getModule()->features.hasSharedEverything(),
2994+
curr,
2995+
"struct.atomic.get requires shared-everything "
2996+
"[--enable-shared-everything]");
2997+
shouldBeTrue(getModule()->features.hasAtomics(),
2998+
curr,
2999+
"struct.atomic.get requires threads [--enable-threads]");
3000+
}
29973001
if (curr->type == Type::unreachable || curr->ref->type.isNull()) {
29983002
return;
29993003
}
@@ -3021,11 +3025,15 @@ void FunctionValidator::visitStructSet(StructSet* curr) {
30213025
shouldBeTrue(getModule()->features.hasGC(),
30223026
curr,
30233027
"struct.set requires gc [--enable-gc]");
3024-
shouldBeTrue(curr->order == MemoryOrder::Unordered ||
3025-
getModule()->features.hasSharedEverything(),
3026-
curr,
3027-
"struct.atomic.set requires shared-everything "
3028-
"[--enable-shared-everything]");
3028+
if (curr->order != MemoryOrder::Unordered) {
3029+
shouldBeTrue(getModule()->features.hasSharedEverything(),
3030+
curr,
3031+
"struct.atomic.set requires shared-everything "
3032+
"[--enable-shared-everything]");
3033+
shouldBeTrue(getModule()->features.hasAtomics(),
3034+
curr,
3035+
"struct.atomic.set requires threads [--enable-threads]");
3036+
}
30293037
if (curr->ref->type == Type::unreachable) {
30303038
return;
30313039
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
;; Test that shared-everything GC instructions require the shared-everything
22
;; feature.
33

4-
;; RUN: not wasm-opt -all --disable-shared-everything %s 2>&1 | filecheck %s
4+
;; RUN: not wasm-opt -all --disable-shared-everything --disable-threads %s 2>&1 | filecheck %s
55

66
(module
77
(type $struct (struct (field (mut i32))))
88

99
;; CHECK: struct.atomic.get requires shared-everything [--enable-shared-everything]
10+
;; CHECK: struct.atomic.get requires threads [--enable-threads]
1011
(func $get-seqcst (result i32)
1112
(struct.atomic.get seqcst $struct 0
1213
(struct.new_default $struct)
1314
)
1415
)
1516

1617
;; CHECK: struct.atomic.get requires shared-everything [--enable-shared-everything]
18+
;; CHECK: struct.atomic.get requires threads [--enable-threads]
1719
(func $get-acqrel (result i32)
1820
(struct.atomic.get acqrel $struct 0
1921
(struct.new_default $struct)
2022
)
2123
)
2224

2325
;; CHECK: struct.atomic.set requires shared-everything [--enable-shared-everything]
26+
;; CHECK: struct.atomic.set requires threads [--enable-threads]
2427
(func $set-seqcst
2528
(struct.atomic.set seqcst $struct 0
2629
(struct.new_default $struct)
@@ -29,10 +32,11 @@
2932
)
3033

3134
;; CHECK: struct.atomic.set requires shared-everything [--enable-shared-everything]
35+
;; CHECK: struct.atomic.set requires threads [--enable-threads]
3236
(func $set-acqrel
3337
(struct.atomic.set acqrel $struct 0
3438
(struct.new_default $struct)
3539
(i32.const 0)
3640
)
3741
)
38-
)
42+
)

0 commit comments

Comments
 (0)