-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
std.PackedIntArray fails for some int types at comptime #19627
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
Comments
On 0.12.0, this gives way to another error: .opt/zig/lib/std/packed_int_array.zig:126:36: error: dereference of '*align(1) u24' exceeds bounds of containing decl of type '[320]u8' I believe this is a subtle bug in |
Ah thanks, if the remaining issue is in the standard lib then I can dig in a bit more, I can probably take a look in the next few days. |
I dug in a bit more using |
Pointer loads fetch The solution is probably to either pad the buffer out to a multiple of Note that if you make this change and PR it, please make sure to add a corresponding test! |
Ah thanks, I just wrote a smaller test case that confirms what you posted. const std = @import("std");
fn foo(bytes: []const u8) u24 {
const p: *align(1) const u24 = @ptrCast(&bytes[1]);
return p.*;
}
export fn example() u32 {
const bytes = [_]u8{ 0, 1, 2, 3 };
return comptime foo(&bytes);
} Produces: So it seems like |
Note to self that there is also Test case for const std = @import("std");
export fn example() u32 {
const bytes = [_]u8{ 0, 1, 2, 3 };
return comptime std.mem.readPackedInt(u24, &bytes, 8, .little);
} |
Zig Version
0.11.0
Steps to Reproduce and Observed Behavior
Hi, I asked a question about this at https://ziggit.dev/t/packedintarray-at-comptime/3915, and it was mentioned that this could be related to #19452, so thought I should report this as an issue.
The issue that use of
PackedIntArray
during comptime seems to fail (with a compile error) for certainInt
types. The compile error (in both0.11.0
and0.12.0-dev.3631+c4587dc9f
) is:The repro case for this is:
Interestingly, I get the same error when using
u10
-u12
as the lookup table type, butu1
-u9
andu13
-u16
all compile fine. I am a confused about what could be special aboutu10
-u12
that is causing the compile error.Expected Behavior
Repro case compiles for all types
u1
-u16
.The text was updated successfully, but these errors were encountered: