1515// ===----------------------------------------------------------------------===//
1616
1717#include " IRGenDebugInfo.h"
18+ #include " GenEnum.h"
1819#include " GenOpaque.h"
1920#include " GenStruct.h"
2021#include " GenType.h"
@@ -1078,8 +1079,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
10781079 llvm::dwarf::DW_TAG_structure_type, UniqueID, Scope, File, Line,
10791080 llvm::dwarf::DW_LANG_Swift, SizeInBits, 0 );
10801081 }
1081- if (OffsetInBits > SizeInBits)
1082- SizeInBits = OffsetInBits;
10831082
10841083 auto DITy = DBuilder.createStructType (
10851084 Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, DerivedFrom,
@@ -1525,7 +1524,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15251524 ? 0
15261525 : DbgTy.getAlignment ().getValue () * SizeOfByte;
15271526 unsigned Encoding = 0 ;
1528- uint32_t NumExtraInhabitants = 0 ;
1527+ uint32_t NumExtraInhabitants = DbgTy.getNumExtraInhabitants ().value_or (0 );
1528+
15291529 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
15301530
15311531 TypeBase *BaseTy = DbgTy.getType ();
@@ -1549,17 +1549,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15491549 Encoding = llvm::dwarf::DW_ATE_unsigned;
15501550 if (auto CompletedDbgTy = CompletedDebugTypeInfo::get (DbgTy))
15511551 SizeInBits = getSizeOfBasicType (*CompletedDbgTy);
1552- if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants ())
1553- NumExtraInhabitants = *DbgTyNumExtraInhabitants;
15541552 break ;
15551553 }
15561554
15571555 case TypeKind::BuiltinIntegerLiteral: {
15581556 Encoding = llvm::dwarf::DW_ATE_unsigned; // ?
15591557 if (auto CompletedDbgTy = CompletedDebugTypeInfo::get (DbgTy))
15601558 SizeInBits = getSizeOfBasicType (*CompletedDbgTy);
1561- if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants ())
1562- NumExtraInhabitants = *DbgTyNumExtraInhabitants;
15631559 break ;
15641560 }
15651561
@@ -1568,48 +1564,30 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15681564 // Assuming that the bitwidth and FloatTy->getFPKind() are identical.
15691565 SizeInBits = FloatTy->getBitWidth ();
15701566 Encoding = llvm::dwarf::DW_ATE_float;
1571- if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants ())
1572- NumExtraInhabitants = *DbgTyNumExtraInhabitants;
15731567 break ;
15741568 }
15751569
1576- case TypeKind::BuiltinNativeObject: {
1577- unsigned PtrSize = CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default);
1578- auto PTy = DBuilder.createPointerType (nullptr , PtrSize, 0 ,
1579- /* DWARFAddressSpace */ llvm::None,
1580- MangledName);
1581- return DBuilder.createObjectPointerType (PTy);
1582- }
1583-
1584- case TypeKind::BuiltinBridgeObject: {
1585- unsigned PtrSize = CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default);
1586- auto PTy = DBuilder.createPointerType (nullptr , PtrSize, 0 ,
1587- /* DWARFAddressSpace */ llvm::None,
1588- MangledName);
1589- return DBuilder.createObjectPointerType (PTy);
1590- }
1591-
1592- case TypeKind::BuiltinRawPointer: {
1593- unsigned PtrSize = CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default);
1594- return DBuilder.createPointerType (nullptr , PtrSize, 0 ,
1595- /* DWARFAddressSpace */ llvm::None,
1596- MangledName);
1597- }
1570+ case TypeKind::BuiltinNativeObject:
1571+ case TypeKind::BuiltinBridgeObject:
1572+ case TypeKind::BuiltinRawPointer:
1573+ case TypeKind::BuiltinRawUnsafeContinuation:
1574+ case TypeKind::BuiltinJob: {
1575+ unsigned PtrSize =
1576+ CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default);
1577+ if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
1578+ Flags |= llvm::DINode::FlagArtificial;
1579+ llvm::DICompositeType *PTy = DBuilder.createStructType (
1580+ Scope, MangledName, File, 0 , PtrSize, 0 , Flags, nullptr , nullptr ,
1581+ llvm::dwarf::DW_LANG_Swift, nullptr , {}, NumExtraInhabitants);
1582+ return PTy;
15981583
1599- case TypeKind::BuiltinRawUnsafeContinuation: {
1600- unsigned PtrSize = CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default);
1601- return DBuilder.createPointerType (nullptr , PtrSize, 0 ,
1602- /* DWARFAddressSpace */ llvm::None,
1603- MangledName);
1604- }
1584+ }
1585+ llvm::DIDerivedType *PTy = DBuilder.createPointerType (
1586+ nullptr , PtrSize, 0 ,
1587+ /* DWARFAddressSpace */ llvm::None, MangledName);
16051588
1606- case TypeKind::BuiltinJob: {
1607- unsigned PtrSize = CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default);
1608- return DBuilder.createPointerType (nullptr , PtrSize, 0 ,
1609- /* DWARFAddressSpace */ llvm::None,
1610- MangledName);
1589+ return DBuilder.createObjectPointerType (PTy);
16111590 }
1612-
16131591 case TypeKind::BuiltinExecutor: {
16141592 return createDoublePointerSizedStruct (
16151593 Scope, " Builtin.Executor" , nullptr , MainFile, 0 ,
@@ -1663,6 +1641,25 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16631641 unsigned FwdDeclLine = 0 ;
16641642 assert (SizeInBits ==
16651643 CI.getTargetInfo ().getPointerWidth (clang::LangAS::Default));
1644+ if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
1645+ auto *DIType = createStructType (
1646+ DbgTy, Decl, ClassTy, Scope, File, L.Line , SizeInBits, AlignInBits,
1647+ Flags, nullptr , llvm::dwarf::DW_LANG_Swift, MangledName);
1648+ assert (DIType && " Unexpected null DIType!" );
1649+ assert (DIType && " createStructType should never return null!" );
1650+ auto SuperClassTy = ClassTy->getSuperclass ();
1651+ if (SuperClassTy) {
1652+ auto SuperClassDbgTy = DebugTypeInfo::getFromTypeInfo (
1653+ SuperClassTy, IGM.getTypeInfoForUnlowered (SuperClassTy), IGM,
1654+ false );
1655+
1656+ llvm::DIType *SuperClassDITy = getOrCreateType (SuperClassDbgTy);
1657+ assert (SuperClassDITy && " getOrCreateType should never return null!" );
1658+ DBuilder.retainType (DBuilder.createInheritance (
1659+ DIType, SuperClassDITy, 0 , 0 , llvm::DINode::FlagZero));
1660+ }
1661+ return DIType;
1662+ }
16661663 return createPointerSizedStruct (Scope, Decl->getNameStr (), L.File ,
16671664 FwdDeclLine, Flags, MangledName);
16681665 }
@@ -2037,6 +2034,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
20372034 }
20382035#endif
20392036
2037+ // / Emits the special builtin types into the debug info. These types are the
2038+ // / ones that are unconditionally emitted into the stdlib's metadata and are
2039+ // / needed to correctly calculate the layout of more complex types built on
2040+ // / top of them.
2041+ void createSpecialStlibBuiltinTypes () {
2042+ if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::ASTTypes)
2043+ return ;
2044+ for (auto BuiltinType: IGM.getOrCreateSpecialStlibBuiltinTypes ()) {
2045+ auto DbgTy = DebugTypeInfo::getFromTypeInfo (
2046+ BuiltinType, IGM.getTypeInfoForUnlowered (BuiltinType), IGM, false );
2047+ DBuilder.retainType (getOrCreateType (DbgTy));
2048+ }
2049+ }
2050+
20402051 llvm::DIType *getOrCreateType (DebugTypeInfo DbgTy) {
20412052 // Is this an empty type?
20422053 if (DbgTy.isNull ())
@@ -2083,6 +2094,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
20832094 TypeDecl = ND;
20842095 Context = ND->getParent ();
20852096 ClangDecl = ND->getClangDecl ();
2097+ } else if (auto BNO = dyn_cast<BuiltinType>(DbgTy.getType ())) {
2098+ Context = BNO->getASTContext ().TheBuiltinModule ;
20862099 }
20872100 if (ClangDecl) {
20882101 clang::ASTReader &Reader = *CI.getClangInstance ().getASTReader ();
@@ -2259,6 +2272,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
22592272 }
22602273 OS << ' "' ;
22612274 }
2275+ createSpecialStlibBuiltinTypes ();
22622276}
22632277
22642278void IRGenDebugInfoImpl::finalize () {
0 commit comments