@@ -1119,24 +1119,22 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1119
1119
return FwdDecl;
1120
1120
}
1121
1121
1122
- llvm::DICompositeType *
1123
- createStructType (DebugTypeInfo DbgTy, NominalTypeDecl *Decl,
1124
- llvm::DIScope *Scope, llvm::DIFile *File, unsigned Line,
1125
- unsigned SizeInBits, unsigned AlignInBits,
1126
- llvm::DINode::DIFlags Flags, llvm::DIType *DerivedFrom,
1127
- unsigned RuntimeLang, StringRef UniqueID) {
1122
+ llvm::DICompositeType *createStructType (
1123
+ NominalOrBoundGenericNominalType *Type, NominalTypeDecl *Decl,
1124
+ llvm::DIScope *Scope, llvm::DIFile *File, unsigned Line,
1125
+ unsigned SizeInBits, unsigned AlignInBits, llvm::DINode::DIFlags Flags,
1126
+ StringRef MangledName, llvm::DIType *SpecificationOf = nullptr ) {
1128
1127
StringRef Name = Decl->getName ().str ();
1129
1128
auto FwdDecl = createTemporaryReplaceableForwardDecl (
1130
- DbgTy. getType () , Scope, File, Line, SizeInBits, AlignInBits, Flags,
1131
- UniqueID, Name);
1129
+ Type , Scope, File, Line, SizeInBits, AlignInBits, Flags, MangledName ,
1130
+ Name);
1132
1131
// Collect the members.
1133
1132
SmallVector<llvm::Metadata *, 16 > Elements;
1134
1133
unsigned OffsetInBits = 0 ;
1135
1134
for (VarDecl *VD : Decl->getStoredProperties ()) {
1136
- auto memberTy = DbgTy.getType ()->getTypeOfMember (VD);
1137
-
1135
+ auto memberTy = Type->getTypeOfMember (VD);
1138
1136
if (auto DbgTy = CompletedDebugTypeInfo::getFromTypeInfo (
1139
- VD-> getInterfaceType () ,
1137
+ memberTy ,
1140
1138
IGM.getTypeInfoForUnlowered (
1141
1139
IGM.getSILTypes ().getAbstractionPattern (VD), memberTy),
1142
1140
IGM))
@@ -1145,13 +1143,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1145
1143
else
1146
1144
// Without complete type info we can only create a forward decl.
1147
1145
return DBuilder.createForwardDecl (
1148
- llvm::dwarf::DW_TAG_structure_type, UniqueID , Scope, File, Line,
1146
+ llvm::dwarf::DW_TAG_structure_type, MangledName , Scope, File, Line,
1149
1147
llvm::dwarf::DW_LANG_Swift, SizeInBits, 0 );
1150
1148
}
1151
1149
1152
- auto DITy = DBuilder.createStructType (
1153
- Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, DerivedFrom,
1154
- DBuilder.getOrCreateArray (Elements), RuntimeLang, nullptr , UniqueID);
1150
+ llvm::DINodeArray BoundParams = collectGenericParams (Type);
1151
+ auto DITy = createStruct (
1152
+ Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, MangledName,
1153
+ DBuilder.getOrCreateArray (Elements), BoundParams, SpecificationOf);
1155
1154
DBuilder.replaceTemporary (std::move (FwdDecl), DITy);
1156
1155
return DITy;
1157
1156
}
@@ -1267,6 +1266,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1267
1266
auto *Decl = Type->getNominalOrBoundGenericNominal ();
1268
1267
if (!Decl)
1269
1268
return nullptr ;
1269
+
1270
+ // This temporary forward decl seems to be redundant. Can it be removed?
1270
1271
StringRef Name = Decl->getName ().str ();
1271
1272
auto FwdDecl = createTemporaryReplaceableForwardDecl (
1272
1273
Type, Scope, File, Line, SizeInBits, AlignInBits, Flags, MangledName,
@@ -1298,11 +1299,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1298
1299
}
1299
1300
}
1300
1301
1302
+ // Create the substituted type.
1301
1303
auto *OpaqueType =
1302
- createOpaqueStruct (Scope, Decl ? Decl->getNameStr () : " " , File, Line,
1303
- SizeInBits, AlignInBits, Flags, MangledName,
1304
- collectGenericParams (Type), UnsubstitutedDITy);
1305
- DBuilder.replaceTemporary (std::move (FwdDecl), OpaqueType);
1304
+ createStructType (Type, Decl, Scope, File, Line, SizeInBits, AlignInBits,
1305
+ Flags, MangledName, UnsubstitutedDITy);
1306
1306
return OpaqueType;
1307
1307
}
1308
1308
@@ -1712,23 +1712,32 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1712
1712
}
1713
1713
1714
1714
llvm::DICompositeType *
1715
- createOpaqueStruct (llvm::DIScope *Scope, StringRef Name, llvm::DIFile *File,
1716
- unsigned Line, unsigned SizeInBits, unsigned AlignInBits,
1717
- llvm::DINode::DIFlags Flags, StringRef MangledName,
1718
- llvm::DINodeArray BoundParams = {} ,
1719
- llvm::DIType *SpecificationOf = nullptr ) {
1715
+ createStruct (llvm::DIScope *Scope, StringRef Name, llvm::DIFile *File,
1716
+ unsigned Line, unsigned SizeInBits, unsigned AlignInBits,
1717
+ llvm::DINode::DIFlags Flags, StringRef MangledName,
1718
+ llvm::DINodeArray Elements, llvm::DINodeArray BoundParams,
1719
+ llvm::DIType *SpecificationOf) {
1720
1720
1721
1721
auto StructType = DBuilder.createStructType (
1722
1722
Scope, Name, File, Line, SizeInBits, AlignInBits, Flags,
1723
- /* DerivedFrom */ nullptr ,
1724
- DBuilder.getOrCreateArray (ArrayRef<llvm::Metadata *>()),
1725
- llvm::dwarf::DW_LANG_Swift, nullptr , MangledName, SpecificationOf);
1723
+ /* DerivedFrom */ nullptr , Elements, llvm::dwarf::DW_LANG_Swift,
1724
+ nullptr , MangledName, SpecificationOf);
1726
1725
1727
1726
if (BoundParams)
1728
1727
DBuilder.replaceArrays (StructType, nullptr , BoundParams);
1729
1728
return StructType;
1730
1729
}
1731
1730
1731
+ llvm::DICompositeType *
1732
+ createOpaqueStruct (llvm::DIScope *Scope, StringRef Name, llvm::DIFile *File,
1733
+ unsigned Line, unsigned SizeInBits, unsigned AlignInBits,
1734
+ llvm::DINode::DIFlags Flags, StringRef MangledName,
1735
+ llvm::DINodeArray BoundParams = {},
1736
+ llvm::DIType *SpecificationOf = nullptr ) {
1737
+ return createStruct (Scope, Name, File, Line, SizeInBits, AlignInBits, Flags,
1738
+ MangledName, {}, BoundParams, SpecificationOf);
1739
+ }
1740
+
1732
1741
bool shouldCacheDIType (llvm::DIType *DITy, DebugTypeInfo &DbgTy) {
1733
1742
// Don't cache a type alias to a forward declaration either.
1734
1743
if (DbgTy.isFixedBuffer () || DITy->isForwardDecl ())
@@ -1794,7 +1803,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1794
1803
llvm_unreachable (" not a real type" );
1795
1804
1796
1805
case TypeKind::BuiltinFixedArray: {
1797
- // TODO: provide proper array debug info
1806
+ if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
1807
+ auto *FixedArray = llvm::cast<swift::BuiltinFixedArrayType>(BaseTy);
1808
+ llvm::DIType *ElementTy = getOrCreateType (FixedArray->getElementType ());
1809
+ llvm::SmallVector<llvm::Metadata *, 2 > Subscripts;
1810
+ if (auto NumElts = FixedArray->getFixedInhabitedSize ()) {
1811
+ auto *NumEltsNode = llvm::ConstantAsMetadata::get (
1812
+ llvm::ConstantInt::get (IGM.Int64Ty , *NumElts));
1813
+ Subscripts.push_back (DBuilder.getOrCreateSubrange (
1814
+ NumEltsNode /* count*/ , nullptr /* lowerBound*/ ,
1815
+ nullptr /* upperBound*/ , nullptr /* stride*/ ));
1816
+ }
1817
+ return DBuilder.createArrayType (SizeInBits, AlignInBits, ElementTy,
1818
+ DBuilder.getOrCreateArray (Subscripts));
1819
+ }
1798
1820
unsigned FwdDeclLine = 0 ;
1799
1821
return createOpaqueStruct (Scope, " Builtin.FixedArray" , MainFile,
1800
1822
FwdDeclLine, SizeInBits, AlignInBits, Flags,
@@ -1876,9 +1898,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1876
1898
return createSpecializedStructOrClassType (
1877
1899
StructTy, Scope, L.File , L.Line , SizeInBits, AlignInBits,
1878
1900
Flags, MangledName);
1879
- return createStructType (DbgTy, Decl, Scope, L.File , L.Line ,
1880
- SizeInBits, AlignInBits, Flags, nullptr ,
1881
- llvm::dwarf::DW_LANG_Swift, MangledName);
1901
+ return createStructType (StructTy, Decl, Scope, L.File , L.Line ,
1902
+ SizeInBits, AlignInBits, Flags, MangledName);
1882
1903
}
1883
1904
StringRef Name = Decl->getName ().str ();
1884
1905
if (!SizeInBitsOrNull)
@@ -1910,9 +1931,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1910
1931
ClassTy, Scope, L.File , L.Line , SizeInBits, AlignInBits,
1911
1932
Flags, MangledName);
1912
1933
1913
- auto *DIType = createStructType (
1914
- DbgTy , Decl, Scope, File, L.Line , SizeInBits, AlignInBits ,
1915
- Flags, nullptr , llvm::dwarf::DW_LANG_Swift , MangledName);
1934
+ auto *DIType =
1935
+ createStructType (ClassTy , Decl, Scope, File, L.Line , SizeInBits,
1936
+ AlignInBits, Flags , MangledName);
1916
1937
assert (DIType && " Unexpected null DIType!" );
1917
1938
assert (DIType && " createStructType should never return null!" );
1918
1939
auto SuperClassTy = ClassTy->getSuperclass ();
0 commit comments