-
Notifications
You must be signed in to change notification settings - Fork 106
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
Padding for union type #1281
Comments
I'd be worried about this given potential duplication, but there's likely an approach where we can bake all current functionality of struct type into an interface and have union extend that.
|
Well, I think we can - there will be a bunch of boring changes though) I think we can add an extra data member into And in the CIRRecordLayputBuilder pass extra boolean parameter into Does it sound like a plan for you? |
I'm not 100% sure what's the best solution here, just putting extra options on the table so we can discuss a potential less intrusive solution.
Why touch Also, if we have to change
I'm not sure that decision still holds, specially in light of what you are bringing up. Perhaps we should just do it early? |
Let me briefly remind how it's done in the OG's
Now, coming back to CIR. The same AST methods are used in But it will be hard to distinguish the type used for padding from the other members later. That is where the idea of adding an additional boolean Another approach I tried is to extract the
The idea was to pass the information via
I'll do my best! So ... I don't know if I wrote a good explanation. But if I did - may be now you have more thoughts? |
Agreed!
Food for thought: are we using the other members for anything right now? Have you considered removing that altogether for something more simple? This could be one the things designed too early without use case in mind that maybe should be reintroduced later whenever there's a use case. If we remove the other members, would it make handling this a bit more clean (or in a generic way that doesn't require knowledge about the type being a union)?
This is a viable solution, I have some other higher level questions about the API: if
Nah, rather not depend on AST presence for this! |
So the solution is almost here!
I would say we don't really use them - unless I missed something. And yes - the easiest solution would be just to stick to the OG and don't emit record type with all the possible members enumerated for unions and save only the largest one and padding. But since we already did the opposite - and may be it's even good, since it preserves more information from AST - I would keep it like it is.
yes. But looks like
First of all, this Thus, with such approach it won't be matter which exact type it is - struct, class or union. Finally, I even think we don't need
that makes me happy! |
Sweet, sounds like a plan then! |
Good! To make sure we are on the same page - I add |
There is a problem with union type: it has no padding. And it's important to have one.
Example:
This is how the original LLVM IR looks like:
As one can see, there is an extra padding for the union type:
[2 x i8] zeroinitializer
, andg0
size is 4 bytes in total. And forg2
offset is computes as 4 - since it points to the second element ofg1
.LLVM IR after CIR doesn't have these padding bytes neither it has
union
keyword (I wonder when we lost it but it's not a problem right now).g0
has size of 2 bytes, so asg1
element size as well.The problem is in the
g2
initialization: unfortunately the offset is computed fromAPValue
methods here and is equal to 4 as in the OG, no CIR is involved.Thus, the offset of the second element of
g1
is computed as 4, and element size is 2 -> we got wrong indices for theGlobalViewAttr
from the very beginning:@g2 = #cir.global_view<@g1, [2 : i32]> : !cir.ptr<!u16i>
!The
g0
size is 2 because for unions we compute size as a size of the largest member and nothing else.According to the comments we chose to track all union members and deffer padding computation to the lowering. But looks like that was not happened.
So the question is - what do you think, how to fix it properly?
I see the following ways:
Any other thoughts, ideas?
The text was updated successfully, but these errors were encountered: