diff options
author | Alon Zakai <azakai@google.com> | 2023-01-09 09:29:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 09:29:21 -0800 |
commit | c049a24c12cc9420f2a6e13bc4b1549922ec5d1f (patch) | |
tree | 1d0e825e5c032c03da32eb746d2ca72ef29acc4b | |
parent | dea55e161497b9c7beaaa9fb3cdff003060ac391 (diff) | |
download | binaryen-c049a24c12cc9420f2a6e13bc4b1549922ec5d1f.tar.gz binaryen-c049a24c12cc9420f2a6e13bc4b1549922ec5d1f.tar.bz2 binaryen-c049a24c12cc9420f2a6e13bc4b1549922ec5d1f.zip |
[Wasm GC] Add missing unreachable check in evaluateKindCheck (#5410)
-rw-r--r-- | src/ir/gc-type-utils.h | 4 | ||||
-rw-r--r-- | test/lit/passes/optimize-instructions-gc.wast | 21 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/ir/gc-type-utils.h b/src/ir/gc-type-utils.h index 8832d4d0f..1646e47c3 100644 --- a/src/ir/gc-type-utils.h +++ b/src/ir/gc-type-utils.h @@ -123,7 +123,9 @@ inline EvaluationResult evaluateKindCheck(Expression* curr) { Kind actual; - if (childType.isFunction()) { + if (childType == Type::unreachable) { + return Unknown; + } else if (childType.isFunction()) { actual = Func; } else if (childType.isData()) { actual = Data; diff --git a/test/lit/passes/optimize-instructions-gc.wast b/test/lit/passes/optimize-instructions-gc.wast index abf3da432..c5100434d 100644 --- a/test/lit/passes/optimize-instructions-gc.wast +++ b/test/lit/passes/optimize-instructions-gc.wast @@ -3230,4 +3230,25 @@ ) ) ) + + ;; CHECK: (func $as_of_unreachable (type $none_=>_ref|data|) (result (ref data)) + ;; CHECK-NEXT: (ref.as_data + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; NOMNL: (func $as_of_unreachable (type $none_=>_ref|data|) (result (ref data)) + ;; NOMNL-NEXT: (ref.as_data + ;; NOMNL-NEXT: (unreachable) + ;; NOMNL-NEXT: ) + ;; NOMNL-NEXT: ) + (func $as_of_unreachable (result (ref data)) + ;; The cast will definitely fail, so we can turn it into an unreachable. The + ;; ref.as must then ignore the unreachable input and not error on trying to + ;; infer anything about it. + (ref.as_data + (ref.cast $A + (ref.null none) + ) + ) + ) ) |