Skip to content

args causes a compiler crash for 0.15.1 and forward #74

@buzmeg

Description

@buzmeg

For both Zig 0.15.1 as well as 0.16.0-dev.234, on Linux x86_64 Fedora 42 as well as Ubuntu 24.04.

The following program causes a Zig compiler crash:

const std = @import("std");
const test_args = @import("test_args");
const args = @import("args");

const CliOptions = struct {
    help: bool = false,
};


pub fn main() !void {
    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();

    const allocator = arena.allocator();

    const cli = args.parseForCurrentProcess(CliOptions, allocator, .print) catch return 1;
    defer cli.deinit();
}

After instrumenting zig, the failure is as follows:

% zig build run
run
└─ run exe test_args
   └─ install
      └─ install test_args
         └─ compile exe test_args Debug native failure
error: thread 819910 panic: reached unreachable code
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/Type.zig:1414:27: 0x6a5b2c4 in abiSizeInner__anon_309595 (main.zig)
            .func_type => unreachable, // represents machine code; not a pointer
                          ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/Type.zig:1264:25: 0x630747b in abiSize (main.zig)
    return (abiSizeInner(ty, .eager, zcu, {}) catch unreachable).scalar;
                        ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/Type.zig:3917:44: 0x6311cbc in getUnionLayout (main.zig)
        const field_size = field_ty.abiSize(zcu);
                                           ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/Type.zig:2090:31: 0x6309913 in unionGetLayout (main.zig)
    return Type.getUnionLayout(union_obj, zcu);
                              ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/codegen.zig:678:45: 0x6324f52 in generateSymbol (main.zig)
            const layout = ty.unionGetLayout(zcu);
                                            ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link/Dwarf.zig:2132:35: 0x82ef3cc in blockValue (main.zig)
        try codegen.generateSymbol(
                                  ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link/Dwarf.zig:1589:53: 0x9c8aa5a in genLocalConstDebugInfoWriterError (main.zig)
        if (has_runtime_bits) try wip_nav.blockValue(src_loc, val);
                                                    ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link/Dwarf.zig:1556:57: 0x96b1d2c in genLocalConstDebugInfo (main.zig)
        return wip_nav.genLocalConstDebugInfoWriterError(src_loc, tag, opt_name, val) catch |err| switch (err) {
                                                        ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/arch/x86_64/Emit.zig:612:61: 0x8c2e7d3 in emitMir (main.zig)
                            try dwarf.genLocalConstDebugInfo(
                                                            ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/arch/x86_64/Mir.zig:2027:14: 0x8710361 in emit (main.zig)
    e.emitMir() catch |err| switch (err) {
             ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/codegen.zig:197:28: 0x7d67792 in emitFunction (main.zig)
            return mir.emit(lf, pt, src_loc, func_index, code, debug_output);
                           ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link/Elf/ZigObject.zig:1440:29: 0x7d68ff5 in updateFunc (main.zig)
    try codegen.emitFunction(
                            ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link/Elf.zig:1690:44: 0x6f3b41e in updateFunc (main.zig)
    return self.zigObjectPtr().?.updateFunc(self, pt, func_index, mir);
                                           ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link.zig:768:82: 0x6877132 in updateFunc (main.zig)
                return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(pt, func_index, mir);
                                                                                 ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link.zig:1490:30: 0x6271f78 in doZcuTask (main.zig)
                lf.updateFunc(pt, func.func, mir) catch |err| switch (err) {
                             ^
/var/home/foo/zig/zig-bootstrap-ubuntu/zig/src/link/Queue.zig:287:23: 0x623919f in flushTaskQueue (main.zig)
        link.doZcuTask(comp, tid, task);
                      ^
/var/home/foo/zig/zig-bootstrap-ubuntu/out/host/lib/zig/std/Thread/Pool.zig:180:50: 0x6239a44 in runFn (std.zig)
            @call(.auto, func, .{id.?} ++ closure.arguments);
                                                 ^
/var/home/foo/zig/zig-bootstrap-ubuntu/out/host/lib/zig/std/Thread/Pool.zig:293:27: 0x5b674a7 in worker (std.zig)
            runnable.runFn(runnable, id);
                          ^
/var/home/foo/zig/zig-bootstrap-ubuntu/out/host/lib/zig/std/Thread.zig:510:13: 0x590d800 in callFn__anon_182763 (std.zig)
            @call(.auto, f, args);
            ^
/var/home/foo/zig/zig-bootstrap-ubuntu/out/host/lib/zig/std/Thread.zig:782:30: 0x573cdf5 in entryFn (std.zig)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x7f8816fe8f53 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7f8816fe8f53` was not available, trace may be incomplete

???:?:?: 0x7f881706c32b in ??? (libc.so.6)

error: the following command terminated unexpectedly:
/var/home/foo/zig/zig-bootstrap-ubuntu/out/zig-native-linux-gnu-baseline/zig build-exe -ODebug --dep test_args --dep args -Mroot=/var/home/foo/zig/test-args/src/main.zig -Mtest_args=/var/home/foo/zig/test-args/src/root.zig -ODebug -Margs=/var/home/foo/.cache/zig/p/args-0.0.0-CiLiqojRAACGzDRO7A9dw7kWSchNk29caJZkXuMCb0Cn/args.zig --cache-dir .zig-cache --global-cache-dir /var/home/foo/.cache/zig --name test_args --zig-lib-dir /var/home/foo/zig/zig-bootstrap-ubuntu/out/zig-native-linux-gnu-baseline/lib/ --listen=-

Build Summary: 0/5 steps succeeded; 1 failed
run transitive failure
└─ run exe test_args transitive failure
   ├─ compile exe test_args Debug native failure
   └─ install transitive failure
      └─ install test_args transitive failure
         └─ compile exe test_args Debug native (reused)

error: the following build command failed with exit code 1:
.zig-cache/o/e36f5ad7d681dec6e261a18b198519c2/build /var/home/foo/zig/zig-bootstrap-ubuntu/out/zig-native-linux-gnu-baseline/zig /var/home/foo/zig/zig-bootstrap-ubuntu/out/zig-native-linux-gnu-baseline/lib /var/home/foo/zig/test-args .zig-cache /var/home/foo/.cache/zig --seed 0x6831805a -Z87ec9b0e0ed20a7f run

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions