16
16
17
17
#include " GenClass.h"
18
18
19
+ #include " clang/AST/ASTContext.h"
20
+ #include " clang/AST/Decl.h"
21
+ #include " clang/AST/RecordLayout.h"
19
22
#include " swift/ABI/Class.h"
20
23
#include " swift/ABI/MetadataValues.h"
21
24
#include " swift/AST/ASTContext.h"
@@ -281,6 +284,42 @@ namespace {
281
284
superclass);
282
285
}
283
286
287
+ void maybeAddCxxRecordBases (ClassDecl *cd) {
288
+ auto cxxRecord = dyn_cast_or_null<clang::CXXRecordDecl>(cd->getClangDecl ());
289
+ if (!cxxRecord)
290
+ return ;
291
+
292
+ auto &layout = cxxRecord->getASTContext ().getASTRecordLayout (cxxRecord);
293
+
294
+ for (auto base : cxxRecord->bases ()) {
295
+ if (base.isVirtual ())
296
+ continue ;
297
+
298
+ auto baseType = base.getType ().getCanonicalType ();
299
+
300
+ auto baseRecord = cast<clang::RecordType>(baseType)->getDecl ();
301
+ auto baseCxxRecord = cast<clang::CXXRecordDecl>(baseRecord);
302
+
303
+ if (baseCxxRecord->isEmpty ())
304
+ continue ;
305
+
306
+ auto offset = Size (layout.getBaseClassOffset (baseCxxRecord).getQuantity ());
307
+ auto size = Size (cxxRecord->getASTContext ().getTypeSizeInChars (baseType).getQuantity ());
308
+
309
+ if (offset != CurSize) {
310
+ assert (offset > CurSize);
311
+ auto paddingSize = offset - CurSize;
312
+ auto &opaqueTI = IGM.getOpaqueStorageTypeInfo (paddingSize, Alignment (1 ));
313
+ auto element = ElementLayout::getIncomplete (opaqueTI);
314
+ addField (element, LayoutStrategy::Universal);
315
+ }
316
+
317
+ auto &opaqueTI = IGM.getOpaqueStorageTypeInfo (size, Alignment (1 ));
318
+ auto element = ElementLayout::getIncomplete (opaqueTI);
319
+ addField (element, LayoutStrategy::Universal);
320
+ }
321
+ }
322
+
284
323
void addDirectFieldsFromClass (ClassDecl *rootClass, SILType rootClassType,
285
324
ClassDecl *theClass, SILType classType,
286
325
bool superclass) {
@@ -290,6 +329,8 @@ namespace {
290
329
->getRecursiveProperties ()
291
330
.hasUnboundGeneric ());
292
331
332
+ maybeAddCxxRecordBases (theClass);
333
+
293
334
forEachField (IGM, theClass, [&](Field field) {
294
335
// Ignore missing properties here; we should have flagged these
295
336
// with the classHasIncompleteLayout call above.
0 commit comments