Skip to content

Commit e6bbff7

Browse files
authored
Fix shareability of externalized nulls (#6791)
1 parent 5078d4d commit e6bbff7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/wasm/literal.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,11 +2687,12 @@ Literal Literal::relaxedFmsF64x2(const Literal& left,
26872687
Literal Literal::externalize() const {
26882688
assert(type.isRef() && type.getHeapType().getUnsharedTop() == HeapType::any &&
26892689
"can only externalize internal references");
2690+
auto share = type.getHeapType().getShared();
26902691
if (isNull()) {
2691-
return Literal(std::shared_ptr<GCData>{}, HeapType::noext);
2692+
return Literal(std::shared_ptr<GCData>{}, HeapTypes::noext.getBasic(share));
26922693
}
26932694
auto heapType = type.getHeapType();
2694-
auto extType = HeapTypes::ext.getBasic(heapType.getShared());
2695+
auto extType = HeapTypes::ext.getBasic(share);
26952696
if (heapType.isMaybeShared(HeapType::i31)) {
26962697
return Literal(std::make_shared<GCData>(heapType, Literals{*this}),
26972698
extType);

test/spec/convert_extern.wast

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
(ref.null (shared noextern))
66
)
77
)
8+
9+
(func $shared-null-rev (export "shared-null-rev") (result (ref null (shared extern)))
10+
;; As before, but the reverse conversion.
11+
(extern.convert_any
12+
(ref.null (shared any))
13+
)
14+
)
815
)
916

1017
(assert_return (invoke "shared-null") (ref.null (shared any)))
18+
(assert_return (invoke "shared-null-rev") (ref.null (shared extern)))
1119

0 commit comments

Comments
 (0)