Zig Version
0.17.0-dev.127+0b768cd9d
Steps to Reproduce and Observed Behavior
The issue was originally reported here: #31930 (comment)
Steps to reproduce:
- Make a sufficiently large file (here I chose
build.ziggenerated byzig init) - Run
zig reduceon it. (I chosetrueas my checker command as it should ideally reduce the source code to nothing) - Be met with a core dump
$ ~/repos/zig/stage3/bin/zig version
0.17.0-dev.127+0b768cd9d
$ ZIG_DEBUG_CMD=1 ~/repos/zig/stage3/bin/zig reduce true build.zig
/home/plumeus/.cache/zig/o/7190026f4c497d2982239a54436f5e75/reduce true build.zig
smoke testing the interestingness check...
found 23 possible transformations
trying 17 random transformations: replace_with_undef delete_node gut_function replace_with_undef delete_node replace_with_undef delete_node delete_node replace_with_true delete_node replace_with_undef delete_node replace_with_undef replace_with_undef replace_with_undef replace_with_undef replace_with_undef
17 random transformations: interesting. 0/23
found 2 possible transformations
trying 1 random transformations: delete_node
thread 117607 panic: syntax errors occurred
/home/plumeus/repos/zig/stage3/lib/zig/compiler/reduce.zig:194:21: 0x121e070 in main (reduce.zig)
@panic("syntax errors occurred");
^
/home/plumeus/repos/zig/stage3/lib/zig/std/start.zig:737:30: 0x1221dbe in callMain (std.zig)
return wrapMain(root.main(.{
^
/home/plumeus/repos/zig/stage3/lib/zig/std/start.zig:190:5: 0x1217fe1 in _start (std.zig)
asm volatile (switch (native_arch) {
^
Aborted (core dumped) ZIG_DEBUG_CMD=1 ~/repos/zig/stage3/bin/zig reduce true build.zig
Provided that the checker is something other than true, it's also noticeable that the source file may end up in a state that won't satisfy the checker program.
Expected Behavior
zig reduce should not crash, and when it does need to abort, it should ideally revert the state of the file to when it was last found to be interesting.
### Zig Version
0.17.0-dev.127+0b768cd9d
### Steps to Reproduce and Observed Behavior
The issue was originally reported here: https://codeberg.org/ziglang/zig/pulls/31930#issuecomment-13265385
Steps to reproduce:
1. Make a sufficiently large file (here I chose `build.zig` generated by `zig init`)
2. Run `zig reduce` on it. (I chose `true` as my checker command as it should ideally reduce the source code to nothing)
3. Be met with a core dump
```sh-session
$ ~/repos/zig/stage3/bin/zig version
0.17.0-dev.127+0b768cd9d
$ ZIG_DEBUG_CMD=1 ~/repos/zig/stage3/bin/zig reduce true build.zig
/home/plumeus/.cache/zig/o/7190026f4c497d2982239a54436f5e75/reduce true build.zig
smoke testing the interestingness check...
found 23 possible transformations
trying 17 random transformations: replace_with_undef delete_node gut_function replace_with_undef delete_node replace_with_undef delete_node delete_node replace_with_true delete_node replace_with_undef delete_node replace_with_undef replace_with_undef replace_with_undef replace_with_undef replace_with_undef
17 random transformations: interesting. 0/23
found 2 possible transformations
trying 1 random transformations: delete_node
thread 117607 panic: syntax errors occurred
/home/plumeus/repos/zig/stage3/lib/zig/compiler/reduce.zig:194:21: 0x121e070 in main (reduce.zig)
@panic("syntax errors occurred");
^
/home/plumeus/repos/zig/stage3/lib/zig/std/start.zig:737:30: 0x1221dbe in callMain (std.zig)
return wrapMain(root.main(.{
^
/home/plumeus/repos/zig/stage3/lib/zig/std/start.zig:190:5: 0x1217fe1 in _start (std.zig)
asm volatile (switch (native_arch) {
^
Aborted (core dumped) ZIG_DEBUG_CMD=1 ~/repos/zig/stage3/bin/zig reduce true build.zig
```
Provided that the checker is something other than `true`, it's also noticeable that the source file may end up in a state that won't satisfy the checker program.
### Expected Behavior
`zig reduce` should not crash, and when it does need to abort, it should ideally revert the state of the file to when it was last found to be interesting.