Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[threads] Handle shared i31 in Builder::makeConstantExpression
  • Loading branch information
tlively committed Jul 16, 2024
commit 27ca9bfece408f18cc650cdace26bb421e5c170c
6 changes: 4 additions & 2 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,10 @@ class Builder {
if (type.isFunction()) {
return makeRefFunc(value.getFunc(), type.getHeapType());
}
if (type.isRef() && type.getHeapType() == HeapType::i31) {
return makeRefI31(makeConst(value.geti31()));
if (type.isRef() && type.getHeapType().isBasic() &&
type.getHeapType().getBasic(Unshared) == HeapType::i31) {
return makeRefI31(makeConst(value.geti31()),
type.getHeapType().getShared());
}
if (type.isString()) {
// The string is already WTF-16, but we need to convert from `Literals` to
Expand Down
38 changes: 38 additions & 0 deletions test/lit/ctor-eval/shared-i31.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: wasm-ctor-eval %s --ctors=test --kept-exports=test,other --quiet -all -S -o - | filecheck %s

;; We should be able to update `global` with a proper shared i31 reference.

(module
;; CHECK: (type $0 (func (result (ref null (shared any)))))

;; CHECK: (global $global (mut (ref null (shared i31))) (ref.i31_shared
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: ))
(global $global (mut (ref null (shared i31))) (ref.null (shared none)))

(func $test (export "test") (result (ref null (shared any)))
(global.set $global
(ref.i31_shared
(i32.const 42)
)
)
(global.get $global)
)

;; CHECK: (export "test" (func $test_2))

;; CHECK: (export "other" (func $other))

;; CHECK: (func $other (type $0) (result (ref null (shared any)))
;; CHECK-NEXT: (global.get $global)
;; CHECK-NEXT: )
(func $other (export "other") (result (ref null (shared any)))
(global.get $global)
)
)
;; CHECK: (func $test_2 (type $0) (result (ref null (shared any)))
;; CHECK-NEXT: (ref.i31_shared
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: )
;; CHECK-NEXT: )