diff options
author | Alon Zakai <azakai@google.com> | 2023-03-03 08:05:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-03 16:05:03 +0000 |
commit | dc8f514bfa4617861b51b6cef23af73464d3b650 (patch) | |
tree | 18ebd30693bcf3ea37dedc25895e0fdcb9d52ec7 | |
parent | 9042f84e213c843d85a90c39ee3006a4d5e4c7a1 (diff) | |
download | binaryen-dc8f514bfa4617861b51b6cef23af73464d3b650.tar.gz binaryen-dc8f514bfa4617861b51b6cef23af73464d3b650.tar.bz2 binaryen-dc8f514bfa4617861b51b6cef23af73464d3b650.zip |
getHeapTypeCounts() must note select types for references (#5540)
Without this we hit an assertion on trying to write the binary, on a missing
heap type.
-rw-r--r-- | src/ir/module-utils.cpp | 3 | ||||
-rw-r--r-- | test/lit/passes/gufa-vs-cfp.wast | 4 | ||||
-rw-r--r-- | test/lit/select-gc.wat | 26 |
3 files changed, 31 insertions, 2 deletions
diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp index a6d2633ff..a2abcd5b5 100644 --- a/src/ir/module-utils.cpp +++ b/src/ir/module-utils.cpp @@ -63,6 +63,9 @@ struct CodeScanner counts.note(call->target->type); } else if (curr->is<RefNull>()) { counts.note(curr->type); + } else if (curr->is<Select>() && curr->type.isRef()) { + // This select will be annotated in the binary, so note it. + counts.note(curr->type); } else if (curr->is<StructNew>()) { counts.note(curr->type); } else if (curr->is<ArrayNew>()) { diff --git a/test/lit/passes/gufa-vs-cfp.wast b/test/lit/passes/gufa-vs-cfp.wast index 0a678af4f..a2fb8f5df 100644 --- a/test/lit/passes/gufa-vs-cfp.wast +++ b/test/lit/passes/gufa-vs-cfp.wast @@ -679,12 +679,12 @@ ;; Subtyping: Create both a subtype and a supertype, with identical constants ;; for the shared field, and get the supertype. (module + ;; CHECK: (type $struct (struct (field i32))) + (type $struct (struct i32)) ;; CHECK: (type $none_=>_i32 (func (result i32))) ;; CHECK: (type $none_=>_none (func)) - ;; CHECK: (type $struct (struct (field i32))) - (type $struct (struct i32)) ;; CHECK: (type $substruct (struct_subtype (field i32) (field f64) $struct)) (type $substruct (struct_subtype i32 f64 $struct)) diff --git a/test/lit/select-gc.wat b/test/lit/select-gc.wat new file mode 100644 index 000000000..8cc1d4ca7 --- /dev/null +++ b/test/lit/select-gc.wat @@ -0,0 +1,26 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; RUN: wasm-opt -all --roundtrip %s -S -o - | filecheck %s + +;; Check that annotated select is propery roundtripped, even if the type is +;; only used in that one place in the whole module. + +(module + ;; CHECK: (type $struct (struct )) + (type $struct (struct)) + + ;; CHECK: (func $foo (type $none_=>_anyref) (result anyref) + ;; CHECK-NEXT: (select (result (ref null $struct)) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $foo (result anyref) + (select (result (ref null $struct)) + (ref.null any) + (ref.null eq) + (i32.const 1) + ) + ) +) |