Skip to content

Assertion failure when @alignOf(SomeStruct) is called without first referencing SomeStruct #391

Closed
@scurest

Description

@scurest
$ cat a.zig
const io = @import("std").io;

const Foo = struct { x: u32, y: u32, z: u32, };

pub fn main() -> %void {
    _ = Foo { .x = 1, .y = 2, .z = 3 };
    %%io.stdout.printf("{}\n", usize(@alignOf(Foo)));
}
$ zig/build/zig build_exe a.zig && ./a
12

This is ok, but if you delete the line _ = Foo { ... }; you get this instead

$ zig/build/zig build_exe a.zig
zig: /home/scurest/zig/src/analyze.cpp:1645: void resolve_struct_type(CodeGen*, TypeTableEntry*): Assertion `LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref) > 0' failed.
Aborted (core dumped)

It seems to work if you create a Foo or if you create a function type that contains Foo (eg. _ = fn() -> Foo;). It doesn't work if you reference Foo by itself (_ = Foo;) or underneath a pointer.

(Also, 12 isn't the right alignment, cf. #37?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions