summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/fuzz_opt.py1
-rw-r--r--src/wasm/wasm-binary.cpp15
-rw-r--r--test/lit/basic/shared-null-no-gc.wast19
3 files changed, 21 insertions, 14 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index b9d42d634..a591f9414 100755
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -361,6 +361,7 @@ INITIAL_CONTENTS_IGNORE = [
'shared-absheaptype.wast',
'type-ssa-shared.wast',
'shared-ref_eq.wast',
+ 'shared-null-no-gc.wast',
]
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index ee8afeb93..d35edadc8 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1629,20 +1629,7 @@ void WasmBinaryWriter::writeHeapType(HeapType type) {
// 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 if (HeapType::isSubType(type, HeapType::ext)) {
- type = HeapType::ext;
- } else if (HeapType::isSubType(type, HeapType::exn)) {
- type = HeapType::exn;
- } 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");
- }
+ type = type.getTop();
}
if (!type.isBasic()) {
diff --git a/test/lit/basic/shared-null-no-gc.wast b/test/lit/basic/shared-null-no-gc.wast
new file mode 100644
index 000000000..b920f80f8
--- /dev/null
+++ b/test/lit/basic/shared-null-no-gc.wast
@@ -0,0 +1,19 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+
+;; Test that we can write a binary without crashing when using a shared bottom
+;; type without GC enabled.
+
+;; RUN: wasm-opt %s --enable-reference-types --enable-shared-everything --roundtrip -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (func $test
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (ref.null (shared nofunc))
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test
+ (drop
+ (ref.null (shared func))
+ )
+ )
+)