Skip to content

Commit 0db3f71

Browse files
Merge pull request #7485 from DianQK/stable/20230725
[Coroutine][DebugInfo] Update the linkage name of the declaration of coro-split functions in the debug info.
2 parents b50895e + 51ee87d commit 0db3f71

File tree

3 files changed

+138
-2
lines changed

3 files changed

+138
-2
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

+1
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,7 @@ class DISubprogram : public DILocalScope {
18781878
DISubprogram *getDeclaration() const {
18791879
return cast_or_null<DISubprogram>(getRawDeclaration());
18801880
}
1881+
void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
18811882
DINodeArray getRetainedNodes() const {
18821883
return cast_or_null<MDTuple>(getRawRetainedNodes());
18831884
}

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,22 @@ void CoroCloner::create() {
945945
// abstract specification, since the DWARF backend expects the
946946
// abstract specification to contain the linkage name and asserts
947947
// that they are identical.
948-
if (!SP->getDeclaration() && SP->getUnit() &&
949-
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift)
948+
if (SP->getUnit() &&
949+
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift) {
950950
SP->replaceLinkageName(MDString::get(Context, NewF->getName()));
951+
if (auto *Decl = SP->getDeclaration()) {
952+
auto *NewDecl = DISubprogram::get(
953+
Decl->getContext(), Decl->getScope(), Decl->getName(),
954+
NewF->getName(), Decl->getFile(), Decl->getLine(), Decl->getType(),
955+
Decl->getScopeLine(), Decl->getContainingType(),
956+
Decl->getVirtualIndex(), Decl->getThisAdjustment(),
957+
Decl->getFlags(), Decl->getSPFlags(), Decl->getUnit(),
958+
Decl->getTemplateParams(), nullptr, Decl->getRetainedNodes(),
959+
Decl->getThrownTypes(), Decl->getAnnotations(),
960+
Decl->getTargetFuncName());
961+
SP->replaceDeclaration(NewDecl);
962+
}
963+
}
951964
}
952965

953966
NewF->setLinkage(savedLinkage);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,simplifycfg)' -S | FileCheck %s
2+
3+
; We want to check that updating the declaration when updating the linkage name of a DISubporgram with a declaration.
4+
5+
; Original source code:
6+
; public enum Foo {
7+
; public func bar() async {
8+
; await f()
9+
; }
10+
; }
11+
; public func f() async {}
12+
13+
14+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
15+
target triple = "x86_64-apple-macosx12.0.0"
16+
17+
%swift.async_func_pointer = type <{ i32, i32 }>
18+
19+
@"$s3foo3FooO3baryyYaFTu" = global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @"$s3foo3FooO3baryyYaF" to i64), i64 ptrtoint (ptr @"$s3foo3FooO3baryyYaFTu" to i64)) to i32), i32 16 }>, align 8
20+
@"$s3foo1fyyYaFTu" = global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @"$s3foo1fyyYaF" to i64), i64 ptrtoint (ptr @"$s3foo1fyyYaFTu" to i64)) to i32), i32 16 }>, align 8
21+
22+
define swifttailcc void @"$s3foo3FooO3baryyYaF"(ptr swiftasync %0) !dbg !5 {
23+
entry:
24+
%1 = alloca ptr, align 8
25+
%2 = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr @"$s3foo3FooO3baryyYaFTu")
26+
%3 = call ptr @llvm.coro.begin(token %2, ptr null)
27+
store ptr %0, ptr %1, align 8
28+
%4 = load i32, ptr getelementptr inbounds (%swift.async_func_pointer, ptr @"$s3foo1fyyYaFTu", i32 0, i32 1), align 8, !dbg !10
29+
%5 = zext i32 %4 to i64, !dbg !10
30+
%6 = call swiftcc ptr @swift_task_alloc(i64 %5), !dbg !10
31+
%7 = load ptr, ptr %1, align 8, !dbg !10
32+
%8 = getelementptr inbounds <{ ptr, ptr }>, ptr %6, i32 0, i32 0, !dbg !10
33+
store ptr %7, ptr %8, align 8, !dbg !10
34+
%9 = call ptr @llvm.coro.async.resume(), !dbg !10
35+
%10 = getelementptr inbounds <{ ptr, ptr }>, ptr %6, i32 0, i32 1, !dbg !10
36+
store ptr %9, ptr %10, align 8, !dbg !10
37+
%11 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0s(i32 0, ptr %9, ptr @__swift_async_resume_project_context, ptr @"$s3foo3FooO3baryyYaF.0", ptr @"$s3foo1fyyYaF", ptr %6), !dbg !10
38+
%12 = extractvalue { ptr } %11, 0, !dbg !10
39+
%13 = call ptr @__swift_async_resume_project_context(ptr %12), !dbg !10
40+
store ptr %13, ptr %1, align 8, !dbg !10
41+
call swiftcc void @swift_task_dealloc(ptr %6), !dbg !10
42+
%14 = load ptr, ptr %1, align 8, !dbg !11
43+
%15 = getelementptr inbounds <{ ptr, ptr }>, ptr %14, i32 0, i32 1, !dbg !11
44+
%16 = load ptr, ptr %15, align 8, !dbg !11
45+
%17 = load ptr, ptr %1, align 8, !dbg !11
46+
%18 = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %3, i1 false, ptr @"$s3foo3FooO3baryyYaF.0.1", ptr %16, ptr %17), !dbg !11
47+
unreachable, !dbg !11
48+
}
49+
50+
; Function Attrs: nounwind
51+
declare token @llvm.coro.id.async(i32, i32, i32, ptr) #0
52+
53+
; Function Attrs: nounwind
54+
declare ptr @llvm.coro.begin(token, ptr writeonly) #0
55+
56+
declare swifttailcc void @"$s3foo1fyyYaF"(ptr swiftasync)
57+
58+
declare swiftcc ptr @swift_task_alloc(i64)
59+
60+
; Function Attrs: nomerge nounwind
61+
declare ptr @llvm.coro.async.resume() #1
62+
63+
define linkonce_odr hidden ptr @__swift_async_resume_project_context(ptr %0) !dbg !12 {
64+
entry:
65+
%1 = load ptr, ptr %0, align 8, !dbg !14
66+
%2 = call ptr @llvm.swift.async.context.addr(), !dbg !14
67+
store ptr %1, ptr %2, align 8, !dbg !14
68+
ret ptr %1, !dbg !14
69+
}
70+
71+
; Function Attrs: nounwind
72+
declare ptr @llvm.swift.async.context.addr() #0
73+
74+
define internal swifttailcc void @"$s3foo3FooO3baryyYaF.0"(ptr %0, ptr %1) !dbg !15 {
75+
entry:
76+
musttail call swifttailcc void %0(ptr swiftasync %1), !dbg !16
77+
ret void, !dbg !16
78+
}
79+
80+
; Function Attrs: nomerge nounwind
81+
declare { ptr } @llvm.coro.suspend.async.sl_p0s(i32, ptr, ptr, ...) #1
82+
83+
declare swiftcc void @swift_task_dealloc(ptr)
84+
85+
define internal swifttailcc void @"$s3foo3FooO3baryyYaF.0.1"(ptr %0, ptr %1) !dbg !17 {
86+
entry:
87+
musttail call swifttailcc void %0(ptr swiftasync %1), !dbg !18
88+
ret void, !dbg !18
89+
}
90+
91+
; Function Attrs: nounwind
92+
declare i1 @llvm.coro.end.async(ptr, i1, ...) #0
93+
94+
attributes #0 = { nounwind }
95+
attributes #1 = { nomerge nounwind }
96+
97+
!llvm.dbg.cu = !{!0}
98+
!llvm.module.flags = !{!3, !4}
99+
100+
!0 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !1, producer: "Apple Swift version 5.9-dev (LLVM 1c4b88beb62789b, Swift b00d1520f89bb7d)", isOptimized: false, runtimeVersion: 5, emissionKind: LineTablesOnly, imports: !2)
101+
!1 = !DIFile(filename: "foo.swift", directory: "/tmp")
102+
!2 = !{}
103+
!3 = !{i32 7, !"Dwarf Version", i32 4}
104+
!4 = !{i32 2, !"Debug Info Version", i32 3}
105+
; CHECK-DAG: ![[DECL:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s3foo3FooO3baryyYaF"
106+
; CHECK-DAG: ![[DECL_Q0:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s3foo3FooO3baryyYaFTQ0_"
107+
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s3foo3FooO3baryyYaF"{{.*}}, declaration: ![[DECL]]
108+
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s3foo3FooO3baryyYaFTQ0_"{{.*}}, declaration: ![[DECL_Q0]]
109+
!5 = distinct !DISubprogram(name: "bar", linkageName: "$s3foo3FooO3baryyYaF", scope: !6, file: !1, line: 2, type: !8, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0, declaration: !9, retainedNodes: !2)
110+
!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "$s3foo3FooOD", scope: !7, flags: DIFlagFwdDecl, runtimeLang: DW_LANG_Swift)
111+
!7 = !DIModule(scope: null, name: "foo")
112+
!8 = !DISubroutineType(types: null)
113+
!9 = !DISubprogram(name: "bar", linkageName: "$s3foo3FooO3baryyYaF", scope: !6, file: !1, line: 2, type: !8, scopeLine: 2, spFlags: 0)
114+
!10 = !DILocation(line: 3, column: 11, scope: !5)
115+
!11 = !DILocation(line: 4, column: 3, scope: !5)
116+
!12 = distinct !DISubprogram(linkageName: "__swift_async_resume_project_context", scope: !7, file: !13, type: !8, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
117+
!13 = !DIFile(filename: "<compiler-generated>", directory: "")
118+
!14 = !DILocation(line: 0, scope: !12)
119+
!15 = distinct !DISubprogram(linkageName: "$s3foo3FooO3baryyYaF", scope: !7, file: !13, type: !8, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
120+
!16 = !DILocation(line: 0, scope: !15)
121+
!17 = distinct !DISubprogram(linkageName: "$s3foo3FooO3baryyYaF", scope: !7, file: !13, type: !8, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
122+
!18 = !DILocation(line: 0, scope: !17)

0 commit comments

Comments
 (0)