From adea6e0f80c68108691f28ab4aa81b8f8973ac35 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 11 Apr 2024 09:22:04 -0700 Subject: 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. --- src/passes/Print.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') 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 + #include #include #include @@ -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"); } -- cgit v1.2.3