-
Notifications
You must be signed in to change notification settings - Fork 127
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
[CIR][CodeGen][BugFix] use proper base type for derived class #404
Conversation
Thanks for working on this.
I had several problems with the pointers/pointees in that section of the code in the past, I had some fun with an ASANified version of clang in order to figure out. So I'm a bit scared with this change (let me see if I can find the previous commits in question). However, that was before @sitio-couto changed the StructType to be mutable, so perhaps the problems I fixed in the past are also gone because of his change. I like the end result of this change, which is keeping the base class type around. @sitio-couto since you touched this last, thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcardosolopes @gitoleg I'm not sure I agree with this change.
we were rewriting the type being processed (due tp misused pointers).
@gitoleg, can you clarify this comment? I'm concerned because StructType shouldn't change post-completion (see CIRGenBuilder::getCompleteStructTy
and StructType::complete
).
In the original codegen a new type is created for the base class
Regarding the base class's new type in the original codegen, I thought it was just for alignment (e.g., example). With this change, there's a lack of padding info for class.A.base
, and seems premature. Maybe It would be better suited at the lowering phase. Overall, this seems to just replicate a struct type without any clear advantages. @gitoleg am I missing something?
@bcardosolopes while I don't see many benefits here, I don't know much about codegen for virtual methods/classes, so take it with a grain of salt.
well, I will do my best to explain!
line №1: Base type pointer is initialized to nullptr now let's take a look at our code
line №1: Base type pointer is initialized to nullptr (same) Finally. Yes, (as far as I understand), base class is used for alignment, when the class itself need to be padded with zeros and derived classes don't need this padding. But it's the next story - this PR is just bug fixing and I have the PR that adds all the unimplemented functions like @sitio-couto I don't know if I explained clear enough, so please let me know if I did not :) |
@gitoleg thanks for the in-depth explanation! Now I understand (nice catch BTW)!
Shouldn't the new
In this case, have you considered deferring this to the lowering phase? I don't see why we would need this low-level information in CIR. It might even complicate passes since they will have to consider different versions of the same class type. @bcardosolopes seems like a case of early optimization, WDYT? |
@gitoleg thanks for the detailed explanation!
The fact that we were missing the
That's an interesting point, I like the idea. However, if we go this direction, I believe we need to change Anyways, I think this PR should be good to land before we decide how the other bits are getting introduced. Any objections @sitio-couto? |
@bcardosolopes none.
Sounds good. |
4e069c6
to
79d4dc7
Compare
@lanza just rebased and this has the side effect of breaking GH PR workflow, making it impossible to review, apologies. Please rebase! |
c3a9271
to
202522d
Compare
@bcardosolopes done! |
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.
In the original codegen a new type is created for the base class, while in CIR we were rewriting the type being processed (due tp misused pointers). This PR fix this, and also makes CIR codegen even with the original one.