diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -1818,6 +1818,7 @@ DISubprogram *getDeclaration() const { return cast_or_null(getRawDeclaration()); } + void replaceDeclaration(DISubprogram *Decl) { replaceOperandWith(6, Decl); } DINodeArray getRetainedNodes() const { return cast_or_null(getRawRetainedNodes()); } diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -937,9 +937,22 @@ // 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); diff --git a/llvm/test/Transforms/Coroutines/coro-async-declaration.ll b/llvm/test/Transforms/Coroutines/coro-async-declaration.ll --- a/llvm/test/Transforms/Coroutines/coro-async-declaration.ll +++ b/llvm/test/Transforms/Coroutines/coro-async-declaration.ll @@ -305,9 +305,11 @@ !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: "", 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)