Skip to content

Commit 781678b

Browse files
Merge pull request #65615 from adrian-prantl/107491524-5.9
Emit debug info for count arguments of variadic generic types.
2 parents 50b5d61 + a0d35f6 commit 781678b

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,20 @@ class IRGenSILFunction :
10891089
copy.push_back(Alloca.getAddress());
10901090
}
10911091

1092+
void emitPackCountDebugVariable(llvm::Value *Shape) {
1093+
if (!PackShapeExpressions.insert(Shape).second)
1094+
return;
1095+
llvm::SmallString<8> Buf;
1096+
unsigned Position = PackShapeExpressions.size() - 1;
1097+
llvm::raw_svector_ostream(Buf) << "$pack_count_" << Position;
1098+
auto Name = IGM.Context.getIdentifier(Buf.str());
1099+
SILDebugVariable Var(Name.str(), true, 0);
1100+
Shape = emitShadowCopyIfNeeded(Shape, getDebugScope(), Var, false,
1101+
false /*was move*/);
1102+
if (IGM.DebugInfo)
1103+
IGM.DebugInfo->emitPackCountParameter(*this, Shape, Var);
1104+
}
1105+
10921106
/// Force all archetypes referenced by the type to be bound by this point.
10931107
/// TODO: just make sure that we have a path to them that the debug info
10941108
/// can follow.
@@ -1102,17 +1116,10 @@ class IRGenSILFunction :
11021116
emitTypeMetadataRef(packArchetype);
11031117
else if (auto packtype = dyn_cast<SILPackType>(t)) {
11041118
llvm::Value *Shape = emitPackShapeExpression(t);
1105-
if (PackShapeExpressions.insert(Shape).second) {
1106-
llvm::SmallString<8> Buf;
1107-
unsigned Position = PackShapeExpressions.size() - 1;
1108-
llvm::raw_svector_ostream(Buf) << "$pack_count_" << Position;
1109-
auto Name = IGM.Context.getIdentifier(Buf.str());
1110-
SILDebugVariable Var(Name.str(), true, 0);
1111-
Shape = emitShadowCopyIfNeeded(Shape, getDebugScope(), Var, false,
1112-
false /*was move*/);
1113-
if (IGM.DebugInfo)
1114-
IGM.DebugInfo->emitPackCountParameter(*this, Shape, Var);
1115-
}
1119+
emitPackCountDebugVariable(Shape);
1120+
} else if (auto packtype = dyn_cast<PackType>(t)) {
1121+
llvm::Value *Shape = emitPackShapeExpression(t);
1122+
emitPackCountDebugVariable(Shape);
11161123
}
11171124
});
11181125
}

test/DebugInfo/variadic-generics-count.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend -emit-ir %s -g -o - \
2-
// RUN: -parse-as-library -module-name a | %FileCheck %s
2+
// RUN: -parse-as-library -module-name a -enable-experimental-feature VariadicGenerics | %FileCheck %s
33

44
public func f1<each T>(ts: repeat each T) {
55
// CHECK: define {{.*}} @"$s1a2f12tsyxxQp_tRvzlF"(%swift.opaque** {{.*}}, i{{32|64}} [[COUNT1_1:.*]], %swift.type** {{.*}})
@@ -31,10 +31,24 @@ public func f4<each U, each V>(us: repeat (each U, each V)) {
3131
// CHECK-LABEL: ret void
3232
}
3333

34+
public struct S<each T> {
35+
let vals: (repeat each T)
36+
37+
public func f5() {
38+
// CHECK: define {{.*}} @"$s1a1SV2f5yyF"(%swift.type* {{.*}}, %T1a1SV* {{.*}} %0)
39+
}
40+
}
41+
42+
public func f6<each T>(s: S<repeat each T>) {
43+
// CHECK: define {{.*}} @"$s1a2f61syAA1SVyxxQp_QPG_tRvzlF"(%T1a1SV* {{.*}}, i{{32|64}} [[COUNT6_1:.*]], %swift.type** {{.*}})
44+
// CHECK-DAG: store i{{32|64}} [[COUNT6_1]], i{{32|64}}* %[[COUNT6_1_A:.*]], align
45+
// CHECK-DAG: call void @llvm.dbg.declare({{.*}}[[COUNT6_1_A]], metadata ![[COUNT6_1_VAR:[0-9]+]], metadata !DIExpression())
46+
}
47+
3448
// CHECK-LABEL: !DICompileUnit
3549
// CHECK-DAG: [[COUNT1_1_VAR]] = !DILocalVariable(name: "$pack_count_0",{{.*}} flags: DIFlagArtificial)
3650
// CHECK-DAG: [[COUNT2_1_VAR]] = !DILocalVariable(name: "$pack_count_0",{{.*}} flags: DIFlagArtificial)
3751
// CHECK-DAG: [[COUNT2_2_VAR]] = !DILocalVariable(name: "$pack_count_1",{{.*}} flags: DIFlagArtificial)
3852
// CHECK-DAG: [[COUNT3_1_VAR]] = !DILocalVariable(name: "$pack_count_0",{{.*}} flags: DIFlagArtificial)
3953
// CHECK-DAG: [[COUNT4_1_VAR]] = !DILocalVariable(name: "$pack_count_0",{{.*}} flags: DIFlagArtificial)
40-
54+
// CHECK-DAG: [[COUNT6_1_VAR]] = !DILocalVariable(name: "$pack_count_0",{{.*}} flags: DIFlagArtificial)

0 commit comments

Comments
 (0)