summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-11-21 15:55:52 -0800
committerGitHub <noreply@github.com>2024-11-21 15:55:52 -0800
commit7b12353fb2ef0240dd8bb3e6aaa764bc8408f9ad (patch)
treee2232de255f94ba6b1710f3e8ea6ee80b2c21b9e /src/passes/Print.cpp
parent4488a3e351214e038600f58e5806c31ad0bfae46 (diff)
downloadbinaryen-7b12353fb2ef0240dd8bb3e6aaa764bc8408f9ad.tar.gz
binaryen-7b12353fb2ef0240dd8bb3e6aaa764bc8408f9ad.tar.bz2
binaryen-7b12353fb2ef0240dd8bb3e6aaa764bc8408f9ad.zip
Fix printing of unreachable br_on_cast{_fail} (#7102)
br_on_cast and br_on_cast_fail have two type annotations: one for their input type and one for their cast type. In cases where their operands were unreachable, we were previously printing "unreachable" for the input type annotation. This is not valid wat because "unreachable" is not a reference type. To fix the problem, print the bottom type of the cast type's hierarchy as the input type for br_on_cast and br_on_cast_fail when the operand is unreachable. This ensures that the instructions have the most precise possible output type according to Wasm typing rules, so it maximizes the number of contexts in which the printed instructions are valid.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 5a5d01299..5c8463f78 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2219,7 +2219,15 @@ struct PrintExpressionContents
printMedium(o, "br_on_cast ");
curr->name.print(o);
o << ' ';
- printType(curr->ref->type);
+ 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));
+ } else {
+ printType(curr->ref->type);
+ }
o << ' ';
printType(curr->castType);
return;
@@ -2227,7 +2235,12 @@ struct PrintExpressionContents
printMedium(o, "br_on_cast_fail ");
curr->name.print(o);
o << ' ';
- printType(curr->ref->type);
+ if (curr->ref->type == Type::unreachable) {
+ printType(
+ Type(curr->castType.getHeapType().getBottom(), NonNullable));
+ } else {
+ printType(curr->ref->type);
+ }
o << ' ';
printType(curr->castType);
return;