ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.85k stars 2.55k forks source link

Compiler segfault while trying to generate compile error #16587

Open Beyley opened 1 year ago

Beyley commented 1 year ago

Zig Version

0.11.0-dev.4282+0f21d3d4d

Steps to Reproduce and Observed Behavior

Clone this repo (branch segfault-compiler) run zig build, you will receive a segfault in the build-exe command that follows

zig build-exe zosu2011 Debug native: error: the following command terminated unexpectedly:
/usr/lib/zig/zig build-exe /home/beyley/zosu2011/src/main.zig --cache-dir /home/beyley/zosu2011/zig-cache --global-cache-dir /home/beyley/.cache/zig --name zosu2011 --mod network::/home/beyley/.cache/zig/p/122090e7cb4459c2224399a45c56f47462733b919aa547c96b8c14ee705bfa22976e/network.zig --deps network --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install zosu2011 transitive failure
   └─ zig build-exe zosu2011 Debug native failure
error: the following build command failed with exit code 1:
/home/beyley/zosu2011/zig-cache/o/2783873f86710035413533200418c1ad/build /usr/lib/zig/zig /home/beyley/zosu2011 /home/beyley/zosu2011/zig-cache /home/beyley/.cache/zig

This only started after this line of code was added

I tried to reproduce with a smaller sample of code, but was unable

Expected Behavior

Compiler should run, and an executable should be output

Beyley commented 1 year ago

Narrowed it down, its failing to generate a compile error, this line should not be a reference to client, it should just be client

Pyrolistical commented 1 year ago

Here is a cut down repo

const std = @import("std");

const Client = struct {};
pub fn sendPackets(_: *Client, _: anytype) void {}

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    var allocator = gpa.allocator();
    var thread_pool: std.Thread.Pool = undefined;
    try thread_pool.init(.{
        .allocator = allocator,
    });

    var client = try allocator.create(Client);
    try thread_pool.spawn(sendPackets, .{
        &client,
        .{},
    });
}
perillo commented 9 months ago

@Beyley, was the example supposed to crash the compiler?

I tried with the latest compiler and got a compiler error.

Pyrolistical commented 9 months ago

@perillo can you post the compiler error? if it's a compiler error then we can close this.