Skip to content

Commit

Permalink
[Coroutine][DebugInfo] Update the linkage name of the declaration of …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
DianQK committed Aug 8, 2023
1 parent 88a83c9 commit ca1a5b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ class DISubprogram : public DILocalScope {
DISubprogram *getDeclaration() const {
return cast_or_null<DISubprogram>(getRawDeclaration());
}
void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); }
DINodeArray getRetainedNodes() const {
return cast_or_null<MDTuple>(getRawRetainedNodes());
}
Expand Down
17 changes: 15 additions & 2 deletions llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,22 @@ void CoroCloner::create() {
// abstract specification, since the DWARF backend expects the
// abstract specification to contain the linkage name and asserts
// that they are identical.
if (!SP->getDeclaration() && SP->getUnit() &&
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift)
if (SP->getUnit() &&
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift) {
SP->replaceLinkageName(MDString::get(Context, NewF->getName()));
if (auto *Decl = SP->getDeclaration()) {
auto *NewDecl = DISubprogram::get(
Decl->getContext(), Decl->getScope(), Decl->getName(),
NewF->getName(), Decl->getFile(), Decl->getLine(), Decl->getType(),
Decl->getScopeLine(), Decl->getContainingType(),
Decl->getVirtualIndex(), Decl->getThisAdjustment(),
Decl->getFlags(), Decl->getSPFlags(), Decl->getUnit(),
Decl->getTemplateParams(), nullptr, Decl->getRetainedNodes(),
Decl->getThrownTypes(), Decl->getAnnotations(),
Decl->getTargetFuncName());
SP->replaceDeclaration(NewDecl);
}
}
}

NewF->setLinkage(savedLinkage);
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/Transforms/Coroutines/coro-async-declaration.ll
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ attributes #13 = { nounwind memory(none) }
!43 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "$s4main5entryOXMtD", file: !44, size: 8, flags: DIFlagArtificial, runtimeLang: DW_LANG_Swift, identifier: "$s4main5entryOXMtD")
!44 = !DIFile(filename: "<compiler-generated>", directory: "")
; CHECK-DAG: ![[DECL:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"
; CHECK-DAG: ![[DECL_Q0:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTQ0_"
; CHECK-DAG: ![[DECL_Y1:[0-9]+]] = !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTY1_"
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"{{.*}}, declaration: ![[DECL]]
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"{{.*}}, declaration: ![[DECL]]
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZ"{{.*}}, declaration: ![[DECL]]
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTQ0_"{{.*}}, declaration: ![[DECL_Q0]]
; CHECK-DAG: distinct !DISubprogram({{.*}}, linkageName: "$s4main5entryOAAyyYaFZTY1_"{{.*}}, declaration: ![[DECL_Y1]]
!45 = !DISubprogram(name: "main", linkageName: "$s4main5entryOAAyyYaFZ", scope: !39, file: !1, line: 2, type: !40, scopeLine: 2, spFlags: 0)
!46 = !{!47, !49}
!47 = !DILocalVariable(name: "self", arg: 1, scope: !38, file: !1, line: 2, type: !48, flags: DIFlagArtificial)
Expand Down

0 comments on commit ca1a5b3

Please sign in to comment.