Skip to content

Commit 58bbadd

Browse files
[DebugInfo] Dont generate line information at the split point of async funclets
Unless there is some meaningful code on the same line as an await call (e.g. other parts of an expression), there should be no additional line entries associated with that line on the continuation funclet. This patch changes codegen to avoid emitting debug location for the "prologue" code at the start of a funclet, instead of simply copying the debug location of the split point.
1 parent fb160f6 commit 58bbadd

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/IRGen/GenCall.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "GenPoly.h"
5151
#include "GenProto.h"
5252
#include "GenType.h"
53+
#include "IRGenDebugInfo.h"
5354
#include "IRGenFunction.h"
5455
#include "IRGenModule.h"
5556
#include "LoadableTypeInfo.h"
@@ -219,6 +220,9 @@ llvm::CallInst *IRGenFunction::emitSuspendAsyncCall(
219220
auto *id = Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async,
220221
{resultTy}, args);
221222
if (restoreCurrentContext) {
223+
// This is setup code after the split point. Don't associate any line
224+
// numbers to it.
225+
irgen::PrologueLocation LocRAII(IGM.DebugInfo.get(), Builder);
222226
llvm::Value *calleeContext =
223227
Builder.CreateExtractValue(id, asyncContextIndex);
224228
calleeContext =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-frontend %s -emit-irgen -g -o - \
2+
// RUN: -module-name M -disable-availability-checking \
3+
// RUN: -parse-as-library | %FileCheck %s --check-prefix=CHECK
4+
5+
// REQUIRES: concurrency
6+
7+
8+
func ASYNC___1___() async -> Int {
9+
return 42
10+
}
11+
12+
// Check that the first debug location after a split point is for the line
13+
// _after_ the await.
14+
15+
// CHECK: define {{.*}} @"$s1M12ASYNC___2___SiyYaF"
16+
func ASYNC___2___() async -> Int {
17+
var x = 10
18+
await ASYNC___1___()
19+
// CHECK: call {{.*}} @llvm.coro.suspend.async{{.*}} ptr @__swift_async_resume_get_context{{.*}} !dbg
20+
// CHECK: !dbg ![[FirstDbg:[0-9]+]]
21+
// CHECK: ![[FirstDbg]] = !DILocation(line: [[@LINE+1]]
22+
x = 12
23+
return x
24+
}

test/DebugInfo/async-let.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public actor Alice {
88
let bob = Bob()
99

1010
// CHECK: define {{.*}}$s1M5AliceC4callyyYaFTY0_{{.*}} !dbg ![[SCOPE0:[0-9]+]]
11-
// CHECK: load ptr, ptr {{.*}} !dbg ![[HOP0:[0-9]+]]
11+
// CHECK: asyncLet_begin{{.*}} !dbg ![[HOP0:[0-9]+]]
1212

1313
// CHECK: define {{.*}}$s1M5AliceC4callyyYaFTY1_{{.*}} !dbg ![[SCOPE1:[0-9]+]]
1414
// CHECK: load ptr, ptr {{.*}} !dbg ![[HOP1:[0-9]+]]
@@ -20,7 +20,7 @@ public actor Alice {
2020
// CHECK: load ptr, ptr {{.*}} !dbg ![[LET_HOP1:[0-9]+]]
2121
public func call() async {
2222
// CHECK: ![[SCOPE0]] = distinct !DISubprogram({{.*}}line: [[@LINE-1]]
23-
// CHECK: ![[HOP0]] = !DILocation(line: [[@LINE-2]], column: 15
23+
// CHECK: ![[HOP0]] = !DILocation(line: [[@LINE+1]], column: 11
2424
async let a = bob.call(x: 1)
2525
// CHECK: ![[SCOPE1]] = distinct !DISubprogram({{.*}}line: [[@LINE-4]]
2626
// CHECK: ![[HOP1]] = !DILocation(line: [[@LINE+5]], column: 17

0 commit comments

Comments
 (0)