From fb55107dd7eaa66bc672c17d5775341bd16a473e Mon Sep 17 00:00:00 2001 From: bplu4t2f Date: Mon, 19 Oct 2026 16:37:17 +0200 Subject: [PATCH] Fix `or_return` debug location of the "continue_block". --- src/llvm_backend_utility.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index ae92e6629..5c4173c7b 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -636,6 +636,14 @@ gb_internal lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue con lbValue rhs = {}; lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs); + // NOTE(bplu4t2f): + // We must store the debug location before the or_return machinery, so that we can + // restore it for the "continue_block". Otherwise the source location of the assignment + // that is happening in the "continue" case is still stuck at the end of the "return_block". + // That means the cursor would jump to the closing brace of a `defer` statement, + // if the current scope has one, since that's running at the end of the "return" case. + LLVMMetadataRef debug_loc = LLVMGetCurrentDebugLocation2(p->builder); + lbBlock *return_block = lb_create_block(p, "or_return.return"); lbBlock *continue_block = lb_create_block(p, "or_return.continue"); @@ -664,7 +672,10 @@ gb_internal lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue con lb_build_return_stmt_internal(p, rhs, ast_token(arg).pos); } } + + // NOTE: The debug source location is still at the end of whatever the return case was doing. lb_start_block(p, continue_block); + LLVMSetCurrentDebugLocation2(p->builder, debug_loc); if (tv.type != nullptr) { return lb_emit_conv(p, lhs, tv.type); }