From 3342d56e4a13170c094a29138b32ff17cad4c01d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 21 Nov 2024 11:26:33 -0800 Subject: [wasm2js] Properly handle loops without labels (#7100) When a loop has no name, the name does not matter, but we also cannot emit the same name for all such loops, as that is invalid JS. Just do not emit a while(){} at all in that case, as no continue can exist anyhow. Fixes #7099 Also fix two missing * in error reporting logic, that was printing pointers rather than the expression we wanted to print. I think we changed how iostream prints things years ago, and forgot to update these. --- src/wasm2js.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/wasm2js.h') diff --git a/src/wasm2js.h b/src/wasm2js.h index 15ae019ea..d965dcc0c 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -1181,6 +1181,11 @@ Ref Wasm2JSBuilder::processExpression(Expression* curr, Ref visitLoop(Loop* curr) { Name asmLabel = curr->name; + if (!asmLabel) { + // This loop has no label, so it cannot be continued to. We can just + // emit the body. + return visit(curr->body, result); + } continueLabels.insert(asmLabel); Ref body = visit(curr->body, result); // if we can reach the end of the block, we must leave the while (1) loop @@ -1779,7 +1784,7 @@ Ref Wasm2JSBuilder::processExpression(Expression* curr, return ret; } default: { - Fatal() << "Unhandled type in unary: " << curr; + Fatal() << "Unhandled type in unary: " << *curr; } } } @@ -1949,7 +1954,7 @@ Ref Wasm2JSBuilder::processExpression(Expression* curr, } return ret; default: - Fatal() << "Unhandled type in binary: " << curr; + Fatal() << "Unhandled type in binary: " << *curr; } return makeJsCoercion(ret, wasmToJsType(curr->type)); } -- cgit v1.2.3