-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
audit alignment #37
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
The answer to everything is |
// global variable
var foo: u8 align 4 = 100;
comptime {
assert(@typeOf(&foo) == &align 4 u8);
const slice = (&foo)[0..1];
assert(@typeOf(slice) == []align 4 u8);
}
// function
fn derp() align 8 -> void {
// local variable
const array: [8]u8 align 8 = undefined;
assert(@typeOf(&array[0]) == &align 8 u8);
}
// packed struct
const baz: packed struct {
a: u32,
b: u32,
} = undefined;
comptime {
assert(@typeOf(&baz.b) == &align 1 const u32);
}
// bit field
const blah: packed struct {
a: u3,
b: u3,
c: u2,
} = undefined;
comptime {
assert(@typeOf(&blah.b) == &align 1:3:6 const u3);
// not allowed to slice pointers with bit offsets: (&blah.b)[0..1] is a compile error
}
|
* remove `@setGlobalAlign` * add align keyword for setting alignment on functions and variables. * loads and stores use alignment from pointer * memcpy, memset use alignment from pointer * add syntax for pointer alignment * slices can have volatile * add u2, i2 primitives * ignore preferred align and use abi align everywhere * back to only having alignOf builtin. preferredAlignOf is too tricky to be useful. See #432. Partial revert of e726925. See #37
* add alignment capability for fn protos * add @alignCast * fix some ast rendering code * fix some ir rendering code * add error for pointer cast increasing alignment * update allocators in std to correctly align See #37
type we can figure out is safe to use See #37
For example, we set size_in_bits on a bool to 1. But then later when making an array type we use this value and multiply by the array size. Is that right?
On structs when making the member debug type we set the alignment of members and calculate the offset in bits to each member. Are we doing it right?
We also set the alignment for structs and have the option to set alignment on local variables and parameters, and more.
Related, figure out exactly what is the difference between packed structs and normal structs. Will LLVM re-order fields to improve alignment? Or is that our job? If LLVM does it, how do we know which values to give to the debug info? If we do it then we need to add that to codegen.
The text was updated successfully, but these errors were encountered: