Skip to content

Commit 33ac7eb

Browse files
committed
Only emit DWARF types for tuple types under -gdwarf-types.
1 parent 5504a18 commit 33ac7eb

File tree

5 files changed

+65
-31
lines changed

5 files changed

+65
-31
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,35 @@ IRGenDebugInfo::createFunctionPointer(DebugTypeInfo DbgTy, llvm::DIScope *Scope,
13021302
return DITy;
13031303
}
13041304

1305+
llvm::DIType *IRGenDebugInfo::createTuple(DebugTypeInfo DbgTy,
1306+
llvm::DIScope *Scope,
1307+
unsigned SizeInBits,
1308+
unsigned AlignInBits, unsigned Flags,
1309+
StringRef MangledName) {
1310+
TypeBase *BaseTy = DbgTy.getType();
1311+
auto *TupleTy = BaseTy->castTo<TupleType>();
1312+
auto FwdDecl = llvm::TempDINode(DBuilder.createReplaceableCompositeType(
1313+
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, MainFile, 0,
1314+
llvm::dwarf::DW_LANG_Swift, SizeInBits, AlignInBits, Flags, MangledName));
1315+
1316+
DITypeCache[DbgTy.getType()] = llvm::TrackingMDNodeRef(FwdDecl.get());
1317+
1318+
unsigned RealSize;
1319+
auto Elements = getTupleElements(TupleTy, Scope, MainFile, Flags,
1320+
DbgTy.getDeclContext(), RealSize);
1321+
// FIXME: Handle %swift.opaque members and make this into an assertion.
1322+
if (!RealSize)
1323+
RealSize = SizeInBits;
1324+
1325+
auto DITy = DBuilder.createStructType(
1326+
Scope, MangledName, MainFile, 0, RealSize, AlignInBits, Flags,
1327+
nullptr, // DerivedFrom
1328+
Elements, llvm::dwarf::DW_LANG_Swift, nullptr, MangledName);
1329+
1330+
DBuilder.replaceTemporary(std::move(FwdDecl), DITy);
1331+
return DITy;
1332+
}
1333+
13051334
llvm::DIType *
13061335
IRGenDebugInfo::createOpaqueStruct(llvm::DIScope *Scope, StringRef Name,
13071336
llvm::DIFile *File, unsigned Line,
@@ -1514,29 +1543,13 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy,
15141543
}
15151544

15161545
case TypeKind::Tuple: {
1517-
auto *TupleTy = BaseTy->castTo<TupleType>();
15181546
// Tuples are also represented as structs.
1519-
auto FwdDecl = llvm::TempDINode(
1520-
DBuilder.createReplaceableCompositeType(
1521-
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, File, 0,
1522-
llvm::dwarf::DW_LANG_Swift, SizeInBits, AlignInBits, Flags,
1523-
MangledName));
1524-
1525-
DITypeCache[DbgTy.getType()] = llvm::TrackingMDNodeRef(FwdDecl.get());
1526-
1527-
unsigned RealSize;
1528-
auto Elements = getTupleElements(TupleTy, Scope, MainFile, Flags,
1529-
DbgTy.getDeclContext(), RealSize);
1530-
// FIXME: Handle %swift.opaque members and make this into an assertion.
1531-
if (!RealSize)
1532-
RealSize = SizeInBits;
1533-
auto DITy = DBuilder.createStructType(
1534-
Scope, MangledName, File, 0, RealSize, AlignInBits, Flags,
1535-
nullptr, // DerivedFrom
1536-
Elements, llvm::dwarf::DW_LANG_Swift, nullptr, MangledName);
1537-
1538-
DBuilder.replaceTemporary(std::move(FwdDecl), DITy);
1539-
return DITy;
1547+
if (Opts.DebugInfoKind > IRGenDebugInfoKind::ASTTypes)
1548+
return createTuple(DbgTy, Scope, SizeInBits, AlignInBits, Flags,
1549+
MangledName);
1550+
else
1551+
return createOpaqueStruct(Scope, MangledName, MainFile, 0, SizeInBits,
1552+
AlignInBits, Flags, MangledName);
15401553
}
15411554

