From a6420d9985eeb325f302a1252d32dc30f89f40ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Koz=C3=A1k?= Date: Thu, 6 Aug 2026 20:33:20 +0200 Subject: [PATCH] llvm: restore debug location scope after generating a nested body Commit d28006153e dropped the deferred restore of the debug location's scope in genBodyDebugScope. Since then, instructions emitted after a nested body inherit the body's lexical block as their location scope. This breaks variable info for locals initialized by a try expression: their dbg_var_ptr is emitted right after the try's block, so the dbg.declare gets a location scoped to the inner lexical block, and LLVM places the variable's DIE inside a DW_TAG_lexical_block whose ranges end with that block. Debuggers then consider the variable out of scope for the rest of the function. Closes #30705 --- src/codegen/llvm/FuncGen.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codegen/llvm/FuncGen.zig b/src/codegen/llvm/FuncGen.zig index 14e31fd1c09f846fcef7417b46b7681423880cfd..7f3e4beb41b29b046bfa1ae30b38c51f4a32df51 100644 --- a/src/codegen/llvm/FuncGen.zig +++ b/src/codegen/llvm/FuncGen.zig @@ -718,6 +718,7 @@ fn genBodyDebugScope( .scope = self.scope.toOptional(), .inlined_at = self.inlined_at, } }; + defer self.wip.debug_location.location.scope = old_scope.toOptional(); try self.genBody(body, coverage_point); } -- 2.54.0