From 2c0716e31480a2a91920b80ba3a5880a126cadd4 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 22 Apr 2022 11:03:23 +0430 Subject: [PATCH] LibWasm: Simplify the return instruction execution code a bit --- .../AbstractMachine/BytecodeInterpreter.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 89e9dff285..83586133c9 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -461,18 +461,21 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi } case Instructions::return_.value(): { auto& frame = configuration.frame(); - size_t end = configuration.stack().size() - frame.arity(); - size_t start = end; - for (; start + 1 > 0 && start < configuration.stack().size(); --start) { - auto& entry = configuration.stack().entries()[start]; - if (entry.has()) { - // Leave the frame, _and_ its label. - start += 2; - break; + Checked checked_index { configuration.stack().size() }; + checked_index -= frame.arity(); + VERIFY(!checked_index.has_overflow()); + + auto index = checked_index.value(); + size_t i = 1; + for (; i <= index; ++i) { + auto& entry = configuration.stack().entries()[index - i]; + if (entry.has