Skip to content

Commit b83be0d

Browse files
committed
Bug 1717971 - Fix combination of try-delegate and catchless try r=rhunt
See WebAssembly/exception-handling#164 for a discussion of the intended behavior of this case. Simplifies try note handling by using the existing mechanism and just installing a no-handler rethrow pad. Differential Revision: https://phabricator.services.mozilla.com/D118789
1 parent 9c51137 commit b83be0d

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

js/src/wasm/WasmBaselineCompile.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -10264,21 +10264,7 @@ bool BaseCompiler::emitEnd() {
1026410264
}
1026510265
break;
1026610266
#ifdef ENABLE_WASM_EXCEPTIONS
10267-
case LabelKind::Try: {
10268-
// The beginning of a `try` block introduces this try note, but
10269-
// we need to remove it in case we have no handlers in this block
10270-
// as it can never be the target of an exception.
10271-
WasmTryNoteVector& tryNotes = masm.tryNotes();
10272-
// This will shift the indices of any try notes in between the `try`
10273-
// instruction and this `end`. This is fine as long as try notes are
10274-
// only accessed through ControlItems, as the shifted try notes will
10275-
// correspond only to items that are popped by this point.
10276-
tryNotes.erase(&tryNotes[controlItem().tryNoteIndex]);
10277-
if (!endBlock(type)) {
10278-
return false;
10279-
}
10280-
break;
10281-
}
10267+
case LabelKind::Try:
1028210268
case LabelKind::Catch:
1028310269
case LabelKind::CatchAll:
1028410270
if (!endTryCatch(type)) {
@@ -10797,17 +10783,23 @@ bool BaseCompiler::endTryCatch(ResultType type) {
1079710783
uint32_t lineOrBytecode = readCallSiteLineOrBytecode();
1079810784

1079910785
Control& tryCatch = controlItem();
10786+
LabelKind tryKind = iter_.controlKind(0);
1080010787

1080110788
if (deadCode_) {
1080210789
fr.resetStackHeight(tryCatch.stackHeight, type);
1080310790
popValueStackTo(tryCatch.stackSize);
1080410791
} else {
10805-
// Since the previous block is a catch, we must handle the extra exception
10792+
// If the previous block is a catch, we must handle the extra exception
1080610793
// reference on the stack (for rethrow) and thus the stack size is 1 more.
10807-
MOZ_ASSERT(stk_.length() == tryCatch.stackSize + type.length() + 1);
10794+
MOZ_ASSERT(stk_.length() == tryCatch.stackSize + type.length() +
10795+
(tryKind == LabelKind::Try ? 0 : 1));
1080810796
// Assume we have a control join, so place results in block result
10809-
// allocations and also handle the implicit exception reference.
10810-
popCatchResults(type, tryCatch.stackHeight);
10797+
// allocations and also handle the implicit exception reference if needed.
10798+
if (tryKind == LabelKind::Try) {
10799+
popBlockResults(type, tryCatch.stackHeight, ContinuationKind::Jump);
10800+
} else {
10801+
popCatchResults(type, tryCatch.stackHeight);
10802+
}
1081110803
MOZ_ASSERT(stk_.length() == tryCatch.stackSize);
1081210804
// Since we will emit a landing pad after this and jump over it to get to
1081310805
// the control join, we free these here and re-capture at the join.
@@ -10824,6 +10816,8 @@ bool BaseCompiler::endTryCatch(ResultType type) {
1082410816
}
1082510817

1082610818
// Create landing pad for all catch handlers in this block.
10819+
// When used for a catchless try block, this will generate a landing pad
10820+
// with no handlers and only the fall-back rethrow.
1082710821
masm.bind(&tryCatch.otherLabel);
1082810822

1082910823
// The stack height also needs to be set not for a block result, but for the
@@ -10836,6 +10830,12 @@ bool BaseCompiler::endTryCatch(ResultType type) {
1083610830
tryNote.entryPoint = masm.currentOffset();
1083710831
tryNote.framePushed = masm.framePushed();
1083810832

10833+
// If we are in a catchless try block, then there were no catch blocks to
10834+
// mark the end of the try note, so we need to end it here.
10835+
if (tryKind == LabelKind::Try) {
10836+
tryNote.end = tryNote.entryPoint;
10837+
}
10838+
1083910839
RegRef exn = RegRef(WasmExceptionReg);
1084010840
needRef(exn);
1084110841

0 commit comments

Comments
 (0)