From 4c7c7c38e2c7e25a014c20b9377b08df71676a1e Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 13 Jun 2021 20:39:40 +0430 Subject: [PATCH] LibJS: Make EnterUnwindContext a terminator op Otherwise a basic block could have multiple outgoing edges without having much reason to do so. --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 5 ++++- Userland/Libraries/LibJS/Bytecode/Op.cpp | 3 ++- Userland/Libraries/LibJS/Bytecode/Op.h | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index fa2050c3c4..9fcdcb1fbd 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -991,8 +991,11 @@ void TryStatement::generate_bytecode(Bytecode::Generator& generator) const } } + auto& target_block = generator.make_block(); generator.switch_to_basic_block(saved_block); - generator.emit(handler_target, finalizer_target); + generator.emit(Bytecode::Label { target_block }, handler_target, finalizer_target); + + generator.switch_to_basic_block(target_block); m_block->generate_bytecode(generator); if (m_finalizer && !generator.is_current_block_terminated()) generator.emit(finalizer_target); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index abc6a21cd5..55ff3b29d7 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -258,6 +258,7 @@ void Throw::execute(Bytecode::Interpreter& interpreter) const void EnterUnwindContext::execute(Bytecode::Interpreter& interpreter) const { interpreter.enter_unwind_context(m_handler_target, m_finalizer_target); + interpreter.jump(m_entry_point); } void LeaveUnwindContext::execute(Bytecode::Interpreter& interpreter) const @@ -453,7 +454,7 @@ String EnterUnwindContext::to_string(Bytecode::Executable const&) const { auto handler_string = m_handler_target.has_value() ? String::formatted("{}", *m_handler_target) : ""; auto finalizer_string = m_finalizer_target.has_value() ? String::formatted("{}", *m_finalizer_target) : ""; - return String::formatted("EnterUnwindContext handler:{} finalizer:{}", handler_string, finalizer_string); + return String::formatted("EnterUnwindContext handler:{} finalizer:{} entry:{}", handler_string, finalizer_string, m_entry_point); } String LeaveUnwindContext::to_string(Bytecode::Executable const&) const diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index c13d51789b..e1342d422c 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -451,8 +451,11 @@ public: class EnterUnwindContext final : public Instruction { public: - EnterUnwindContext(Optional