Skip to content

segfault when bitcasting u8x64 vector to [2]u8x32 within function #17996

Description

@archaistvolts

Zig Version

0.12.0-dev.1595+70d8baaec

Steps to Reproduce and Observed Behavior

This first happened 2 days ago in simdjzon's ci here. That ci run used zig-linux-x86_64-0.12.0-dev.1591+3fc6a2f11. There have been no recent changes to the project and this never happened before then.

The following is a minimal reproduction of the segfault.

// /tmp/tmp.zig
pub const STEP_SIZE = 64;
pub const u8x32 = @Vector(32, u8);
pub const u8x64 = @Vector(64, u8);

pub fn main() !void {
    const input: []const u8 =
        \\{
        \\    "Width": 800,
        \\    "Height": 600,
        \\    "Title": "View from my room",
        \\    "Url": "http://ex.com/img.png",
        \\    "Private": false,
        \\    "Owner": null
        \\}
    ;

    // this works fine.
    const input_vec: u8x64 = input[0..STEP_SIZE].*;
    const chunks = @as([2]u8x32, @bitCast(input_vec));
    _ = chunks;

    // the segfault only happens when passing the 64 byte vector to a function
    try next(input[0..STEP_SIZE].*);
}

fn next(input_vec: u8x64) !void {
    const chunks = @as([2]u8x32, @bitCast(input_vec));
    _ = chunks;
}
zig run /tmp/tmp.zig
Segmentation fault at address 0x0
/tmp/tmp.zig:27:5: 0x21cefa in next (tmp)
    const chunks = @as([2]u8x32, @bitCast(input_vec));
    ^
/tmp/tmp.zig:23:13: 0x21cf71 in main (tmp)
    try next(input[0..STEP_SIZE].*);
            ^
/home/travis/dev/zig/zig/download/0.12.0-dev.1595+70d8baaec/files/lib/std/start.zig:585:37: 0x21ceb7 in posixCallMainAndExit (tmp)
            const result = root.main() catch |err| {
                                    ^
/home/travis/dev/zig/zig/download/0.12.0-dev.1595+70d8baaec/files/lib/std/start.zig:253:5: 0x21c9e1 in _start (tmp)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)

Expected Behavior

no segfault.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorregressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions