diff --git a/scripts/test/fuzzing.py b/scripts/test/fuzzing.py index 8ddc4982563..96121d4649e 100644 --- a/scripts/test/fuzzing.py +++ b/scripts/test/fuzzing.py @@ -114,6 +114,7 @@ 'exact-references-lowering.wast', 'exact-casts.wast', 'exact-casts-trivial.wast', + 'abstract-type-refining-exact.wast', 'optimize-instructions-exact.wast', 'optimize-instructions-all-casts.wast', 'optimize-instructions-all-casts-exact.wast', diff --git a/src/wasm-type.h b/src/wasm-type.h index 4ecbf6ab379..579d65e727a 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -418,8 +418,12 @@ class Type { } // Return a new reference type with some part updated to the specified value. + // Always clear exactness when replacing the referenced type with a basic heap + // type to avoid creating an invalid type. Type with(HeapType heapType) const { - return Type(heapType, getNullability(), getExactness()); + return Type(heapType, + getNullability(), + heapType.isBasic() ? Inexact : getExactness()); } Type with(Nullability nullability) const { return Type(getHeapType(), nullability, getExactness()); diff --git a/test/lit/passes/abstract-type-refining-exact.wast b/test/lit/passes/abstract-type-refining-exact.wast new file mode 100644 index 00000000000..dec05e0f328 --- /dev/null +++ b/test/lit/passes/abstract-type-refining-exact.wast @@ -0,0 +1,18 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. + +;; RUN: wasm-opt %s -all --closed-world --abstract-type-refining -S -o - | filecheck %s + +(module + ;; CHECK: (rec + ;; CHECK-NEXT: (type $foo (struct)) + (type $foo (struct)) + + ;; CHECK: (func $test (type $1) + ;; CHECK-NEXT: (local $0 (ref none)) + ;; CHECK-NEXT: ) + (func $test + ;; $foo will be replaced with none` and the exactness should be dropped + ;; without errors. + (local (ref (exact $foo))) + ) +)