Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
foobles opened this issue Jan 8, 2021 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@foobles
Copy link
Contributor

foobles commented Jan 8, 2021

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.

@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jan 26, 2021
@Vexu Vexu added this to the 0.9.0 milestone Jan 26, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
3 participants