Skip to content

Commit 2084da1

Browse files
committed
Emit the special stdlib builtin types into full dwarf metadata
1 parent 5f8da9e commit 2084da1

File tree

2 files changed

+67
-41
lines changed

2 files changed

+67
-41
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "IRGenDebugInfo.h"
18+
#include "GenEnum.h"
1819
#include "GenOpaque.h"
1920
#include "GenStruct.h"
2021
#include "GenType.h"
@@ -1525,7 +1526,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15251526
? 0
15261527
: DbgTy.getAlignment().getValue() * SizeOfByte;
15271528
unsigned Encoding = 0;
1528-
uint32_t NumExtraInhabitants = 0;
1529+
uint32_t NumExtraInhabitants =
1530+
DbgTy.getNumExtraInhabitants() ? *DbgTy.getNumExtraInhabitants() : 0;
1531+
15291532
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
15301533

15311534
TypeBase *BaseTy = DbgTy.getType();
@@ -1549,17 +1552,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15491552
Encoding = llvm::dwarf::DW_ATE_unsigned;
15501553
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy))
15511554
SizeInBits = getSizeOfBasicType(*CompletedDbgTy);
1552-
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants())
1553-
NumExtraInhabitants = *DbgTyNumExtraInhabitants;
15541555
break;
15551556
}
15561557

15571558
case TypeKind::BuiltinIntegerLiteral: {
15581559
Encoding = llvm::dwarf::DW_ATE_unsigned; // ?
15591560
if (auto CompletedDbgTy = CompletedDebugTypeInfo::get(DbgTy))
15601561
SizeInBits = getSizeOfBasicType(*CompletedDbgTy);
1561-
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants())
1562-
NumExtraInhabitants = *DbgTyNumExtraInhabitants;
15631562
break;
15641563
}
15651564

@@ -1568,48 +1567,30 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15681567
// Assuming that the bitwidth and FloatTy->getFPKind() are identical.
15691568
SizeInBits = FloatTy->getBitWidth();
15701569
Encoding = llvm::dwarf::DW_ATE_float;
1571-
if (auto DbgTyNumExtraInhabitants = DbgTy.getNumExtraInhabitants())
1572-
NumExtraInhabitants = *DbgTyNumExtraInhabitants;
15731570
break;
15741571
}
15751572

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-
}
1573+
case TypeKind::BuiltinNativeObject:
1574+
case TypeKind::BuiltinBridgeObject:
1575+
case TypeKind::BuiltinRawPointer:
1576+
case TypeKind::BuiltinRawUnsafeContinuation:
1577+
case TypeKind::BuiltinJob: {
1578+
unsigned PtrSize =
1579+
CI.getTargetInfo().getPointerWidth(clang::LangAS::Default);
1580+
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
1581+
Flags |= llvm::DINode::FlagArtificial;
1582+
llvm::DICompositeType *PTy = DBuilder.createStructType(
1583+
Scope, MangledName, File, 0, PtrSize, 0, Flags, nullptr, nullptr,
1584+
llvm::dwarf::DW_LANG_Swift, nullptr, {}, NumExtraInhabitants);
1585+
return PTy;
15981586

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-
}
1587+
}
1588+
llvm::DIDerivedType *PTy = DBuilder.createPointerType(
1589+
nullptr, PtrSize, 0,
1590+
/* DWARFAddressSpace */ llvm::None, MangledName);
16051591

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);
1592+
return DBuilder.createObjectPointerType(PTy);
16111593
}
1612-
16131594
case TypeKind::BuiltinExecutor: {
16141595
return createDoublePointerSizedStruct(
16151596
Scope, "Builtin.Executor", nullptr, MainFile, 0,
@@ -2033,6 +2014,20 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
20332014
}
20342015
#endif
20352016

2017+
/// Emits the special builtin types into the debug info. These types are the
2018+
/// ones that are unconditionally emitted into the stdlib's metadata and are
2019+
/// needed to correctly calculate the layout of more complex types built on
2020+
/// top of them.
2021+
void createSpecialStlibBuiltinTypes() {
2022+
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::ASTTypes)
2023+
return;
2024+
for (auto BuiltinType: IGM.getSpecialBuiltinTypes()) {
2025+
auto DbgTy = DebugTypeInfo::getFromTypeInfo(
2026+
BuiltinType, IGM.getTypeInfoForUnlowered(BuiltinType), IGM, false);
2027+
DBuilder.retainType(getOrCreateType(DbgTy));
2028+
}
2029+
}
2030+
20362031
llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy) {
20372032
// Is this an empty type?
20382033
if (DbgTy.isNull())
@@ -2079,6 +2074,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
20792074
TypeDecl = ND;
20802075
Context = ND->getParent();
20812076
ClangDecl = ND->getClangDecl();
2077+
} else if (auto BNO = dyn_cast<BuiltinType>(DbgTy.getType())) {
2078+
Context = BNO->getASTContext().TheBuiltinModule;
20822079
}
20832080
if (ClangDecl) {
20842081
clang::ASTReader &Reader = *CI.getClangInstance().getASTReader();
@@ -2255,6 +2252,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
22552252
}
22562253
OS << '"';
22572254
}
2255+
createSpecialStlibBuiltinTypes();
22582256
}
22592257

22602258
void IRGenDebugInfoImpl::finalize() {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-frontend %s -Onone -emit-ir -gdwarf-types -o - | %FileCheck %s
2+
3+
// File is empty as this test check for the builtin stdlib types that should
4+
// always be emitted.
5+
6+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sBoD",
7+
// CHECK-SAME: size: 64, num_extra_inhabitants: 2147483647, flags: DIFlagArtificial,
8+
// CHECK-SAME: runtimeLang: DW_LANG_Swift)
9+
10+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$syXlD",
11+
// CHECK-SAME: size: 64,
12+
13+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sBbD",
14+
// CHECK-SAME: size: 64, num_extra_inhabitants: 2147483647, flags: DIFlagArtificial,
15+
// CHECK-SAME: runtimeLang: DW_LANG_Swift)
16+
17+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sBpD",
18+
// CHECK-SAME: size: 64, num_extra_inhabitants: 1, flags: DIFlagArtificial,
19+
// CHECK-SAME: runtimeLang: DW_LANG_Swift)
20+
21+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$syyXfD",
22+
// CHECK-SAME: size: 64,
23+
// CHECK-SAME: runtimeLang: DW_LANG_Swift
24+
25+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$sypXpD", size: 64,
26+
// CHECK-SAME: flags: DIFlagArtificial, runtimeLang: DW_LANG_Swift, identifier: "$sypXpD")
27+
28+

0 commit comments

Comments
 (0)