From 013a8d346807da751fec283eddf86aee9ea28382 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 22 Nov 2024 14:21:54 -0800 Subject: Print castType for unreachable br_on_cast{_fail} (#7107) I forgot that there is a validation rule that the output type for br_on_cast and br_on_cast_fail must be a subtype of the input type. We were previously printing bottom input types in cases where the cast operand was unreachable, but that's only valid if the cast type is the same bottom type. Instead print the most precise valid input type, which is the cast type itself. --- src/passes/Print.cpp | 10 ++++------ test/lit/wat-kitchen-sink.wast | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 0b15477ee..bbf5f2a6b 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2229,10 +2229,9 @@ struct PrintExpressionContents o << ' '; if (curr->ref->type == Type::unreachable) { // Need to print some reference type in the correct hierarchy rather - // than unreachable, and the bottom type is valid in the most - // contexts. - printType( - Type(curr->castType.getHeapType().getBottom(), NonNullable)); + // than unreachable, and the cast type itself is the best possible + // option. + printType(curr->castType); } else { printType(curr->ref->type); } @@ -2244,8 +2243,7 @@ struct PrintExpressionContents curr->name.print(o); o << ' '; if (curr->ref->type == Type::unreachable) { - printType( - Type(curr->castType.getHeapType().getBottom(), NonNullable)); + printType(curr->castType); } else { printType(curr->ref->type); } diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index 52cb2ca1d..33d2e1d62 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -4086,7 +4086,7 @@ ;; CHECK-NEXT: (block $block (result i31ref) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (block (result (ref any)) - ;; CHECK-NEXT: (br_on_cast $block (ref none) i31ref + ;; CHECK-NEXT: (br_on_cast $block i31ref i31ref ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) @@ -4136,7 +4136,7 @@ ;; CHECK-NEXT: (block $block (result (ref any)) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (block (result i31ref) - ;; CHECK-NEXT: (br_on_cast_fail $block (ref none) i31ref + ;; CHECK-NEXT: (br_on_cast_fail $block i31ref i31ref ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) -- cgit v1.2.3