Skip to content

Commit 6ce76ff

Browse files
committed
Update the linkage name of coro-split functions in the debug info.
This patch updates the linkage name in the DISubprogram of coro-split functions, which is particularly important for Swift, where the funclets have a special name mangling. This patch does not affect C++ coroutines, since the DW_AT_specification is expected to hold the (original) linkage name. I believe this is mostly due to limitations in AsmPrinter, so we might be able to relax this restriction in the future. Differential Revision: https://reviews.llvm.org/D99693
1 parent f2dface commit 6ce76ff

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

+2
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,8 @@ class DISubprogram : public DILocalScope {
20102010

20112011
StringRef getName() const { return getStringOperand(2); }
20122012
StringRef getLinkageName() const { return getStringOperand(3); }
2013+
/// Only used by clients of CloneFunction, and only right after the cloning.
2014+
void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
20132015

20142016
DISubroutineType *getType() const {
20152017
return cast_or_null<DISubroutineType>(getRawType());

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,9 @@ void CoroCloner::create() {
846846

847847
CloneFunctionInto(NewF, &OrigF, VMap,
848848
CloneFunctionChangeType::LocalChangesOnly, Returns);
849+
850+
auto &Context = NewF->getContext();
851+
849852
// For async functions / continuations, adjust the scope line of the
850853
// clone to the line number of the suspend point. The scope line is
851854
// associated with all pre-prologue instructions. This avoids a jump
@@ -855,15 +858,24 @@ void CoroCloner::create() {
855858
if (ActiveSuspend)
856859
if (auto DL = ActiveSuspend->getDebugLoc())
857860
SP->setScopeLine(DL->getLine());
861+
// Update the linkage name to reflect the modified symbol name. It
862+
// is necessary to update the linkage name in Swift, since the
863+
// mangling changes for resume functions. It might also be the
864+
// right thing to do in C++, but due to a limitation in LLVM's
865+
// AsmPrinter we can only do this if the function doesn't have an
866+
// abstract specification, since the DWARF backend expects the
867+
// abstract specification to contain the linkage name and asserts
868+
// that they are identical.
869+
if (!SP->getDeclaration() && SP->getUnit() &&
870+
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift)
871+
SP->replaceLinkageName(MDString::get(Context, NewF->getName()));
858872
}
859873

860874
NewF->setLinkage(savedLinkage);
861875
NewF->setVisibility(savedVisibility);
862876
NewF->setUnnamedAddr(savedUnnamedAddr);
863877
NewF->setDLLStorageClass(savedDLLStorageClass);
864878

865-
auto &Context = NewF->getContext();
866-
867879
// Replace the attributes of the new function:
868880
auto OrigAttrs = NewF->getAttributes();
869881
auto NewAttrs = AttributeList();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ declare void @llvm.coro.async.size.replace(i8*, i8*)
547547
scope: !2, file: !3, line: 1, type: !4,
548548
scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2)
549549
; CHECK: ![[SP2]] = distinct !DISubprogram(name: "my_async_function",
550-
; CHECK-SAME: linkageName: "my_async_function",
550+
; CHECK-SAME: linkageName: "my_async_function.resume.0",
551551
; CHECK-SAME: scopeLine: 2
552552
!2 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !3, emissionKind: FullDebug)
553553
!3 = !DIFile(filename: "/tmp/1.swift", directory: "/")

llvm/test/Transforms/Coroutines/coro-debug.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ attributes #7 = { noduplicate }
114114
!3 = !{i32 2, !"Dwarf Version", i32 4}
115115
!4 = !{i32 2, !"Debug Info Version", i32 3}
116116
!5 = !{!"clang version 5.0.0"}
117-
!6 = distinct !DISubprogram(name: "f", linkageName: "flink", scope: !7, file: !7, line: 55, type: !8, isLocal: false, isDefinition: true, scopeLine: 55, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
117+
!6 = distinct !DISubprogram(name: "f", linkageName: "flink", scope: !7, file: !7, line: 55, type: !8, isLocal: false, isDefinition: true, scopeLine: 55, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2, declaration: !DISubprogram(name: "f", linkageName: "flink", scope: !7, file: !7, line: 55, type: !8, isLocal: false, isDefinition: false, flags: DIFlagPrototyped))
118118
!7 = !DIFile(filename: "simple-repro.c", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")
119119
!8 = !DISubroutineType(types: !9)
120120
!9 = !{!10, !11}

0 commit comments

Comments
 (0)