Skip to content

Commit 89f28fc

Browse files
Merge pull request #41654 from aschwaighofer/debug_info_linkage_name_async_suspend_dispatch
IRGen: Emit the proper linkageName debug info of the containing function for async suspend dispatch thunks
2 parents 48e23a6 + 189b0ac commit 89f28fc

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
23752375
IRGenFunction dispatchIGF(IGM, dispatch);
23762376
// Don't emit debug info if we are generating a function for the prologue.
23772377
if (IGM.DebugInfo && Builder.getCurrentDebugLocation())
2378-
IGM.DebugInfo->emitArtificialFunction(dispatchIGF, dispatch);
2378+
IGM.DebugInfo->emitOutlinedFunction(dispatchIGF, dispatch, CurFn->getName());
23792379
auto &Builder = dispatchIGF.Builder;
23802380
auto it = dispatchIGF.CurFn->arg_begin(), end = dispatchIGF.CurFn->arg_end();
23812381
llvm::Value *fnPtrArg = &*(it++);

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
204204
void emitImport(ImportDecl *D);
205205
llvm::DISubprogram *emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
206206
SILFunctionTypeRepresentation Rep,
207-
SILType Ty, DeclContext *DeclCtx = nullptr);
207+
SILType Ty, DeclContext *DeclCtx = nullptr,
208+
StringRef oulinedFromName = StringRef());
208209
llvm::DISubprogram *emitFunction(SILFunction &SILFn, llvm::Function *Fn);
209210
void emitArtificialFunction(IRBuilder &Builder, llvm::Function *Fn,
210211
SILType SILTy);
212+
void emitOutlinedFunction(IRBuilder &Builder,
213+
llvm::Function *Fn,
214+
StringRef outlinedFromName);
211215

212216
/// Return false if we fail to create the right DW_OP_LLVM_fragment operand.
213217
bool handleFragmentDIExpr(const SILDIExprOperand &CurDIExprOp,
@@ -2261,7 +2265,8 @@ llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,
22612265
llvm::DISubprogram *
22622266
IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
22632267
SILFunctionTypeRepresentation Rep,
2264-
SILType SILTy, DeclContext *DeclCtx) {
2268+
SILType SILTy, DeclContext *DeclCtx,
2269+
StringRef outlinedFromName) {
22652270
auto Cached = ScopeCache.find(DS);
22662271
if (Cached != ScopeCache.end()) {
22672272
auto SP = cast<llvm::DISubprogram>(Cached->second);
@@ -2277,7 +2282,9 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
22772282
auto *SILFn = DS ? DS->Parent.dyn_cast<SILFunction *>() : nullptr;
22782283

22792284
StringRef LinkageName;
2280-
if (Fn)
2285+
if (!outlinedFromName.empty())
2286+
LinkageName = outlinedFromName;
2287+
else if (Fn)
22812288
LinkageName = Fn->getName();
22822289
else if (DS)
22832290
LinkageName = SILFn->getName();
@@ -2407,6 +2414,18 @@ void IRGenDebugInfoImpl::emitArtificialFunction(IRBuilder &Builder,
24072414
setCurrentLoc(Builder, Scope, ALoc);
24082415
}
24092416

2417+
void IRGenDebugInfoImpl::emitOutlinedFunction(IRBuilder &Builder,
2418+
llvm::Function *Fn,
2419+
StringRef outlinedFromName) {
2420+
RegularLocation ALoc = RegularLocation::getAutoGeneratedLocation();
2421+
const SILDebugScope *Scope = new (IGM.getSILModule()) SILDebugScope(ALoc);
2422+
emitFunction(Scope, Fn, SILFunctionTypeRepresentation::Thin, SILType(),
2423+
nullptr, outlinedFromName);
2424+
/// Reusing the current file would be wrong: An objc thunk, for example, could
2425+
/// be triggered from any random location. Use a placeholder name instead.
2426+
setCurrentLoc(Builder, Scope, ALoc);
2427+
}
2428+
24102429
bool IRGenDebugInfoImpl::handleFragmentDIExpr(
24112430
const SILDIExprOperand &CurDIExprOp, SmallVectorImpl<uint64_t> &Operands) {
24122431
assert(CurDIExprOp.getOperator() == SILDIExprOperator::Fragment);
@@ -2911,7 +2930,11 @@ void IRGenDebugInfo::emitArtificialFunction(IRBuilder &Builder,
29112930
static_cast<IRGenDebugInfoImpl *>(this)->emitArtificialFunction(Builder, Fn,
29122931
SILTy);
29132932
}
2914-
2933+
void IRGenDebugInfo::emitOutlinedFunction(IRBuilder &Builder,
2934+
llvm::Function *Fn, StringRef name) {
2935+
static_cast<IRGenDebugInfoImpl *>(this)->emitOutlinedFunction(Builder, Fn,
2936+
name);
2937+
}
29152938
void IRGenDebugInfo::emitVariableDeclaration(
29162939
IRBuilder &Builder, ArrayRef<llvm::Value *> Storage, DebugTypeInfo Ty,
29172940
const SILDebugScope *DS, Optional<SILLocation> VarLoc,

lib/IRGen/IRGenDebugInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ class IRGenDebugInfo {
145145
void emitArtificialFunction(IRBuilder &Builder,
146146
llvm::Function *Fn, SILType SILTy = SILType());
147147

148+
inline void emitOutlinedFunction(IRGenFunction &IGF,
149+
llvm::Function *Fn,
150+
StringRef outlinedFromName) {
151+
emitOutlinedFunction(IGF.Builder, Fn, outlinedFromName);
152+
}
153+
154+
void emitOutlinedFunction(IRBuilder &Builder,
155+
llvm::Function *Fn,
156+
StringRef outlinedFromName);
157+
148158
/// Emit a dbg.declare intrinsic at the current insertion point and
149159
/// the Builder's current debug location.
150160
void emitVariableDeclaration(IRBuilder &Builder,

test/IRGen/async/get_async_continuation.sil

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-objc-interop -primary-file %s -emit-ir -sil-verify-all -disable-llvm-optzns -disable-swift-specific-llvm-optzns | %IRGenFileCheck %s
1+
// RUN: %target-swift-frontend -g -enable-objc-interop -primary-file %s -emit-ir -sil-verify-all -disable-llvm-optzns -disable-swift-specific-llvm-optzns | %IRGenFileCheck %s
22
// RUN: %target-swift-frontend -enable-objc-interop -primary-file %s -emit-ir -sil-verify-all
33

44
// REQUIRES: concurrency
@@ -72,10 +72,11 @@ bb0:
7272
// CHECK: {{musttail call swifttailcc|tail call swiftcc}} void @swift_continuation_await(%swift.continuation_context* %0)
7373
// CHECK-NEXT: ret void
7474

75-
// CHECK: define {{.*}} void @async_continuation.0(i8* %0, %swift.context* %1)
75+
// CHECK: define {{.*}} void @async_continuation.0(i8* %0, %swift.context* %1){{.*}}!dbg ![[DBG:[0-9]+]]
7676
// CHECK-NOT: define
7777
// CHECK: tail call swift{{(tail)?}}cc void %{{.*}}(%swift.context* swiftasync %1)
7878
// CHECK-NEXT: ret void
79+
// CHECK: ![[DBG]] = distinct !DISubprogram(linkageName: "async_continuation"
7980

8081
sil @async_continuation : $@async () -> () {
8182
entry:

0 commit comments

Comments
 (0)