Skip to content

Commit 2880517

Browse files
[DebugInfo] Don't emit debug info for async suspend/dispatch functions
Those functions are effectively outlined functions with an alwaysinline attribute. By removing their debug info and relying on the inliner to propagate the call site location to the inlined instructions, we restore the "original" locations as if the function had never been outlined. This is technically relying on an implementation detail of the inliner, but it seems to be the simplest way of addressing this issue.
1 parent fa1860c commit 2880517

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,9 +2899,6 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
28992899
dispatch->setDoesNotThrow();
29002900
dispatch->addFnAttr(llvm::Attribute::AlwaysInline);
29012901
IRGenFunction dispatchIGF(IGM, dispatch);
2902-
// Don't emit debug info if we are generating a function for the prologue.
2903-
if (IGM.DebugInfo && Builder.getCurrentDebugLocation())
2904-
IGM.DebugInfo->emitOutlinedFunction(dispatchIGF, dispatch, CurFn->getName());
29052902
auto &Builder = dispatchIGF.Builder;
29062903
auto it = dispatchIGF.CurFn->arg_begin(), end = dispatchIGF.CurFn->arg_end();
29072904
llvm::Value *fnPtrArg = &*(it++);
@@ -2987,9 +2984,6 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() {
29872984
suspendFn->setDoesNotThrow();
29882985
suspendFn->addFnAttr(llvm::Attribute::AlwaysInline);
29892986
IRGenFunction suspendIGF(IGM, suspendFn);
2990-
if (IGM.DebugInfo)
2991-
IGM.DebugInfo->emitOutlinedFunction(suspendIGF, suspendFn,
2992-
CurFn->getName());
29932987
auto &Builder = suspendIGF.Builder;
29942988

29952989
llvm::Value *resumeFunction = suspendFn->getArg(0);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
// Check that all the helper "outlined" functions do not have debug information.
8+
9+
func ASYNC___1___() async -> Int {
10+
return 42
11+
}
12+
13+
func ASYNC___2___() async -> Int {
14+
print("hello")
15+
var x = await ASYNC___1___()
16+
x += await ASYNC___1___()
17+
return x
18+
}
19+
20+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___1___SiyYaF.0"
21+
// CHECK-NOT: !dbg
22+
// CHECK: ret void
23+
// CHECK-NEXT: }
24+
25+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.1"
26+
// CHECK-NOT: !dbg
27+
// CHECK: ret void
28+
// CHECK-NEXT: }
29+
30+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0"
31+
// CHECK-NOT: !dbg
32+
// CHECK: ret void
33+
// CHECK-NEXT: }
34+
35+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0.1"
36+
// CHECK-NOT: !dbg
37+
// CHECK: ret void
38+
// CHECK-NEXT: }
39+
40+
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0.2"
41+
// CHECK-NOT: !dbg
42+
// CHECK: ret void
43+
// CHECK-NEXT: }

test/IRGen/async/get_async_continuation.sil

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ bb0:
6969
// CHECK: {{musttail call swifttailcc|tail call swiftcc}} void @swift_continuation_await(ptr %0)
7070
// CHECK-NEXT: ret void
7171

72-
// CHECK: define {{.*}} void @async_continuation.0(ptr %0, ptr %1){{.*}}!dbg ![[DBG:[0-9]+]]
72+
// CHECK: define {{.*}} void @async_continuation.0(ptr %0, ptr %1)
7373
// CHECK-NOT: define
7474
// CHECK: tail call swift{{(tail)?}}cc void %{{.*}}(ptr swiftasync %1)
7575
// CHECK-NEXT: ret void
76-
// CHECK: ![[DBG]] = distinct !DISubprogram(linkageName: "async_continuation"
7776

7877
sil @async_continuation : $@async () -> () {
7978
entry:

0 commit comments

Comments
 (0)