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

@IntType silently wraps around on number of bits #1242

Closed
BarabasGitHub opened this Issue Jul 15, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@BarabasGitHub
Contributor

BarabasGitHub commented Jul 15, 2018

Basically currently this is the case:

@IntType(false, @maxValue(u64)).bitcount == @maxValue(u32)
@IntType(false, @maxValue(u32) + 1).bit_count == 0

I'm guessing there should be a limit somewhere.

@andrewrk andrewrk added this to the 0.3.0 milestone Jul 15, 2018

@andrewrk andrewrk added the bug label Jul 15, 2018

@andrewrk

This comment has been minimized.

Member

andrewrk commented Jul 15, 2018

It looks like the current size of the parameter is u8: https://ziglang.org/documentation/master/#IntType

I think that's not actually correct though. I believe it should be changed to u32, which is the size of the parameter that llvm accepts for the bit count.

@BarabasGitHub

This comment has been minimized.

Contributor

BarabasGitHub commented Jul 15, 2018

Oh I didn't even notice the u8 one there. That's definitely not how it works. You can pass much larger values and they'll just work. I guess it's treated as a comptime_int?

@andrewrk

This comment has been minimized.

Member

andrewrk commented Jul 16, 2018

Turns out it was treated as a usize according to zig, but then the compiler internally stored it as a u32, which caused the wrapping. Pushing a fix shortly.

@andrewrk andrewrk closed this in e9a03cc Jul 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment