From f7677681b0f44a47b3210cabc127999c4c6e1593 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 2 Jun 2026 09:24:20 -0700 Subject: [PATCH 1/5] go --- src/ir/child-typer.h | 5 +- test/lit/basic/gc-atomics-shared.wast | 73 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/lit/basic/gc-atomics-shared.wast diff --git a/src/ir/child-typer.h b/src/ir/child-typer.h index 089b21f86e0..dd0937e2dd1 100644 --- a/src/ir/child-typer.h +++ b/src/ir/child-typer.h @@ -1250,7 +1250,10 @@ template struct ChildTyper : OverriddenVisitor { note(&curr->ref, Type(*ht, Nullable)); note(&curr->index, Type::i32); // TODO: (shared eq) as appropriate. - note(&curr->expected, type.isRef() ? Type(HeapType::eq, Nullable) : type); + note(&curr->expected, + type.isRef() + ? Type(HeapTypes::eq.getBasic(type.getHeapType().getShared()), Nullable) + : type); note(&curr->replacement, type); } diff --git a/test/lit/basic/gc-atomics-shared.wast b/test/lit/basic/gc-atomics-shared.wast new file mode 100644 index 00000000000..bdebfb79015 --- /dev/null +++ b/test/lit/basic/gc-atomics-shared.wast @@ -0,0 +1,73 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; RUN: wasm-opt -all %s -S -o - | filecheck %s + +(module + ;; CHECK: (type $array (shared (array (mut (ref null (shared eq)))))) + (type $array (shared (array (mut (ref null (shared eq)))))) + + ;; CHECK: (global $g (ref $array) (array.new_default $array + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: )) + (global $g (ref $array) (array.new_default $array (i32.const 0))) + + ;; CHECK: (func $test (type $1) (result (ref null (shared eq))) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $g) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (block ;; (replaces unreachable ArrayCmpxchg we can't emit) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (if (result (ref null (shared none))) + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (then + ;; CHECK-NEXT: (ref.null (shared none)) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (else + ;; CHECK-NEXT: (ref.null (shared none)) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $test (result (ref null (shared eq))) + (array.atomic.rmw.cmpxchg acqrel acqrel $array + (global.get $g) + (i32.const 0) + (ref.as_non_null (ref.null none)) + (if (result (ref null (shared eq))) + (block + (drop (ref.as_non_null (ref.null none))) + (unreachable) + ) + (then (ref.null (shared eq))) + (else (ref.null (shared eq))) + ) + ) + ) +) + From 7737133dc67f8a5a19c17252fdf67ddb1dddcd45 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 2 Jun 2026 09:29:47 -0700 Subject: [PATCH 2/5] fix --- test/lit/basic/gc-atomics-shared.wast | 29 +++++---------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/test/lit/basic/gc-atomics-shared.wast b/test/lit/basic/gc-atomics-shared.wast index bdebfb79015..668c32cd03e 100644 --- a/test/lit/basic/gc-atomics-shared.wast +++ b/test/lit/basic/gc-atomics-shared.wast @@ -2,6 +2,9 @@ ;; RUN: wasm-opt -all %s -S -o - | filecheck %s +;; Check that we properly validate array.atomic.rmw.cmpxchg of a shared array, +;; when the instruction is unreachable. + (module ;; CHECK: (type $array (shared (array (mut (ref null (shared eq)))))) (type $array (shared (array (mut (ref null (shared eq)))))) @@ -25,22 +28,7 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; (replaces unreachable ArrayCmpxchg we can't emit) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (if (result (ref null (shared none))) - ;; CHECK-NEXT: (block - ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (ref.as_non_null - ;; CHECK-NEXT: (ref.null none) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (unreachable) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (then - ;; CHECK-NEXT: (ref.null (shared none)) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (else - ;; CHECK-NEXT: (ref.null (shared none)) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (unreachable) @@ -59,14 +47,7 @@ (global.get $g) (i32.const 0) (ref.as_non_null (ref.null none)) - (if (result (ref null (shared eq))) - (block - (drop (ref.as_non_null (ref.null none))) - (unreachable) - ) - (then (ref.null (shared eq))) - (else (ref.null (shared eq))) - ) + (unreachable) ) ) ) From 29e7baa7be5c497c3fa62d089af3208642fb0b40 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 2 Jun 2026 09:29:53 -0700 Subject: [PATCH 3/5] form --- src/ir/child-typer.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ir/child-typer.h b/src/ir/child-typer.h index dd0937e2dd1..0e2edc400fd 100644 --- a/src/ir/child-typer.h +++ b/src/ir/child-typer.h @@ -1250,10 +1250,11 @@ template struct ChildTyper : OverriddenVisitor { note(&curr->ref, Type(*ht, Nullable)); note(&curr->index, Type::i32); // TODO: (shared eq) as appropriate. - note(&curr->expected, - type.isRef() - ? Type(HeapTypes::eq.getBasic(type.getHeapType().getShared()), Nullable) - : type); + note( + &curr->expected, + type.isRef() + ? Type(HeapTypes::eq.getBasic(type.getHeapType().getShared()), Nullable) + : type); note(&curr->replacement, type); } From 870c5915cbc595b14e678d14910216b387ddd7f7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 2 Jun 2026 11:32:52 -0700 Subject: [PATCH 4/5] cleanup --- src/ir/child-typer.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ir/child-typer.h b/src/ir/child-typer.h index 0e2edc400fd..5a374f89b8e 100644 --- a/src/ir/child-typer.h +++ b/src/ir/child-typer.h @@ -1249,7 +1249,6 @@ template struct ChildTyper : OverriddenVisitor { Type type = ht->getArray().element.type; note(&curr->ref, Type(*ht, Nullable)); note(&curr->index, Type::i32); - // TODO: (shared eq) as appropriate. note( &curr->expected, type.isRef() From 500c60eec74a8954005a7a002ea673069bf649ff Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 2 Jun 2026 11:33:53 -0700 Subject: [PATCH 5/5] cleanup --- test/lit/basic/gc-atomics-shared.wast | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/lit/basic/gc-atomics-shared.wast b/test/lit/basic/gc-atomics-shared.wast index 668c32cd03e..818239c1569 100644 --- a/test/lit/basic/gc-atomics-shared.wast +++ b/test/lit/basic/gc-atomics-shared.wast @@ -2,8 +2,9 @@ ;; RUN: wasm-opt -all %s -S -o - | filecheck %s -;; Check that we properly validate array.atomic.rmw.cmpxchg of a shared array, -;; when the instruction is unreachable. +;; Check that we properly parse array.atomic.rmw.cmpxchg of a shared array, +;; when the instruction is unreachable (when the the expected field does not +;; have the correct sharedness). (module ;; CHECK: (type $array (shared (array (mut (ref null (shared eq))))))