diff options
author | Thomas Lively <tlively@google.com> | 2023-10-02 13:12:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 13:12:38 -0700 |
commit | 77f36789aac707d1d5daed20e6e7612c9a9af51b (patch) | |
tree | b05d54a5164711c1b2807b9c5e5e54206627938e /src | |
parent | d49f518eee07d9c267a32ca9443069255b4cbd1f (diff) | |
download | binaryen-77f36789aac707d1d5daed20e6e7612c9a9af51b.tar.gz binaryen-77f36789aac707d1d5daed20e6e7612c9a9af51b.tar.bz2 binaryen-77f36789aac707d1d5daed20e6e7612c9a9af51b.zip |
Refine ref.test's castType during refinalization (#5985)
Just like we do with other casts, refine the cast type to be the greatest lower
bound of its previous cast type and its input type. The difference is that the
output type of ref.test remains i32, but it's still useful to retain more
precise type information.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 3baaacb16..a8bb4a536 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2549,6 +2549,10 @@ void FunctionValidator::visitRefTest(RefTest* curr) { curr->ref->type.isRef(), curr, "ref.test ref must have ref type")) { return; } + if (!shouldBeTrue( + curr->castType.isRef(), curr, "ref.test target must have ref type")) { + return; + } shouldBeEqual( curr->castType.getHeapType().getBottom(), curr->ref->type.getHeapType().getBottom(), diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 52a09e90c..21dc6e25e 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -953,6 +953,8 @@ void RefTest::finalize() { type = Type::unreachable; } else { type = Type::i32; + // Do not unnecessarily lose type information. + castType = Type::getGreatestLowerBound(castType, ref->type); } } |