From 60ce8babf77e65836d844741fbe50f297ad00781 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 13 May 2021 09:04:29 -0700 Subject: [PATCH] [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 `` with a non-zero line number. The convention for `` 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 --- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 7 +++++-- llvm/test/Transforms/Coroutines/coro-async.ll | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index f75bca0..545b74e 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -862,14 +862,17 @@ void CoroCloner::create() { auto &Context = NewF->getContext(); // For async functions / continuations, adjust the scope line of the - // clone to the line number of the suspend point. The scope line is + // clone to the line number of the suspend point. However, only + // adjust the scope line when the files are the same. This ensures + // line number and file name belong together. The scope line is // associated with all pre-prologue instructions. This avoids a jump // in the linetable from the function declaration to the suspend point. if (DISubprogram *SP = NewF->getSubprogram()) { assert(SP != OrigF.getSubprogram() && SP->isDistinct()); if (ActiveSuspend) if (auto DL = ActiveSuspend->getDebugLoc()) - SP->setScopeLine(DL->getLine()); + if (SP->getFile() == DL->getFile()) + SP->setScopeLine(DL->getLine()); // Update the linkage name to reflect the modified symbol name. It // is necessary to update the linkage name in Swift, since the // mangling changes for resume functions. It might also be the diff --git a/llvm/test/Transforms/Coroutines/coro-async.ll b/llvm/test/Transforms/Coroutines/coro-async.ll index a779e15..b319b25 100644 --- a/llvm/test/Transforms/Coroutines/coro-async.ll +++ b/llvm/test/Transforms/Coroutines/coro-async.ll @@ -187,7 +187,7 @@ define void @my_async_function_pa(i8* %ctxt, %async.task* %task, %async.actor* % i32 128 ; Initial async context size without space for frame }> -define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt) "frame-pointer"="all" { +define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt) "frame-pointer"="all" !dbg !6 { entry: %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: i8* %resume.func_ptr, i8* %resume_proj_fun, void (i8*, i8*, %async.task*, %async.actor*)* @my_async_function.my_other_async_function_fp.apply, - i8* %callee, i8* %callee_context, %async.task* %task, %async.actor *%actor) + i8* %callee, i8* %callee_context, %async.task* %task, %async.actor *%actor), !dbg !9 %continuation_task_arg = extractvalue {i8*, i8*, i8*} %res, 0 %task.2 = bitcast i8* %continuation_task_arg to %async.task* @@ -241,6 +241,7 @@ entry: ; CHECK-LABEL: define swiftcc void @my_async_function2(%async.task* %task, %async.actor* %actor, i8* %async.ctxt) ; CHECK-SAME: #[[FRAMEPOINTER:[0-9]+]] +; CHECK-SAME: !dbg ![[SP3:[0-9]+]] ; CHECK: store i8* %async.ctxt, ; CHECK: store %async.actor* %actor, ; CHECK: store %async.task* %task, @@ -253,6 +254,7 @@ entry: ; CHECK-LABEL: define internal swiftcc void @my_async_function2.resume.0(i8* %0, i8* nocapture readnone %1, i8* nocapture readonly %2) ; CHECK-SAME: #[[FRAMEPOINTER]] +; CHECK-SAME: !dbg ![[SP4:[0-9]+]] ; CHECK: [[CALLEE_CTXT_ADDR:%.*]] = bitcast i8* %2 to i8** ; CHECK: [[CALLEE_CTXT:%.*]] = load i8*, i8** [[CALLEE_CTXT_ADDR]] ; CHECK: [[CALLEE_CTXT_SPILL_ADDR:%.*]] = getelementptr inbounds i8, i8* [[CALLEE_CTXT]], i64 152 @@ -554,3 +556,16 @@ declare void @llvm.coro.async.size.replace(i8*, i8*) !4 = !DISubroutineType(types: !{}) !5 = !DILocation(line: 2, column: 0, scope: !1) +; CHECK: ![[SP3]] = distinct !DISubprogram(name: "my_async_function2", +; CHECK-SAME: linkageName: "my_async_function2", +; CHECK-SAME: scopeLine: 1 +!6 = distinct !DISubprogram(name: "my_async_function2", + linkageName: "my_async_function2", + scope: !2, file: !3, line: 1, type: !4, + scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2) +; CHECK: ![[SP4]] = distinct !DISubprogram(name: "my_async_function2", +; CHECK-SAME: linkageName: "my_async_function2.resume.0", +; CHECK-SAME: scopeLine: 1 +!7 = !DILexicalBlockFile(scope: !6, file: !8, discriminator: 0) +!8 = !DIFile(filename: "/tmp/fake.cpp", directory: "/") +!9 = !DILocation(line: 2, column: 0, scope: !7) -- 2.7.4