diff --git a/scripts/test/fuzzing.py b/scripts/test/fuzzing.py index 0f4a1befa74..0bbfbcd9717 100644 --- a/scripts/test/fuzzing.py +++ b/scripts/test/fuzzing.py @@ -105,6 +105,7 @@ 'exact-references.wast', 'optimize-instructions-exact.wast', 'local-subtyping-exact.wast', + 'remove-unused-types-exact.wast', ] diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp index b90d8eb8790..cba761465b3 100644 --- a/src/ir/type-updating.cpp +++ b/src/ir/type-updating.cpp @@ -205,7 +205,9 @@ void GlobalTypeRewriter::mapTypes(const TypeMap& oldToNewTypes) { Type getNew(Type type) { if (type.isRef()) { - return Type(getNew(type.getHeapType()), type.getNullability()); + return Type(getNew(type.getHeapType()), + type.getNullability(), + type.getExactness()); } if (type.isTuple()) { auto tuple = type.getTuple(); diff --git a/src/wasm-type.h b/src/wasm-type.h index f09e1e440fe..a33a2bed907 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -709,7 +709,8 @@ struct TypeBuilder { return t; } assert(t.isRef()); - return getTempRefType(map(t.getHeapType()), t.getNullability()); + return getTempRefType( + map(t.getHeapType()), t.getNullability(), t.getExactness()); }; auto copyType = [&](Type t) -> Type { if (t.isTuple()) { diff --git a/test/lit/passes/remove-unused-types-exact.wast b/test/lit/passes/remove-unused-types-exact.wast new file mode 100644 index 00000000000..6cb9c1ddd74 --- /dev/null +++ b/test/lit/passes/remove-unused-types-exact.wast @@ -0,0 +1,16 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; RUN: wasm-opt %s -all --closed-world --remove-unused-types -S -o - | filecheck %s + +;; Test that a simple type rewrite handles exact references in heap type +;; definitions correctly. In particular, the function should continue returning +;; an exact nullref and the call expression should have the same type. + +(module + ;; CHECK: (func $return-exact (type $0) (result (exact nullref)) + ;; CHECK-NEXT: (call $return-exact) + ;; CHECK-NEXT: ) + (func $return-exact (result (exact nullref)) + (call $return-exact) + ) +)