authorgravatar for milos.kozak@lejmr.comMiloš Kozák <milos.kozak@lejmr.com> 2026-08-06 20:33:20+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-11 10:25:26+02:00
loga6420d9985eeb325f302a1252d32dc30f89f40ee
treec3651486e9c9dda73bb17a5a3f8d1417b0d2850c
parentde207594e40d659eb2d6d9fd3813c66ee5ae4340

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

1 files changed, 1 insertions(+), 0 deletions(-)

src/codegen/llvm/FuncGen.zig+1
......@@ -718,6 +718,7 @@ fn genBodyDebugScope(
718718 .scope = self.scope.toOptional(),
719719 .inlined_at = self.inlined_at,
720720 } };
721 defer self.wip.debug_location.location.scope = old_scope.toOptional();
721722
722723 try self.genBody(body, coverage_point);
723724}