Fixes GH#53983.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
See: https://github.com/llvm/llvm-project/issues/53983
I can add a release note and some testing, but wanted feedback that this was the right approach. The problem is when generating code for the constructor for the bar element inside of MyStruct, Dest has an elementType of Base, but Builder.CreateStructGEP assumes the {i8, i8} layout implied by Base. which causes an assert trying to emit code for the second element. So, I've added logic to make sure the layout of STy and Dest are identical, which fixes the assert but doesn't break any of the existing testing around aggregate stores.
AFAICT the AST and lowering all looks correct, and this is an issue in code generation. But this is a new area of clang for me so I'd welcome suggestions about if there is a better fix or if the fix should be in a different place. Thanks!
The change seems reasonable. Could you add a test with a crasher repro and some validation of the generated IR?
Sorry, didn't see your comment when submitting mine.
I think the offending code is clearly wrong here and adding the isLayoutIdentical seems like the right thing to do.
This looks like a small change and I'm happy to LGTM this myself.
However, I also have very little experience with codegen, you might want to find someone more experienced with it to have a more informed look. @jyknight maybe?
clang/lib/CodeGen/CGCall.cpp | ||
---|---|---|
1338 | Is it guaranteed that Dest.getElementType() is never something other than StructType? |
Add newline at end of test file.
clang/lib/CodeGen/CGCall.cpp | ||
---|---|---|
1338 | Yikes, no. And checking the cast as another condition broke a bunch of other cases. This works much better. |
clang/lib/CodeGen/CGCall.cpp | ||
---|---|---|
1338 | Intuitively, I feel like canLosslesslyBitCastTo should be used in conjuction with something like Builder.CreateBitcast and after a quick skim through existing I can't find any uses with CreateStore in the codebase. This leads me to think that we need to call a different function here. As mentioned earlier, I may be completely wrong as I don't have much experience with codegen. I will let @jyknight sanity-check my intuition. |
Is it guaranteed that Dest.getElementType() is never something other than StructType?