diff options
author | Alon Zakai <azakai@google.com> | 2023-07-31 09:53:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-31 16:53:48 +0000 |
commit | 1ac8770aee26a221c86a7fe92194a06f5c094070 (patch) | |
tree | c164308e8eef69b6e721e492a4443bf1fc3a044b | |
parent | b1e23ca6a1b930421279141ed06e94300eddcf17 (diff) | |
download | binaryen-1ac8770aee26a221c86a7fe92194a06f5c094070.tar.gz binaryen-1ac8770aee26a221c86a7fe92194a06f5c094070.tar.bz2 binaryen-1ac8770aee26a221c86a7fe92194a06f5c094070.zip |
Fix binary writing of strings without GC enabled (#5836)
-rw-r--r-- | src/wasm/wasm-binary.cpp | 14 | ||||
-rw-r--r-- | test/lit/binary/strings-nogc.test | 12 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 639f4b848..3ceab828b 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1519,14 +1519,20 @@ void WasmBinaryWriter::writeType(Type type) { void WasmBinaryWriter::writeHeapType(HeapType type) { // ref.null always has a bottom heap type in Binaryen IR, but those types are - // only actually valid with GC enabled. When GC is not enabled, emit the - // corresponding valid top types instead. + // only actually valid with GC. Otherwise, emit the corresponding valid top + // types instead. if (!wasm->features.hasGC()) { if (HeapType::isSubType(type, HeapType::func)) { type = HeapType::func; - } else { - assert(HeapType::isSubType(type, HeapType::ext)); + } else if (HeapType::isSubType(type, HeapType::ext)) { type = HeapType::ext; + } else if (wasm->features.hasStrings()) { + // Strings are enabled, and this isn't a func or an ext, so it must be a + // string type (string or stringview), which we'll emit below, or a bottom + // type (which we must allow, because we wouldn't know whether to emit a + // string or stringview for it). + } else { + WASM_UNREACHABLE("invalid type without GC"); } } diff --git a/test/lit/binary/strings-nogc.test b/test/lit/binary/strings-nogc.test new file mode 100644 index 000000000..7aa21d750 --- /dev/null +++ b/test/lit/binary/strings-nogc.test @@ -0,0 +1,12 @@ +;; Verify that we support strings in the binary format even without GC. + +;; RUN: wasm-opt --enable-reference-types --enable-strings --roundtrip %s + +(module + (func $0 + (local $0 stringref) + (local.set $0 + (ref.null none) + ) + ) +) |