Skip to content

Commit f1e4296

Browse files
Merge pull request #2824 from adrian-prantl/linkage-name
Update the linkage name of coro-split functions in the debug info.
2 parents 211b6a4 + fc877eb commit f1e4296

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,8 @@ class DISubprogram : public DILocalScope {
20672067

20682068
StringRef getName() const { return getStringOperand(2); }
20692069
StringRef getLinkageName() const { return getStringOperand(3); }
2070+
/// Only used by clients of CloneFunction, and only right after the cloning.
2071+
void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
20702072

20712073
DISubroutineType *getType() const {
20722074
return cast_or_null<DISubroutineType>(getRawType());

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,12 +862,26 @@ void CoroCloner::create() {
862862

863863
CloneFunctionInto(NewF, &OrigF, VMap, /*ModuleLevelChanges=*/true, Returns);
864864

865-
// Adjust the scope line of the clone to the line number of the suspend point.
865+
// For async functions / continuations, adjust the scope line of the
866+
// clone to the line number of the suspend point. The scope line is
867+
// associated with all pre-prologue instructions. This avoids a jump
868+
// in the linetable from the function declaration to the suspend point.
866869
if (DISubprogram *SP = NewF->getSubprogram()) {
867870
assert(SP != OrigF.getSubprogram() && SP->isDistinct());
868871
if (ActiveSuspend)
869872
if (auto DL = ActiveSuspend->getDebugLoc())
870873
SP->setScopeLine(DL->getLine());
874+
// Update the linkage name to reflect the modified symbol name. It
875+
// is necessary to update the linkage name in Swift, since the
876+
// mangling changes for resume functions. It might also be the
877+
// right thing to do in C++, but due to a limitation in LLVM's
878+
// AsmPrinter we can only do this if the function doesn't have an
879+
// abstract specification, since the DWARF backend expects the
880+
// abstract specification to contain the linkage name and asserts
881+
// that they are identical.
882+
if (!SP->getDeclaration() && SP->getUnit() &&
883+
SP->getUnit()->getSourceLanguage() == dwarf::DW_LANG_Swift)
884+
SP->replaceLinkageName(MDString::get(Context, NewF->getName()));
871885
}
872886

873887
NewF->setLinkage(savedLinkage);

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ attributes #7 = { noduplicate }
113113
!3 = !{i32 2, !"Dwarf Version", i32 4}
114114
!4 = !{i32 2, !"Debug Info Version", i32 3}
115115
!5 = !{!"clang version 5.0.0"}
116-
!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)
116+
!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))
117117
!7 = !DIFile(filename: "simple-repro.c", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")
118118
!8 = !DISubroutineType(types: !9)
119119
!9 = !{!10, !11}

0 commit comments

Comments
 (0)