-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
alignedAlloc incorrectly calculates byte count #1851
Comments
comptime {
@compileLog("type", "@sizeOf", "@alignOf", "@sizeOf([1]T)");
var i = 0;
while (i < 33) : (i += 1) {
const T = @IntType(false, i * 8);
@compileLog(T, @sizeOf(T), @alignOf(T), @sizeOf([1]T));
}
}
I'm going to solve this by defining I believe we're actually calling the wrong LLVM function to determine the size of things. Fix coming shortly. |
After the fix:
|
This will break existing code that expects things like |
That's correct. Given a
serialize/deserialize were fixed with a 1 line change: - const int_size = @sizeOf(U);
+ const int_size = (U.bit_count + 7) / 8; The docs for |
An issue discussed in #1738 was that
@sizeOf(T)
doesn't account for alignment.alignedAlloc
uses@sizeOf(T)
without regard for alignment as well. In some cases this will cause an allocator to allocate fewer bytes than are actually used.Assuming x86 or x64 hardware:
It would appear as though both
@sliceToBytes
and@bytesToSlice
are similarly affected.That thing with having to
alignCast
forfor
seems to be an unrelated problem.The text was updated successfully, but these errors were encountered: