srctree

mlugg parent 5c628312 31a7f22b
llvm: update current debug location scope when entering debug scope

This issue was causing debug information to sometimes not functioncorrectly for some local variables, with debuggers simply reporting thatthe variable does not exist. What was happening was that after an AIRbody - and thus debug lexical scope - begins, but before any dbg_stmtwithin it, the scope on self.wip.debug_location refers to the parentscope, but the scope field on the DILocalVariable metadata passed to@llvm.dbg.declare points, correctly, to the nested scope. I haven'tlooked into precisely what happens here, but in short, it would appearthat LLVM Doesn't Like It (tm).

The fix is simple: when we change self.scope at the start or end of anAIR body, also modify the scope on self.wip.debug_location. This iscorrect as we always want the debug info for an instruction to beassociated with the block it is within, even if the line/column areslightly outdated for any reason.

inlinesplit
src/codegen/llvm.zig added: 11, removed: 1, total 10
@@ -5202,6 +5202,16 @@ pub const FuncGen = struct {
self.prev_dbg_line,
self.prev_dbg_column,
);
 
switch (self.wip.debug_location) {
.location => |*l| l.scope = self.scope,
.no_location => {},
}
defer switch (self.wip.debug_location) {
.location => |*l| l.scope = old_scope,
.no_location => {},
};
 
try self.genBody(body);
}