Skip to content

Commit 69f7dba

Browse files
committed
[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
1 parent 278248e commit 69f7dba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/IRGen/GenStruct.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,11 @@ class ClangRecordLowering {
14801480
}
14811481

14821482
// Otherwise, add it as an opaque blob.
1483-
auto fieldSize = isZeroSized ? clang::CharUnits::Zero() : ClangContext.getTypeSizeInChars(clangField->getType());
1484-
return addOpaqueField(offset,
1485-
dataSize.value_or(Size(fieldSize.getQuantity())));
1483+
auto fieldTypeSize = ClangContext.getTypeSizeInChars(clangField->getType());
1484+
auto fieldSize = isZeroSized
1485+
? clang::CharUnits::Zero()
1486+
: dataSize.value_or(Size(fieldTypeSize.getQuantity()));
1487+
return addOpaqueField(offset, Size(fieldSize.getQuantity()));
14861488
}
14871489

14881490
/// Add opaque storage for bitfields spanning the given range of bits.

0 commit comments

Comments
 (0)