Skip to content

Commit ca1a5b3

Browse files
committed
[Coroutine][DebugInfo] Update the linkage name of the declaration of coro-split functions in the debug info.
This patch adds the linkage name update to DISubprogram's declaration after 6ce76ff. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D157184
1 parent 88a83c9 commit ca1a5b3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

+1
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,7 @@ class DISubprogram : public DILocalScope {
18181818
DISubprogram *getDeclaration() const {
18191819
return cast_or_null<DISubprogram>(getRawDeclaration());
18201820
}
1821+
void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
18211822
DINodeArray getRetainedNodes() const {
18221823
return cast_or_null<MDTuple>(getRawRetainedNodes());
18231824
}

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,22 @@ void CoroCloner::create() {
937937
// abstract specification, since the DWARF backend expects the
938938
// abstract specification to contain the linkage name and asserts
939939
// that they are identical.
940-
if (!SP->getDeclaration() && SP->getUnit() &&
941-
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift)
940+
if (SP->getUnit() &&
941+
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift) {
942942
SP->replaceLinkageName(MDString::get(Context, NewF->getName()));
943+
if (auto *Decl = SP->getDeclaration()) {
944+
auto *NewDecl = DISubprogram::get(
945+
Decl->getContext(), Decl->getScope(), Decl->getName(),
946+
NewF->getName(), Decl->getFile(), Decl->getLine(), Decl->getType(),
947+
Decl->getScopeLine(), Decl->getContainingType(),
948+
Decl->getVirtualIndex(), Decl->getThisAdjustment(),
949+
Decl->getFlags(), Decl->getSPFlags(), Decl->getUnit(),
950+
Decl->getTemplateParams(), nullptr, Decl->getRetainedNodes(),
951+
Decl->getThrownTypes(), Decl->getAnnotations(),
952+
Decl->getTargetFuncName());
953+
SP->replaceDeclaration(NewDecl);
954+
}
955+
}
943956
}
944957

945958
NewF->setLinkage(savedLinkage);

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,11 @@ attributes #13 = { nounwind memory(none) }
305305
!43 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "$s4main5entryOXMtD", file: !44, size: 8, flags: DIFlagArtificial, runtimeLang: DW_LANG_Swift, identifier: "$s4main5entryOXMtD")
306306
!44 = !DIFile(filename: "<compiler-generated>", directory: "")
307307
; CHECK-DAG: ![[DECL:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"
308+
; CHECK-DAG: ![[DECL_Q0:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTQ0_"
309+
; CHECK-DAG: ![[DECL_Y1:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTY1_"
308310
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"{{.*}}, declaration: ![[DECL]]
309-
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"{{.*}}, declaration: ![[DECL]]
310-
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"{{.*}}, declaration: ![[DECL]]
311+
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTQ0_"{{.*}}, declaration: ![[DECL_Q0]]
312+
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTY1_"{{.*}}, declaration: ![[DECL_Y1]]
311313
!45 = !DISubprogram(name: "main", linkageName: "$s4main5entryOAAyyYaFZ", scope: !39, file: !1, line: 2, type: !40, scopeLine: 2, spFlags: 0)
312314
!46 = !{!47, !49}
313315
!47 = !DILocalVariable(name: "self", arg: 1, scope: !38, file: !1, line: 2, type: !48, flags: DIFlagArtificial)

0 commit comments

Comments
 (0)