Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make else if conditions contain debug stmt info #11160

Closed
Tracked by #89
andrewrk opened this issue Mar 14, 2022 · 0 comments · Fixed by #11177
Closed
Tracked by #89

make else if conditions contain debug stmt info #11160

andrewrk opened this issue Mar 14, 2022 · 0 comments · Fixed by #11177
Assignees
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Mar 14, 2022

Zig version: 0.10.0-dev.1311+5ea94e771

const std = @import("std");

pub fn main() void {
    var x: i32 = 1234;
    if (x + 1 < 10) {
        x += 1;
    } else if (x / 2 == 0) {
        x += 2;
    }
    var y = x;
    _ = y;
}

Here you can see in a debugging session, the debugger regrettably steps over the x / 2 == 0 expression:

$ ./stage2/bin/zig build-exe test3.zig -fLLVM
$ gdb ./test3
(gdb) break test3.main
Breakpoint 1 at 0x201b24: file test3.zig, line 4.
(gdb) run
Starting program: /home/andy/dev/zig/build-release/test3 

Breakpoint 1, test3.main () at test3.zig:4
4	    var x: i32 = 1234;
(gdb) step
5	    if (x + 1 < 10) {
(gdb) 
10	    var y = x;
(gdb) 

This is because we do not emit a dbg_stmt for it in the ZIR:

        %17 = condbr(%16, {
          %19 = dbg_stmt(4, 9)
          %20 = load(%7) node_offset:6:11
          %21 = typeof(%20) node_offset:6:11
          %22 = add(%20, @Ref.one) node_offset:6:11
          %23 = store(%7, %22)
          %39 = break(%18, @Ref.void_value)
        }, {
          %30 = block({
            %24 = load(%7) node_offset:7:16
            %25 = int(2)
            %26 = div(%24, %25) node_offset:7:18
            %27 = cmp_eq(%26, @Ref.zero) node_offset:7:22
            %28 = as_node(@Ref.bool_type, %27) node_offset:7:22
            %29 = condbr(%28, {
              %31 = dbg_stmt(6, 9)
              %32 = load(%7) node_offset:8:11
              %33 = typeof(%32) node_offset:8:11
              %34 = int(2)
              %35 = add(%32, %34) node_offset:8:11
              %36 = store(%7, %35)
              %37 = break(%30, @Ref.void_value)
            }, {
              %38 = break(%30, @Ref.void_value)
            }) node_offset:7:12
          }) node_offset:7:12

If you ctrl+f to highlight dbg_stmt you can see that one is missing from the else if branch, just before the condition.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Mar 14, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Mar 14, 2022
@Vexu Vexu self-assigned this Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants