Skip to content

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

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

Closed
scurest opened this issue Jun 15, 2017 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@scurest
Copy link
Contributor

scurest commented Jun 15, 2017

$ 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?)

@andrewrk andrewrk added this to the 0.1.0 milestone Jun 15, 2017
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jun 15, 2017
@andrewrk
Copy link
Member

Thanks for the report. Hoping to look at this and your other report tonight.

@scurest
Copy link
Contributor Author

scurest commented Jun 16, 2017

Thanks! No rush or anything. It's a really neat language, by the way :)

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
Projects
None yet
Development

No branches or pull requests

2 participants