diff options
author | Thomas Lively <tlively@google.com> | 2024-04-11 09:22:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-11 09:22:04 -0700 |
commit | adea6e0f80c68108691f28ab4aa81b8f8973ac35 (patch) | |
tree | f14db2e43e7307a3472e297e014f109b8fb28f7c | |
parent | dd092420b9468450fa7cbded8adbdc8489857a0e (diff) | |
download | binaryen-adea6e0f80c68108691f28ab4aa81b8f8973ac35.tar.gz binaryen-adea6e0f80c68108691f28ab4aa81b8f8973ac35.tar.bz2 binaryen-adea6e0f80c68108691f28ab4aa81b8f8973ac35.zip |
Ensure printed tuple.extract arity is valid (#6487)
We previously printed the size of the tuple operand as the arity, but that
printed `1` when the operand is unreachable. We don't allow our text input to
use `1` as the arity, so don't print it, either. Instead, print the smallest
valid arity, `2`, in this case.
-rw-r--r-- | src/passes/Print.cpp | 7 | ||||
-rw-r--r-- | test/lit/passes/optimize-instructions-multivalue.wast | 2 | ||||
-rw-r--r-- | test/lit/passes/tuple-optimization.wast | 4 |
3 files changed, 9 insertions, 4 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 80047a281..68a2e4cb6 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -18,6 +18,8 @@ // Print out text in s-expression format // +#include <algorithm> + #include <ir/iteration.h> #include <ir/module-utils.h> #include <ir/table-utils.h> @@ -2016,7 +2018,10 @@ struct PrintExpressionContents } void visitTupleExtract(TupleExtract* curr) { printMedium(o, "tuple.extract "); - o << curr->tuple->type.size() << " "; + // If the tuple is unreachable, its size will be reported as 1, but that's + // not a valid tuple size. The size we print mostly doesn't matter if the + // tuple is unreachable, but it does have to be valid. + o << std::max(curr->tuple->type.size(), size_t(2)) << " "; o << curr->index; } void visitRefI31(RefI31* curr) { printMedium(o, "ref.i31"); } diff --git a/test/lit/passes/optimize-instructions-multivalue.wast b/test/lit/passes/optimize-instructions-multivalue.wast index 42b2223ab..636ef190c 100644 --- a/test/lit/passes/optimize-instructions-multivalue.wast +++ b/test/lit/passes/optimize-instructions-multivalue.wast @@ -103,7 +103,7 @@ ) ;; CHECK: (func $extract-make-unreachable (param $x i32) (param $y i32) (result i32) - ;; CHECK-NEXT: (tuple.extract 1 0 + ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: (local.get $y) diff --git a/test/lit/passes/tuple-optimization.wast b/test/lit/passes/tuple-optimization.wast index a7e952fba..d092d479f 100644 --- a/test/lit/passes/tuple-optimization.wast +++ b/test/lit/passes/tuple-optimization.wast @@ -580,12 +580,12 @@ ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (tuple.extract 1 0 + ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (tuple.extract 1 1 + ;; CHECK-NEXT: (tuple.extract 2 1 ;; CHECK-NEXT: (local.tee $tuple ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) |