-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Proposal: Change ABI alignment of zero-sized types from 0 to 1 #7221
Comments
One thing which could make this cleaner: changing |
Hmm, I like that idea, @EleanorNB. This would be nice on platforms that had bytes that were not 8 bits, such as some DSPs. On those, in C, it is sometimes difficult to tell how big something is because |
So the ABI alignment of sub-byte types (bool, u3, etc) is 1 byte, and
that's how it should be. Nothing gets bitpacked until you use a packed
struct or `align(0)`, which overrides the ABI alignment. As far as I know,
there are currently no sized types that have an ABI alignment less than
one. And this is a good thing, because bit-packed pointers cause code
bloat. When bit packing, the alignment of any given object is either 1 or
8 bits, and while I agree that there might be some use in obtaining that
value, it's separate from ABI alignment.
…On Fri, Nov 27, 2020, 2:29 AM Eleanor Bartle ***@***.***> wrote:
One thing which could make this cleaner: changing align() to take a *bit*
alignment rather than a byte alignment. So @Alignof(u8) would be 8,
@Alignof(bool) would be 1, and @Alignof(ZST) would also be 1. Thus, we
eliminate special cases, and allow ZSTs to have arbitrary bit offsets.
(Plus: we accommodate architectures with sub-byte or super-byte addressing,
and align() now takes a clean u32 rather than a lopsided u29, which I
suspect was also LLVM's motivation for choosing that number.)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#7221 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARNCWWUH6HIOFQAPYKQMPLSR5PQFANCNFSM4UCZBICA>
.
|
We could solve that by defaulting the alignment of sub-addressable types to the size of the platform address unit (not necessarily 8 bits, as noted above). This introduces a platform dependence in the alignment of some values, but there is precedent for that, it is easily checked at comptime, and the alternative is to inflict this same variability on all known-size types (how many address units in a Related: #5185 (comment) |
In #6706 it was decided that pointers to zero-sized types should not be zero sized. As a consequence of this, zero-sized types now need an ABI alignment. This was chosen to be 0, to preserve the invariant that
@alignOf(T) <= @sizeOf(T)
. However, in #6954, @marler8997 made a strong argument for making it 1, to preserve the invariant@alignOf(T) >= 1
. This issue exists to continue this discussion now that #6945 has been closed.Arguments for align 0:
@alignOf(T) <= @sizeOf(T)
(is this actually useful though?)@alignOf
isn't anything new.Arguments for align 1:
@alignOf(T) >= 1
, removing special cases when using this value.The text was updated successfully, but these errors were encountered: