zig icon indicating copy to clipboard operation
zig copied to clipboard

Consts are frequently "optimized away" in debug.

Open Srekel opened this issue 2 years ago • 1 comments

Zig Version

0.11.0-dev.3910+689f3163a

Steps to Reproduce and Observed Behavior

I don't have a minimal repro for this now, but can try to come up with one when this is planned. I suspect it'll be pretty easy as it happens pretty much any time I break into the debugger.

Here's an example of what it looks like "live":

image

I'm on Windows 10 and using VS Code to debug.

Expected Behavior

I would expect consts to be inspectable, just like regular vars, in debug builds.

Srekel avatar Jul 24 '23 17:07 Srekel

Here's one particular reproducible pattern using 0.12.0-dev.3193+4ba4f94c9

const std = @import("std");

pub fn main() !void {
    var v: u32 = 1;
    std.mem.doNotOptimizeAway(&v);
    const a = if (v != 0) v else return;
    const b = a;
    std.debug.print("{} {}\n", .{ a, b });
}

Only the variables v and b show up in CodeLLDB, but not a.

ni-vzavalishin avatar Mar 23 '24 11:03 ni-vzavalishin