Skip to content

Commit 128d452

Browse files
committed
[DebugInfo] Always emit unsubsituted generic types with size 0
Unsubstituted generic types shouldn't have a size, precisely because the generic parameters aren't substituted in. Always emit them with a size 0.
1 parent bd1b99b commit 128d452

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11251125
llvm::DICompositeType *createUnsubstitutedGenericStructOrClassType(
11261126
DebugTypeInfo DbgTy, NominalTypeDecl *Decl, Type UnsubstitutedType,
11271127
llvm::DIScope *Scope, llvm::DIFile *File, unsigned Line,
1128-
unsigned SizeInBits, unsigned AlignInBits, llvm::DINode::DIFlags Flags,
1129-
llvm::DIType *DerivedFrom, unsigned RuntimeLang, StringRef UniqueID) {
1128+
llvm::DINode::DIFlags Flags, llvm::DIType *DerivedFrom,
1129+
unsigned RuntimeLang, StringRef UniqueID) {
11301130
// FIXME: ideally, we'd like to emit this type with no size and alignment at
11311131
// all (instead of emitting them as 0). Fix this by changing DIBuilder to
11321132
// allow for struct types that have optional size and alignment.
1133+
unsigned SizeInBits = 0;
1134+
unsigned AlignInBits = 0;
11331135
StringRef Name = Decl->getName().str();
11341136
auto FwdDecl = createStructForwardDecl(DbgTy, Decl, Scope, File, Line,
11351137
SizeInBits, Flags, UniqueID, Name);
@@ -1172,8 +1174,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11721174
std::string DeclTypeMangledName = Mangler.mangleTypeForDebugger(
11731175
UnsubstitutedTy->mapTypeOutOfContext(), {});
11741176
if (DeclTypeMangledName == MangledName) {
1175-
return createUnsubstitutedVariantType(DbgTy, Decl, MangledName,
1176-
SizeInBits, AlignInBits, Scope,
1177+
return createUnsubstitutedVariantType(DbgTy, Decl, MangledName, Scope,
11771178
File, 0, Flags);
11781179
}
11791180
auto FwdDecl = llvm::TempDIType(DBuilder.createReplaceableCompositeType(
@@ -1232,9 +1233,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
12321233
Mangler.mangleTypeForDebugger(UnsubstitutedTy->mapTypeOutOfContext(), {});
12331234
if (DeclTypeMangledName == MangledName) {
12341235
return createUnsubstitutedGenericStructOrClassType(
1235-
DbgTy, Decl, UnsubstitutedTy, Scope, File, Line, SizeInBits,
1236-
AlignInBits, Flags, nullptr, llvm::dwarf::DW_LANG_Swift,
1237-
DeclTypeMangledName);
1236+
DbgTy, Decl, UnsubstitutedTy, Scope, File, Line, Flags, nullptr,
1237+
llvm::dwarf::DW_LANG_Swift, DeclTypeMangledName);
12381238
}
12391239
// Force the creation of the unsubstituted type, don't create it
12401240
// directly so it goes through all the caching/verification logic.
@@ -1327,7 +1327,7 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
13271327
llvm::DIFile *File, unsigned Line,
13281328
llvm::DINode::DIFlags Flags) {
13291329
assert(!Decl->getRawType() &&
1330-
"Attempting to create variant debug info from raw enum!");
1330+
"Attempting to create variant debug info from raw enum!");;
13311331

13321332
StringRef Name = Decl->getName().str();
13331333
unsigned SizeInBits = DbgTy.getSizeInBits();
@@ -1399,7 +1399,6 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
13991399
llvm::DICompositeType *
14001400
createUnsubstitutedVariantType(DebugTypeInfo DbgTy, EnumDecl *Decl,
14011401
StringRef MangledName,
1402-
unsigned SizeInBits, unsigned AlignInBits,
14031402
llvm::DIScope *Scope, llvm::DIFile *File,
14041403
unsigned Line, llvm::DINode::DIFlags Flags) {
14051404
assert(!Decl->getRawType() &&
@@ -1408,6 +1407,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
14081407
StringRef Name = Decl->getName().str();
14091408
auto NumExtraInhabitants = DbgTy.getNumExtraInhabitants();
14101409

1410+
unsigned SizeInBits = 0;
1411+
unsigned AlignInBits = 0;
14111412
// A variant part should actually be a child to a DW_TAG_structure_type
14121413
// according to the DWARF spec.
14131414
auto FwdDecl = llvm::TempDIType(DBuilder.createReplaceableCompositeType(
@@ -2082,7 +2083,7 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
20822083
auto L = getFileAndLocation(Decl);
20832084
unsigned FwdDeclLine = 0;
20842085
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
2085-
if (EnumTy->isSpecialized())
2086+
if (EnumTy->isSpecialized() && !Decl->hasRawType())
20862087
return createSpecializedEnumType(EnumTy, Decl, MangledName,
20872088
SizeInBits, AlignInBits, Scope, File,
20882089
FwdDeclLine, Flags);
@@ -2262,6 +2263,12 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
22622263
unsigned CachedSizeInBits = getSizeInBits(CachedType);
22632264
if ((SizeInBits && CachedSizeInBits != *SizeInBits) ||
22642265
(!SizeInBits && CachedSizeInBits)) {
2266+
// In some situation a specialized type is emitted with size 0, even if the real
2267+
// type has a size.
2268+
if (DbgTy.getType()->isSpecialized() && SizeInBits && *SizeInBits > 0 &&
2269+
CachedSizeInBits == 0)
2270+
return true;
2271+
22652272
CachedType->dump();
22662273
DbgTy.dump();
22672274
llvm::errs() << "SizeInBits = " << SizeInBits << "\n";

0 commit comments

Comments
 (0)