Hey all, just made a bug report here:
opened 03:20PM - 11 Jun 24 UTC
closed 05:20PM - 12 Jun 24 UTC
bug
standard library
### Zig Version
0.14.0-dev.15+d4bc64038
### Steps to Reproduce and Observed Be… havior
See forked branch with fixes to `update_cpu_features.zig`:
https://github.com/haydenridd/zig/tree/fix-update-cpu-features
I made changes to this utility to get it to compile and run with the new `std.Progress` API. It's a relatively simple use of the API, and as far as I can tell I'm calling everything correctly. Compile + run _not_ in single threaded mode with llvm-tblgen corresponding to `18.1.7` (version corresponding to issue's Zig version). Process runs for a time, and then an error like so will occur:
```
thread 28332 panic: index out of bounds: index 40, len 39
/home/hayden/Documents/zig/zig/build/stage3/lib/zig/std/Progress.zig:1054:40: 0x10e386e in computeRedraw (update_cpu_features)
const children_node = &children[@intFromEnum(parent_index)];
^
/home/hayden/Documents/zig/zig/build/stage3/lib/zig/std/Progress.zig:463:40: 0x10c9bf7 in updateThreadRun (update_cpu_features)
const buffer, _ = computeRedraw(&serialized_buffer);
^
/home/hayden/Documents/zig/zig/build/stage3/lib/zig/std/Thread.zig:408:13: 0x10a96ca in callFn__anon_8874 (update_cpu_features)
@call(.auto, f, args);
^m-tblgen
/home/hayden/Documents/zig/zig/build/stage3/lib/zig/std/Thread.zig:1226:30: 0x109ed07 in entryFn (update_cpu_features)
return callFn(f, self.fn_args);
^
/home/hayden/Documents/zig/zig/build/stage3/lib/zig/c.zig:239:13: 0x1163c00 in clone (c)
asm volatile (
^m-tblgen
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
```
This utility runs to completion when compiled in single threaded mode, however NO progress prompts are printed at all, which is suspicious...
### Expected Behavior
Expected `update_cpu_features.zig` to run to completion successfully with no std.Progress related errors!
But hoping someone else may have seen this using the new std.Progress API that was introduced in 0.13.0. Basically I went to fix the update_cpu_features.zig utility (tools/ dir in the zig repo) to work with the new std.Progress API and am encountering some really odd behavior. It works fine for a bit then panics on an index out of bounds error here in the API:
var children_buffer: [node_storage_buffer_len]Children = undefined;
const children = children_buffer[0..serialized.parents.len];
@memset(children, .{ .child = .none, .sibling = .none });
for (serialized.parents, 0..) |parent, child_index_usize| {
const child_index: Node.Index = @enumFromInt(child_index_usize);
assert(parent != .unused);
const parent_index = parent.unwrap() orelse continue;
const children_node = &children[@intFromEnum(parent_index)];
if (children_node.child.unwrap()) |existing_child_index| {
const existing_child = &children[@intFromEnum(existing_child_index)];
children[@intFromEnum(child_index)].sibling = existing_child.sibling;
existing_child.sibling = child_index.toOptional();
} else {
children_node.child = child_index.toOptional();
}
}
// The strategy is, with every redraw:
Anyone see something similar? Maybe I’m just subtly using the API wrong?
For convenience here’s my branch with the fixes to update_cpu_features.zig:
https://github.com/haydenridd/zig/tree/fix-update-cpu-features
You don’t have to compile this specific build of Zig from source to see the error, using 0.13.0 to build/run update_cpu_features.zig displays the error.
1 Like