@@ -1451,6 +1451,8 @@ class ClangRecordLowering {
1451
1451
// / Place the next struct field at its appropriate offset.
1452
1452
void addStructField (const clang::FieldDecl *clangField,
1453
1453
VarDecl *swiftField, const clang::ASTRecordLayout &layout) {
1454
+ // Skip importing zero-sized fields for now.
1455
+ bool isZeroSized = clangField->isZeroSize (ClangContext);
1454
1456
unsigned fieldOffset = layout.getFieldOffset (clangField->getFieldIndex ());
1455
1457
assert (!clangField->isBitField ());
1456
1458
Size offset ( SubobjectAdjustment.getValue () + fieldOffset / 8 );
@@ -1460,12 +1462,12 @@ class ClangRecordLowering {
1460
1462
auto &fieldTI = cast<FixedTypeInfo>(IGM.getTypeInfo (
1461
1463
SwiftType.getFieldType (swiftField, IGM.getSILModule (),
1462
1464
IGM.getMaximalTypeExpansionContext ())));
1463
- addField (swiftField, offset, fieldTI);
1465
+ addField (swiftField, offset, fieldTI, isZeroSized );
1464
1466
return ;
1465
1467
}
1466
1468
1467
1469
// Otherwise, add it as an opaque blob.
1468
- auto fieldSize = ClangContext.getTypeSizeInChars (clangField->getType ());
1470
+ auto fieldSize = isZeroSized ? clang::CharUnits::Zero () : ClangContext.getTypeSizeInChars (clangField->getType ());
1469
1471
return addOpaqueField (offset, Size (fieldSize.getQuantity ()));
1470
1472
}
1471
1473
@@ -1491,23 +1493,23 @@ class ClangRecordLowering {
1491
1493
if (fieldSize.isZero ()) return ;
1492
1494
1493
1495
auto &opaqueTI = IGM.getOpaqueStorageTypeInfo (fieldSize, Alignment (1 ));
1494
- addField (nullptr , offset, opaqueTI);
1496
+ addField (nullptr , offset, opaqueTI, false );
1495
1497
}
1496
1498
1497
1499
// / Add storage for an (optional) Swift field at the given offset.
1498
1500
void addField (VarDecl *swiftField, Size offset,
1499
- const FixedTypeInfo &fieldType) {
1500
- assert (offset >= NextOffset && " adding fields out of order" );
1501
+ const FixedTypeInfo &fieldType, bool isZeroSized ) {
1502
+ assert (isZeroSized || offset >= NextOffset && " adding fields out of order" );
1501
1503
1502
1504
// Add a padding field if required.
1503
- if (offset != NextOffset)
1505
+ if (!isZeroSized && offset != NextOffset)
1504
1506
addPaddingField (offset);
1505
1507
1506
- addFieldInfo (swiftField, fieldType);
1508
+ addFieldInfo (swiftField, fieldType, isZeroSized );
1507
1509
}
1508
1510
1509
1511
// / Add information to track a value field at the current offset.
1510
- void addFieldInfo (VarDecl *swiftField, const FixedTypeInfo &fieldType) {
1512
+ void addFieldInfo (VarDecl *swiftField, const FixedTypeInfo &fieldType, bool isZeroSized ) {
1511
1513
bool isLoadableField = isa<LoadableTypeInfo>(fieldType);
1512
1514
unsigned explosionSize = 0 ;
1513
1515
if (isLoadableField)
@@ -1517,11 +1519,15 @@ class ClangRecordLowering {
1517
1519
unsigned explosionEnd = NextExplosionIndex;
1518
1520
1519
1521
ElementLayout layout = ElementLayout::getIncomplete (fieldType);
1520
- auto isEmpty = fieldType.isKnownEmpty (ResilienceExpansion::Maximal);
1521
- if (isEmpty)
1522
- layout.completeEmptyTailAllocatedCType (
1523
- fieldType.isTriviallyDestroyable (ResilienceExpansion::Maximal), NextOffset);
1524
- else
1522
+ auto isEmpty = isZeroSized || fieldType.isKnownEmpty (ResilienceExpansion::Maximal);
1523
+ if (isEmpty) {
1524
+ if (isZeroSized)
1525
+ layout.completeEmpty (
1526
+ fieldType.isTriviallyDestroyable (ResilienceExpansion::Maximal), NextOffset);
1527
+ else
1528
+ layout.completeEmptyTailAllocatedCType (
1529
+ fieldType.isTriviallyDestroyable (ResilienceExpansion::Maximal), NextOffset);
1530
+ } else
1525
1531
layout.completeFixed (fieldType.isTriviallyDestroyable (ResilienceExpansion::Maximal),
1526
1532
NextOffset, LLVMFields.size ());
1527
1533
0 commit comments