Skip to content

Bug: ICE when getting pointer to bit-aligned field of a struct with byte size > 8191 #7724

Open
@foobles

Description

@foobles

Currently, this compiles fine:

const Foo = packed struct {
    _pad: u9999 = undefined,
    bit: u1,
};
pub fn main() void {
    const foo = Foo { .bit = 0 };
    const ptr: *align(@alignOf(Foo):9999:1256) const u1 = &foo.bit;
}

But this crashes the compiler inside the function get_int_type:

const Foo = packed struct {
    _pad: u65535 = undefined,
    bit: u1,
};
pub fn main() void {
    const foo = Foo { .bit = 0 };
    const ptr: *align(@alignOf(Foo):65535:8192) const u1 = &foo.bit;
}

This is because the host_int_bytes of ptr's type is 8192, which in the function resolve_llvm_types_pointer() is used like this:

        ZigType *host_int_type = get_int_type(g, false, type->data.pointer.host_int_bytes * 8);

This then becomes a call to get_int_type(g, false, 65536) which is above the range of allowed integer bits, and causes an assertion error.

Edit:

Idea for a solution: instead of getting the LLVM type of a specifically sized integer type with N bits, instead we could create the LLVM type [data.pointer.host_int_bytes x i8]. This seems to communicate intent as "byte buffer with specific size" better than a strangely sized integer, while likely needing extremely few changes to support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions