Skip to content

Commit ef5aae1

Browse files
authored
Merge pull request #72445 from augusto2112/zero-unsub-types-main
[DebugInfo] Always emit unsubsituted generic types with size 0
2 parents cc1bf0d + 128d452 commit ef5aae1

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
@@ -1134,11 +1134,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11341134
llvm::DICompositeType *createUnsubstitutedGenericStructOrClassType(
11351135
DebugTypeInfo DbgTy, NominalTypeDecl *Decl, Type UnsubstitutedType,
11361136
llvm::DIScope *Scope, llvm::DIFile *File, unsigned Line,
1137-
unsigned SizeInBits, unsigned AlignInBits, llvm::DINode::DIFlags Flags,
1138-
llvm::DIType *DerivedFrom, unsigned RuntimeLang, StringRef UniqueID) {
1137+
llvm::DINode::DIFlags Flags, llvm::DIType *DerivedFrom,
1138+
unsigned RuntimeLang, StringRef UniqueID) {
11391139
// FIXME: ideally, we'd like to emit this type with no size and alignment at
11401140
// all (instead of emitting them as 0). Fix this by changing DIBuilder to
11411141
// allow for struct types that have optional size and alignment.
1142+
unsigned SizeInBits = 0;
1143+
unsigned AlignInBits = 0;
11421144
StringRef Name = Decl->getName().str();
11431145
auto FwdDecl = createStructForwardDecl(DbgTy, Decl, Scope, File, Line,
11441146
SizeInBits, Flags, UniqueID, Name);
@@ -1181,8 +1183,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11811183
std::string DeclTypeMangledName = Mangler.mangleTypeForDebugger(
11821184
UnsubstitutedTy->mapTypeOutOfContext(), {});
11831185
if (DeclTypeMangledName == MangledName) {
1184-
return createUnsubstitutedVariantType(DbgTy, Decl, MangledName,
1185-
SizeInBits, AlignInBits, Scope,
1186+
return createUnsubstitutedVariantType(DbgTy, Decl, MangledName, Scope,
11861187
File, 0, Flags);
11871188
}
11881189
auto FwdDecl = llvm::TempDIType(DBuilder.createReplaceableCompositeType(
@@ -1241,9 +1242,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
12411242
Mangler.mangleTypeForDebugger(UnsubstitutedTy->mapTypeOutOfContext(), {});
12421243
if (DeclTypeMangledName == MangledName) {
12431244
return createUnsubstitutedGenericStructOrClassType(
1244-
DbgTy, Decl, UnsubstitutedTy, Scope, File, Line, SizeInBits,
1245-
AlignInBits, Flags, nullptr, llvm::dwarf::DW_LANG_Swift,
1246-
DeclTypeMangledName);
1245+
DbgTy, Decl, UnsubstitutedTy, Scope, File, Line, Flags, nullptr,
1246+
llvm::dwarf::DW_LANG_Swift, DeclTypeMangledName);
12471247
}
12481248
// Force the creation of the unsubstituted type, don't create it
12491249
// directly so it goes through all the caching/verification logic.
@@ -1336,7 +1336,7 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
13361336
llvm::DIFile *File, unsigned Line,
13371337
llvm::DINode::DIFlags Flags) {
13381338
assert(!Decl->getRawType() &&
1339-
"Attempting to create variant debug info from raw enum!");
1339+
"Attempting to create variant debug info from raw enum!");;
13401340

13411341
StringRef Name = Decl->getName().str();
13421342
unsigned SizeInBits = DbgTy.getSizeInBits();
@@ -1408,7 +1408,6 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
14081408
llvm::DICompositeType *
14091409
createUnsubstitutedVariantType(DebugTypeInfo DbgTy, EnumDecl *Decl,
14101410
StringRef MangledName,
1411-
unsigned SizeInBits, unsigned AlignInBits,
14121411
llvm::DIScope *Scope, llvm::DIFile *File,
14131412
unsigned Line, llvm::DINode::DIFlags Flags) {
14141413
assert(!Decl->getRawType() &&
@@ -1417,6 +1416,8 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
14171416
StringRef Name = Decl->getName().str();
14181417
auto NumExtraInhabitants = DbgTy.getNumExtraInhabitants();
14191418

1419+
unsigned SizeInBits = 0;
1420+
unsigned AlignInBits = 0;
14201421
// A variant part should actually be a child to a DW_TAG_structure_type
14211422
// according to the DWARF spec.
14221423
llvm::TempDICompositeType FwdDecl(DBuilder.createReplaceableCompositeType(
@@ -2091,7 +2092,7 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
20912092
auto L = getFileAndLocation(Decl);
20922093
unsigned FwdDeclLine = 0;
20932094
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
2094-
if (EnumTy->isSpecialized())
2095+
if (EnumTy->isSpecialized() && !Decl->hasRawType())
20952096
return createSpecializedEnumType(EnumTy, Decl, MangledName,
20962097
SizeInBits, AlignInBits, Scope, File,
20972098
FwdDeclLine, Flags);
@@ -2271,6 +2272,12 @@ createSpecializedStructOrClassType(NominalOrBoundGenericNominalType *Type,
22712272
unsigned CachedSizeInBits = getSizeInBits(CachedType);
22722273
if ((SizeInBits && CachedSizeInBits != *SizeInBits) ||
22732274
(!SizeInBits && CachedSizeInBits)) {
2275+
// In some situation a specialized type is emitted with size 0, even if the real
2276+
// type has a size.
2277+
if (DbgTy.getType()->isSpecialized() && SizeInBits && *SizeInBits > 0 &&
2278+
CachedSizeInBits == 0)
2279+
return true;
2280+
22742281
CachedType->dump();
22752282
DbgTy.dump();
22762283
llvm::errs() << "SizeInBits = " << SizeInBits << "\n";

0 commit comments

Comments
 (0)