Commit Graph

6 Commits

Author SHA1 Message Date
Egor Zhdan
a7c174431f [cxx-interop] Do not crash when emitting layout of std::string
If a `[[no_unique_address]]` field has zero size according to Clang, and field has a type that isn't representable in Swift, Swift would previously try to add an opaque field of size 1 for it.

This is wrong and was causing crashes for `std::string` while emitting a padding field:
```
_LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding<T1> _LIBCPP_CONCAT3(__padding1_, __LINE__, _);
```

rdar://151941799
2025-05-30 17:32:15 +01:00
John Hui
1fdb239cea [cxx-interop] Avoid querying layout of dependent types during symbolic import
In #80786, we started importing certain padded fields as opaque blobs.
Part of this logic involved querying those fields' ASTRecordLayout.
However, dependent types (which are imported symbolically) do not have
an ASTRecordLayout, so calling Clang's getASTRecordLayout() would lead
to an assertion error for class templates where a no_unique_address
field is some kind of dependent C++ record type.

This patch avoids the field padding check during symbolic import mode
because that check is only relevant for codegen anyway.

rdar://150067288
2025-04-30 18:36:29 -07:00
John Hui
5fdbb44041 [NFC] Add test where the padding of a [[no_unique_address]] field with a custom type is reused 2025-04-30 18:15:27 -07:00
John Hui
9b0ab9095e [NFC] Rename types to mention optional 2025-04-30 15:48:10 -07:00
Gabor Horvath
939ee49dcb [cxx-interop] Fix a crash with [[no_unique_address]]
Swift does not support storing fields in the padding of the previous
fields just yet, so let's not import fields like that from C++.
Represent them as opaque blobs instead.

Fixes #80764

rdar://149072458
2025-04-25 12:46:31 +01:00
Gabor Horvath
998591e9f9 [cxx-interop] Do not import zero-sized fields
Zero sized fields are messing up the offset calculations when we import
C++ fields to Swift. We assume that the size of the field is determined
by the type of the field. This is not true for fields marked with
no_unique_address. Those fields can have 0 size while the
sizeof(decltype(field)) is still 1.

rdar://143907490
2025-02-03 11:55:54 +00:00