Skip to content

πŸ’[cxx-interop] Fix memory layout for structs with out-of-order base types #78237

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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Dec 17, 2024

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

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 makes sure that IRGen handles base types of C++ structs in the correct order.

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.

rdar://140848603
(cherry picked from commit 57c7ecd)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Dec 17, 2024
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan marked this pull request as ready for review December 17, 2024 12:56
@egorzhdan egorzhdan requested a review from a team as a code owner December 17, 2024 12:56
@egorzhdan egorzhdan merged commit 8e4cfa3 into release/6.1 Dec 18, 2024
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/6.1-derived-out-of-order branch December 18, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants