summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-binary.cpp12
-rw-r--r--test/lit/downgrade-reftypes.wast14
2 files changed, 23 insertions, 3 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 1d0e99415..7b3f741b6 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1401,9 +1401,15 @@ void WasmBinaryWriter::writeType(Type type) {
o << S32LEB(BinaryConsts::EncodedType::funcref);
return;
}
- assert(Type::isSubType(type, Type(HeapType::ext, Nullable)));
- o << S32LEB(BinaryConsts::EncodedType::externref);
- return;
+ if (Type::isSubType(type, Type(HeapType::ext, Nullable))) {
+ o << S32LEB(BinaryConsts::EncodedType::externref);
+ return;
+ }
+ if (Type::isSubType(type, Type(HeapType::string, Nullable))) {
+ o << S32LEB(BinaryConsts::EncodedType::stringref);
+ return;
+ }
+ WASM_UNREACHABLE("bad type without GC");
}
auto heapType = type.getHeapType();
if (heapType.isBasic() && type.isNullable()) {
diff --git a/test/lit/downgrade-reftypes.wast b/test/lit/downgrade-reftypes.wast
index 94343933f..5bc9af653 100644
--- a/test/lit/downgrade-reftypes.wast
+++ b/test/lit/downgrade-reftypes.wast
@@ -33,6 +33,13 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (block $label$4 (result stringref)
+ ;; CHECK-NEXT: (br $label$4
+ ;; CHECK-NEXT: (string.const "hello world")
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $foo (type $f)
(drop
@@ -57,5 +64,12 @@
)
)
)
+ (drop
+ (block $l4 (result (ref string))
+ (br $l4
+ (string.const "hello world")
+ )
+ )
+ )
)
)