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

Invalid code gen when passing none % 8 == 0 sized field to a function taking a &const to the fields type #966

Closed
Hejsil opened this issue Apr 29, 2018 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@Hejsil
Copy link
Sponsor Contributor

Hejsil commented Apr 29, 2018

fn toInt(value: *const u7) u7 {
    return value.*;
}

pub const LevelUpMove = packed struct {
    move_id: u9,
    level: u7,
};

test "" {
    var lup: LevelUpMove = undefined;
    _ = toInt(lup.level);
}
Call parameter type does not match function signature!
  %2 = getelementptr inbounds %LevelUpMove, %LevelUpMove* %lup, i32 0, i32 0, !dbg !618
 i7*  %3 = call fastcc i7 @toInt(i16* %2), !dbg !620
LLVM ERROR: Broken module found, compilation aborted!
@andrewrk andrewrk added this to the 0.3.0 milestone Apr 29, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Apr 29, 2018
@andrewrk
Copy link
Member

Ah, this is a missing compile error. Here's the error you get if you explicitly pass a pointer:

test.zig:12:19: error: expected type '*const u7', found '*align(:9:16) u7'
    _ = toInt(&lup.level);
                  ^

@andrewrk
Copy link
Member

I was able to make it work fine.

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