Skip to content

Commit d2d5135

Browse files
authored
Fix issues with ref.cast_nop (#5473)
It did not have proper annotation for the safety field, and also it could not handle basic heap types.
1 parent f8261ba commit d2d5135

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/wasm-delegations-fields.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ switch (DELEGATE_ID) {
620620
}
621621
case Expression::Id::RefCastId: {
622622
DELEGATE_START(RefCast);
623+
DELEGATE_FIELD_INT(RefCast, safety);
623624
DELEGATE_FIELD_CHILD(RefCast, ref);
624625
DELEGATE_END(RefCast);
625626
break;

src/wasm/wasm-binary.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6935,8 +6935,7 @@ void WasmBinaryBuilder::visitRefAsCast(RefCast* curr, uint32_t code) {
69356935
bool WasmBinaryBuilder::maybeVisitRefCast(Expression*& out, uint32_t code) {
69366936
if (code == BinaryConsts::RefCastStatic || code == BinaryConsts::RefCast ||
69376937
code == BinaryConsts::RefCastNull || code == BinaryConsts::RefCastNop) {
6938-
bool legacy =
6939-
code == BinaryConsts::RefCastStatic || code == BinaryConsts::RefCastNop;
6938+
bool legacy = code == BinaryConsts::RefCastStatic;
69406939
auto heapType = legacy ? getIndexedHeapType() : getHeapType();
69416940
auto* ref = popNonVoidExpression();
69426941
Nullability nullability;

src/wasm/wasm-stack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ void BinaryInstWriter::visitRefCast(RefCast* curr) {
20362036
o << int8_t(BinaryConsts::GCPrefix);
20372037
if (curr->safety == RefCast::Unsafe) {
20382038
o << U32LEB(BinaryConsts::RefCastNop);
2039-
parent.writeIndexedHeapType(curr->type.getHeapType());
2039+
parent.writeHeapType(curr->type.getHeapType());
20402040
} else {
20412041
// TODO: These instructions are deprecated. Remove them.
20422042
if (auto type = curr->type.getHeapType();

test/lit/ref-cast-nop.wast

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@
1515
(local.get $x)
1616
)
1717
)
18+
19+
;; CHECK: (func $ref.cast_nop.null (type $ref|any|_=>_ref|none|) (param $x (ref any)) (result (ref none))
20+
;; CHECK-NEXT: (ref.cast_nop none
21+
;; CHECK-NEXT: (local.get $x)
22+
;; CHECK-NEXT: )
23+
;; CHECK-NEXT: )
24+
(func $ref.cast_nop.null (param $x (ref any)) (result (ref none))
25+
(ref.cast_nop none
26+
(local.get $x)
27+
)
28+
)
1829
)

0 commit comments

Comments
 (0)