# llvm: update current debug location scope when entering debug scope · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/31a7f22b800c091962726de2dd29f10a8eb25b78)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 31a7f22b800c091962726de2dd29f10a8eb25b78

Requested commit: 31a7f22b800c091962726de2dd29f10a8eb25b78

Commit: 31a7f22b800c091962726de2dd29f10a8eb25b78

Tree: 2cfbb25b0ed73eecb17c976777df08765237a4be

Author: mlugg

Committer: Matthew Lugg

## Message

```
llvm: update current debug location scope when entering debug scope

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

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

```

## Parents

- [5c628312b16ce972cc3108ed44eed47960e17af7](https://git.cafe/gitcafe/zig/commit/5c628312b16ce972cc3108ed44eed47960e17af7?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/31a7f22b800c091962726de2dd29f10a8eb25b78?format=markdown)
