Skip to content

Avoid errors in Type::with(HeapType) #7551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/test/fuzzing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment about basic types and exactness here I think.

return Type(heapType, getNullability(), getExactness());
return Type(heapType,
getNullability(),
heapType.isBasic() ? Inexact : getExactness());
}
Type with(Nullability nullability) const {
return Type(getHeapType(), nullability, getExactness());
Expand Down
18 changes: 18 additions & 0 deletions test/lit/passes/abstract-type-refining-exact.wast
Original file line number Diff line number Diff line change
@@ -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)))
)
)
Loading