zig
zig copied to clipboard
Consts are frequently "optimized away" in debug.
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":
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.
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.