15421555
case TypeKind::InOut: {

lib/IRGen/IRGenDebugInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ class IRGenDebugInfo {
324324
unsigned SizeInBits, unsigned AlignInBits,
325325
unsigned Flags, StringRef MangledName);
326326

327+
/// Create DWARF debug info for a tuple type.
328+
llvm::DIType *createTuple(DebugTypeInfo DbgTy, llvm::DIScope *Scope,
329+
unsigned SizeInBits, unsigned AlignInBits,
330+
unsigned Flags, StringRef MangledName);
331+
327332
/// Create an opaque struct with a mangled name.
328333
llvm::DIType *createOpaqueStruct(llvm::DIScope *Scope, StringRef Name,
329334
llvm::DIFile *File, unsigned Line,

test/DebugInfo/enum.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ public enum Tuple<P> {
7878

7979
func bar<T>(_ x : Tuple<T>) -> Tuple<T> { return x }
8080

81-
// CHECK: ![[LIST:.*]] = !DICompositeType({{.*}}identifier: "_TtGO4enum4ListQq_S0__"
81+
// CHECK: !DILocalVariable(name: "self", arg: 1, {{.*}} line: [[@LINE+5]], type: ![[LIST:.*]], flags: DIFlagArtificial)
82+
// CHECK: ![[LIST]] = !DICompositeType({{.*}}identifier: "_TtGO4enum4ListQq_S0__"
8283
public enum List<T> {
8384
indirect case Tail(List, T)
8485
case End
85-
86-
// CHECK: !DILocalVariable(name: "self", arg: 1, {{.*}} line: [[@LINE+1]], type: ![[LIST]], flags: DIFlagArtificial)
8786
func fooMyList() {}
8887
}

test/DebugInfo/tuple.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -o - | FileCheck %s
2+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -gdwarf-types -o - \
3+
// RUN: | FileCheck %s --check-prefix=DWARF
4+
25
// Don't emit a line number for tuple types. They are unnamed
36
// and have no declaration, so the line number is nonsensical.
47
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "_TtTSiSf_"
5-
let tuple : (Int, Float) = (1, 2.89)
8+
// CHECK-NOT: line:
9+
// CHECK-NEXT: =
10+
let tuple1 : (Int, Float) = (1, 2.89)
11+
12+
// Tuple types.
13+
var tuple2: (Double, Bool) = (1, true)
14+
// DWARF: !DIGlobalVariable(name: "tuple2",{{.*}} type: ![[TUPTY:[^,)]+]]
15+
// DWARF: ![[TUPTY]] = !DICompositeType(tag: DW_TAG_structure_type,
16+
// DWARF-SAME: elements: ![[ELEMS:[0-9]+]]
17+
// DWARF: ![[ELEMS]] = !{![[MD:[0-9]+]], ![[MB:[0-9]+]]}
18+
// DWARF: ![[MD]] = !DIDerivedType(tag: DW_TAG_member
19+
// DWARF-SAME: baseType: ![[DBL:[0-9]+]]
20+
// DWARF: ![[DBL]] = !DICompositeType({{.*}}, name: "Double"
21+
// DWARF: ![[MB]] = !DIDerivedType(tag: DW_TAG_member,
22+
// DWARF-SAME: baseType: ![[B:[0-9]+]]
23+
// DWARF: ![[B]] = !DICompositeType({{.*}}, name: "Bool"
24+
func myprint(_ p: (i: Int, b: Bool)) {
25+
print("\(p.i) -> \(p.b)")
26+
}

test/DebugInfo/variables.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ var g = foo(1.0);
6060
// Tuple types.
6161
var tuple: (Int, Bool) = (1, true)
6262
// CHECK-DAG: !DIGlobalVariable(name: "tuple", linkageName: "_Tv{{9variables|4main}}5tupleTSiSb_",{{.*}} type: ![[TUPTY:[^,)]+]]
63-
// CHECK-DAG: ![[TUPTY]] = !DICompositeType(tag: DW_TAG_structure_type,{{.*}} elements: ![[ELEMS:[0-9]+]]
64-
// CHECK-DAG: ![[ELEMS]] = !{![[MI64:[0-9]+]], ![[MB:[0-9]+]]}
65-
// CHECK-DAG: ![[INTTY:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Int"
66-
// CHECK-DAG: ![[MI64]] = !DIDerivedType(tag: DW_TAG_member,{{.*}} baseType: ![[INTTY]]
67-
// CHECK-DAG: ![[MB]] = !DIDerivedType(tag: DW_TAG_member,{{.*}} baseType: ![[B]]
63+
// CHECK-DAG: ![[TUPTY]] = !DICompositeType({{.*}}identifier: "_TtTSiSb_"
6864
func myprint(_ p: (i: Int, b: Bool)) {
6965
print("\(p.i) -> \(p.b)")
7066
}

0 commit comments

Comments
 (0)