π[cxx-interop] Fix memory layout for structs with out-of-order base types #78237
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: In C++, a primary base class that is placed in the beginning of the type's memory layout isn't always the type that is the first in the list of bases β the base types might be laid out in memory in a different order.
This change makes sure that IRGen handles base types of C++ structs in the correct order.
Scope: This fixes an assertion in asserts-enabled compilers, and an out-of-memory error in asserts-disabled compilers. The issue was happening for both value types and foreign reference types. This change also includes a small refactoring to reuse the logic between the two code paths.
Risk: Low, this only applies to C++ structs, and the behavior is only altered for structs with multiple inheritance.
Testing: Added compiler tests.
Issue: rdar://140848603
Reviewer: @rjmccall @j-hui @Xazax-hun
Original PR: #78166