-
Notifications
You must be signed in to change notification settings - Fork 13.4k
enum / tag alignment is always 1 right now #1645
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Some notes: this is a pain to fix right now due to the possibility of generic tags. Monomorphizing would help. |
I put this on a 0.3 milestone. It should now be feasible thanks to monomorphization. |
After we convert enums to LLVM named structs we may be able to specify their alignment. |
I don't see a way to tell LLVM the alignment of a type. |
There must be a way, since gcc can do it (with attributes). |
Hmm, you may be right. I looked at how clang handled this C file:
and it was not illuminating:
|
It appears that clang just inserts the necessary padding and so forth itself. How disappointing. |
OK, I have the fix in the works and need more test cases. I've found the four |
I ran into an obstacle on 32-bit x86 #2303. |
A good test would be something like:
This currently segfaults for me. |
This should be closed now as it seems to have been fixed. |
Univariants are correct now, and everything agrees with everything else (I think) as far as how enums are represented, but that representation is not actually correct: non-univariant enum bodies are aligned only as much as the discriminant. But I'm not sure if this issue was meant to cover that. |
I think we ought to align non-univariant enums the same way that a C struct like so would be aligned:
That's what this issue was meant to cover. Based on @jld's comment I take it that this is not yet true in all cases, though because we use a |
(Or rather, this issue was meant to cover both the univariant case (which sounds like it is fixed properly) and the multivariant case (not entirely)) |
So, for the multivariant case, I was thinking more like this: union {
struct { some_int_t discr; /* args of variant 1 */ } v1;
/* ... */
struct { some_int_t discr; /* args of variant N */ } vN;
}; This means that cases of less-than-maximal alignment can possibly start earlier, which could save space if they're the longest. Also, it makes things simpler to implement. |
Right now, we do not compute the correct alignment for enum types. Effectively we treat them as
[u8]
at all times. This causes a variety of problems. Mostly it causes poor interaction with shape code and C code, which assumes that we do alignment correctly. I think there is probably an issue for this but I haven't found one that specifically describes it.Some symptoms:
1535: Replacing a type like
int
withenum foo { foo(int) }
is not equivalent. It will cause shape code to misbehave when doing comparisons and the like because shape code will try to align to a word boundary, but the data will be stored with no alignment at all. (For example, I tried to replacety::t
with such a type)The text was updated successfully, but these errors were encountered: