Skip to content

Commit 03e3219

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 (cherry picked from commit ca1a5b3)
1 parent c761d7f commit 03e3219

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,7 @@ class DISubprogram : public DILocalScope {
20852085
DISubprogram *getDeclaration() const {
20862086
return cast_or_null<DISubprogram>(getRawDeclaration());
20872087
}
2088+
void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
20882089
DINodeArray getRetainedNodes() const {
20892090
return cast_or_null<MDTuple>(getRawRetainedNodes());
20902091
}

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,22 @@ void CoroCloner::create() {
932932
// abstract specification, since the DWARF backend expects the
933933
// abstract specification to contain the linkage name and asserts
934934
// that they are identical.
935-
if (!SP->getDeclaration() && SP->getUnit() &&
936-
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift)
935+
if (SP->getUnit() &&
936+
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift) {
937937
SP->replaceLinkageName(MDString::get(Context, NewF->getName()));
938+
if (auto *Decl = SP->getDeclaration()) {
939+
auto *NewDecl = DISubprogram::get(
940+
Decl->getContext(), Decl->getScope(), Decl->getName(),
941+
NewF->getName(), Decl->getFile(), Decl->getLine(), Decl->getType(),
942+
Decl->getScopeLine(), Decl->getContainingType(),
943+
Decl->getVirtualIndex(), Decl->getThisAdjustment(),
944+
Decl->getFlags(), Decl->getSPFlags(), Decl->getUnit(),
945+
Decl->getTemplateParams(), nullptr, Decl->getRetainedNodes(),
946+
Decl->getThrownTypes(), Decl->getAnnotations(),
947+
Decl->getTargetFuncName());
948+
SP->replaceDeclaration(NewDecl);
949+
}
950+
}
938951
}
939952

940953
NewF->setLinkage(savedLinkage);

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

Lines changed: 4 additions & 2 deletions
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)