ziglang / zig

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

Compiler crashes converting aligned array to many-item pointer or slice #21517

Open kulkarniniraj opened 5 days ago

kulkarniniraj commented 5 days ago

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

const print = @import("std").debug.print;

const DirEntry = extern struct {
    name:               [8] u8,
    ext:                [3] u8,    
};

pub fn main() !void {
    var data_buffer: [512]u8 align(2)= undefined;

    const dir_entry_list: []DirEntry = &data_buffer;

    print("dir entry: {s}", .{dir_entry_list[0].name});    
}

Build or run

zig build-exe scratchpad.zig

Compiler crashes:

fish: Job 1, 'zig build-exe scratchpad.zig' terminated by signal SIGSEGV (Address boundary error)

Expected Behavior

Program builds or compiler throws some error.

kulkarniniraj commented 5 days ago

Only observed with align(2) or more. align(1) or removing align throws compiler errors as expected.