Skip to content

Commit a516671

Browse files
committed
[coro] Preserve scope line for compiler generated functions
Coro-split functions with an active suspend point have their scope line set to the line of the suspend point. However for compiler generated functions, this results in debug info with unconventional results: a file named `<compiler-generated>` with a non-zero line number. The convention for `<compiler-generated>` is that the line number is zero. This change propagates the scope line only for non-compiler generated functions. Differential Revision: https://reviews.llvm.org/D102412 (cherry picked from commit 60ce8ba)
1 parent a814876 commit a516671

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,14 +867,17 @@ void CoroCloner::create() {
867867
CloneFunctionInto(NewF, &OrigF, VMap, /*ModuleLevelChanges=*/true, Returns);
868868

869869
// For async functions / continuations, adjust the scope line of the
870-
// clone to the line number of the suspend point. The scope line is
870+
// clone to the line number of the suspend point. However, only
871+
// adjust the scope line when the files are the same. This ensures
872+
// line number and file name belong together. The scope line is
871873
// associated with all pre-prologue instructions. This avoids a jump
872874
// in the linetable from the function declaration to the suspend point.
873875
if (DISubprogram *SP = NewF->getSubprogram()) {
874876
assert(SP != OrigF.getSubprogram() && SP->isDistinct());
875877
if (ActiveSuspend)
876878
if (auto DL = ActiveSuspend->getDebugLoc())
877-
SP->setScopeLine(DL->getLine());
879+
if (SP->getFile() == DL->getFile())
880+
SP->setScopeLine(DL->getLine());
878881
// Update the linkage name to reflect the modified symbol name. It
879882
// is necessary to update the linkage name in Swift, since the
880883
// mangling changes for resume functions. It might also be the

llvm/test/Transforms/Coroutines/coro-async.ll

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ define void @my_async_function_pa(i8* %ctxt, %async.task* %task, %async.actor* %
187187
i32 128 ; Initial async context size without space for frame
188188
}>
189189

190-
define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt) {
190+
define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt) !dbg !6 {
191191
entry:
192192

193193
%id = call token @llvm.coro.id.async(i32 128, i32 16, i32 2, i8* bitcast (<{i32, i32}>* @my_async_function2_fp to i8*))
@@ -210,7 +210,7 @@ entry:
210210
i8* %resume.func_ptr,
211211
i8* %resume_proj_fun,
212212
void (i8*, i8*, %async.task*, %async.actor*)* @my_async_function.my_other_async_function_fp.apply,
213-
i8* %callee, i8* %callee_context, %async.task* %task, %async.actor *%actor)
213+
i8* %callee, i8* %callee_context, %async.task* %task, %async.actor *%actor), !dbg !9
214214

215215
%continuation_task_arg = extractvalue {i8*, i8*, i8*} %res, 0
216216
%task.2 = bitcast i8* %continuation_task_arg to %async.task*
@@ -239,7 +239,8 @@ entry:
239239
unreachable
240240
}
241241

242-
; CHECK-LABEL: define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt) {
242+
; CHECK-LABEL: define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt)
243+
; CHECK-SAME: !dbg ![[SP3:[0-9]+]]
243244
; CHECK: store i8* %async.ctxt,
244245
; CHECK: store %async.actor* %actor,
245246
; CHECK: store %async.task* %task,
@@ -250,7 +251,8 @@ entry:
250251
; CHECK: tail call swiftcc void @asyncSuspend(i8* [[CALLEE_CTXT]], %async.task* %task, %async.actor* %actor)
251252
; CHECK: ret void
252253

253-
; CHECK-LABEL: define internal swiftcc void @my_async_function2.resume.0(i8* %0, i8* nocapture readnone %1, i8* nocapture readonly %2) {
254+
; CHECK-LABEL: define internal swiftcc void @my_async_function2.resume.0(i8* %0, i8* nocapture readnone %1, i8* nocapture readonly %2)
255+
; CHECK-SAME: !dbg ![[SP4:[0-9]+]]
254256
; CHECK: [[CALLEE_CTXT_ADDR:%.*]] = bitcast i8* %2 to i8**
255257
; CHECK: [[CALLEE_CTXT:%.*]] = load i8*, i8** [[CALLEE_CTXT_ADDR]]
256258
; CHECK: [[CALLEE_CTXT_SPILL_ADDR:%.*]] = getelementptr inbounds i8, i8* [[CALLEE_CTXT]], i64 152
@@ -260,7 +262,7 @@ entry:
260262
; CHECK: tail call swiftcc void @asyncSuspend(i8* [[CALLEE_CTXT_RELOAD]]
261263
; CHECK: ret void
262264

263-
; CHECK-LABEL: define internal swiftcc void @my_async_function2.resume.1(i8* nocapture readonly %0, i8* %1, i8* nocapture readnone %2) {
265+
; CHECK-LABEL: define internal swiftcc void @my_async_function2.resume.1(i8* nocapture readonly %0, i8* %1, i8* nocapture readnone %2)
264266
; CHECK: bitcast i8* %0 to i8**
265267
; CHECK: [[ACTOR_ARG:%.*]] = bitcast i8* %1
266268
; CHECK: tail call swiftcc void @asyncReturn({{.*}}[[ACTOR_ARG]])
@@ -550,3 +552,17 @@ declare void @llvm.coro.async.size.replace(i8*, i8*)
550552
!3 = !DIFile(filename: "/tmp/1.swift", directory: "/")
551553
!4 = !DISubroutineType(types: !{})
552554
!5 = !DILocation(line: 2, column: 0, scope: !1)
555+
556+
; CHECK: ![[SP3]] = distinct !DISubprogram(name: "my_async_function2",
557+
; CHECK-SAME: linkageName: "my_async_function2",
558+
; CHECK-SAME: scopeLine: 1
559+
!6 = distinct !DISubprogram(name: "my_async_function2",
560+
linkageName: "my_async_function2",
561+
scope: !2, file: !3, line: 1, type: !4,
562+
scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2)
563+
; CHECK: ![[SP4]] = distinct !DISubprogram(name: "my_async_function2",
564+
; CHECK-SAME: linkageName: "my_async_function2.resume.0",
565+
; CHECK-SAME: scopeLine: 1
566+
!7 = !DILexicalBlockFile(scope: !6, file: !8, discriminator: 0)
567+
!8 = !DIFile(filename: "/tmp/fake.cpp", directory: "/")
568+
!9 = !DILocation(line: 2, column: 0, scope: !7)

0 commit comments

Comments
 (0)