15
15
// ===----------------------------------------------------------------------===//
16
16
17
17
#include " IRGenDebugInfo.h"
18
+ #include " GenEnum.h"
18
19
#include " GenOpaque.h"
19
20
#include " GenStruct.h"
20
21
#include " GenType.h"
@@ -1078,8 +1079,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1078
1079
llvm::dwarf::DW_TAG_structure_type, UniqueID, Scope, File, Line,
1079
1080
llvm::dwarf::DW_LANG_Swift, SizeInBits, 0 );
1080
1081
}
1081
- if (OffsetInBits > SizeInBits)
1082
- SizeInBits = OffsetInBits;
1083
1082
1084
1083
auto DITy = DBuilder.createStructType (
1085
1084
Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, DerivedFrom,
@@ -1525,7 +1524,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1525
1524
? 0
1526
1525
: DbgTy.getAlignment ().getValue () * SizeOfByte;
1527
1526
unsigned Encoding = 0 ;
1528
- uint32_t NumExtraInhabitants = 0 ;
1527
+ uint32_t NumExtraInhabitants = DbgTy.getNumExtraInhabitants ().value_or (0 );
1528
+
1529
1529
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1530
1530
1531
1531
TypeBase *BaseTy = DbgTy.getType ();
@@ -1549,17 +1549,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1549
1549
Encoding = llvm::dwarf::DW_ATE_unsigned;
1550
1550
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get (DbgTy))
1551
1551
SizeInBits = getSizeOfBasicType (*CompletedDbgTy);
1552
- if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants ())
1553
- NumExtraInhabitants = *DbgTyNumExtraInhabitants;
1554
1552
break ;
1555
1553
}
1556
1554
1557
1555
case TypeKind::BuiltinIntegerLiteral: {
1558
1556
Encoding = llvm::dwarf::DW_ATE_unsigned; // ?
1559
1557
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get (DbgTy))
1560
1558
SizeInBits = getSizeOfBasicType (*CompletedDbgTy);
1561
- if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants ())
1562
- NumExtraInhabitants = *DbgTyNumExtraInhabitants;
1563
1559
break ;
1564
1560
}
1565
1561
@@ -1568,48 +1564,30 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1568
1564
// Assuming that the bitwidth and FloatTy->getFPKind() are identical.
1569
1565
SizeInBits = FloatTy->getBitWidth ();
1570
1566
Encoding = llvm::dwarf::DW_ATE_float;
1571
- if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants ())
1572
- NumExtraInhabitants = *DbgTyNumExtraInhabitants;
1573
1567
break ;
1574
1568
}
1575
1569
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;
1598
1583
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);
1605
1588
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);
1611
1590
}
1612
-
1613
1591
case TypeKind::BuiltinExecutor: {
1614
1592
return createDoublePointerSizedStruct (
1615
1593
Scope, " Builtin.Executor" , nullptr , MainFile, 0 ,
@@ -1663,6 +1641,25 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1663
1641
unsigned FwdDeclLine = 0 ;
1664
1642
assert (SizeInBits ==
1665
1643
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
+ }
1666
1663
return createPointerSizedStruct (Scope, Decl->getNameStr (), L.File ,
1667
1664
FwdDeclLine, Flags, MangledName);
1668
1665
}
@@ -2037,6 +2034,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2037
2034
}
2038
2035
#endif
2039
2036
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
+
2040
2051
llvm::DIType *getOrCreateType (DebugTypeInfo DbgTy) {
2041
2052
// Is this an empty type?
2042
2053
if (DbgTy.isNull ())
@@ -2083,6 +2094,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2083
2094
TypeDecl = ND;
2084
2095
Context = ND->getParent ();
2085
2096
ClangDecl = ND->getClangDecl ();
2097
+ } else if (auto BNO = dyn_cast<BuiltinType>(DbgTy.getType ())) {
2098
+ Context = BNO->getASTContext ().TheBuiltinModule ;
2086
2099
}
2087
2100
if (ClangDecl) {
2088
2101
clang::ASTReader &Reader = *CI.getClangInstance ().getASTReader ();
@@ -2259,6 +2272,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
2259
2272
}
2260
2273
OS << ' "' ;
2261
2274
}
2275
+ createSpecialStlibBuiltinTypes ();
2262
2276
}
2263
2277
2264
2278
void IRGenDebugInfoImpl::finalize () {
0 commit comments