diff options
author | Alon Zakai <azakai@google.com> | 2021-10-27 17:33:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 17:33:12 -0700 |
commit | 2d585ebad9885259932168daf7384b58154badd6 (patch) | |
tree | c1ccf03ca489857f99081c5494b408a69b599ddd /src | |
parent | 5ec74cf79590648f3a633387f0d1d8a5930a410b (diff) | |
download | binaryen-2d585ebad9885259932168daf7384b58154badd6.tar.gz binaryen-2d585ebad9885259932168daf7384b58154badd6.tar.bz2 binaryen-2d585ebad9885259932168daf7384b58154badd6.zip |
Fix printing of some unreachable GC instructions (#4281)
We have separate logic for printing their headers and bodies, and they were not in sync.
Specifically, we would not emit drops in the body of a block, which is not valid, and would
fail roundtripping on text.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 34fe92ff6..db121a22c 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2469,9 +2469,22 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << " ;; end try"; } } - void printUnreachableReplacement(Expression* curr) { - // See the parallel function in PrintExpressionContents for background. + void maybePrintUnreachableReplacement(Expression* curr, Type type) { + // See the parallel function + // PrintExpressionContents::printUnreachableReplacement for background. That + // one handles the header, and this one the body. For convenience, this one + // also gets a parameter of the type to check for unreachability, to avoid + // boilerplate in the callers; if the type is not unreachable, it does the + // normal behavior. // + // Note that the list of instructions using that function must match those + // using this one, so we print the header and body properly together. + + if (type != Type::unreachable) { + visitExpression(curr); + return; + } + // Emit a block with drops of the children. o << "(block"; if (!minify) { @@ -2485,33 +2498,26 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } decIndent(); } + void visitStructNew(StructNew* curr) { + maybePrintUnreachableReplacement(curr, curr->type); + } void visitStructSet(StructSet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(curr); - return; - } - visitExpression(curr); + maybePrintUnreachableReplacement(curr, curr->ref->type); } void visitStructGet(StructGet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(curr); - return; - } - visitExpression(curr); + maybePrintUnreachableReplacement(curr, curr->ref->type); + } + void visitArrayNew(ArrayNew* curr) { + maybePrintUnreachableReplacement(curr, curr->type); + } + void visitArrayInit(ArrayInit* curr) { + maybePrintUnreachableReplacement(curr, curr->type); } void visitArraySet(ArraySet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(curr); - return; - } - visitExpression(curr); + maybePrintUnreachableReplacement(curr, curr->ref->type); } void visitArrayGet(ArrayGet* curr) { - if (curr->ref->type == Type::unreachable) { - printUnreachableReplacement(curr); - return; - } - visitExpression(curr); + maybePrintUnreachableReplacement(curr, curr->ref->type); } // Module-level visitors void printSupertypeOr(HeapType curr, std::string noSuper) { |