Skip to content

IRGen: Emit the proper linkageName debug info of the containing function for async suspend dispatch thunks #41654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ IRGenFunction::createAsyncDispatchFn(const FunctionPointer &fnPtr,
IRGenFunction dispatchIGF(IGM, dispatch);
// Don't emit debug info if we are generating a function for the prologue.
if (IGM.DebugInfo && Builder.getCurrentDebugLocation())
IGM.DebugInfo->emitArtificialFunction(dispatchIGF, dispatch);
IGM.DebugInfo->emitOutlinedFunction(dispatchIGF, dispatch, CurFn->getName());
auto &Builder = dispatchIGF.Builder;
auto it = dispatchIGF.CurFn->arg_begin(), end = dispatchIGF.CurFn->arg_end();
llvm::Value *fnPtrArg = &*(it++);
Expand Down
31 changes: 27 additions & 4 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
void emitImport(ImportDecl *D);
llvm::DISubprogram *emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
SILFunctionTypeRepresentation Rep,
SILType Ty, DeclContext *DeclCtx = nullptr);
SILType Ty, DeclContext *DeclCtx = nullptr,
StringRef oulinedFromName = StringRef());
llvm::DISubprogram *emitFunction(SILFunction &SILFn, llvm::Function *Fn);
void emitArtificialFunction(IRBuilder &Builder, llvm::Function *Fn,
SILType SILTy);
void emitOutlinedFunction(IRBuilder &Builder,
llvm::Function *Fn,
StringRef outlinedFromName);

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

StringRef LinkageName;
if (Fn)
if (!outlinedFromName.empty())
LinkageName = outlinedFromName;
else if (Fn)
LinkageName = Fn->getName();
else if (DS)
LinkageName = SILFn->getName();
Expand Down Expand Up @@ -2407,6 +2414,18 @@ void IRGenDebugInfoImpl::emitArtificialFunction(IRBuilder &Builder,
setCurrentLoc(Builder, Scope, ALoc);
}

void IRGenDebugInfoImpl::emitOutlinedFunction(IRBuilder &Builder,
llvm::Function *Fn,
StringRef outlinedFromName) {
RegularLocation ALoc = RegularLocation::getAutoGeneratedLocation();
const SILDebugScope *Scope = new (IGM.getSILModule()) SILDebugScope(ALoc);
emitFunction(Scope, Fn, SILFunctionTypeRepresentation::Thin, SILType(),
nullptr, outlinedFromName);
/// Reusing the current file would be wrong: An objc thunk, for example, could
/// be triggered from any random location. Use a placeholder name instead.
setCurrentLoc(Builder, Scope, ALoc);
}

bool IRGenDebugInfoImpl::handleFragmentDIExpr(
const SILDIExprOperand &CurDIExprOp, SmallVectorImpl<uint64_t> &Operands) {
assert(CurDIExprOp.getOperator() == SILDIExprOperator::Fragment);
Expand Down Expand Up @@ -2911,7 +2930,11 @@ void IRGenDebugInfo::emitArtificialFunction(IRBuilder &Builder,
static_cast<IRGenDebugInfoImpl *>(this)->emitArtificialFunction(Builder, Fn,
SILTy);
}

void IRGenDebugInfo::emitOutlinedFunction(IRBuilder &Builder,
llvm::Function *Fn, StringRef name) {
static_cast<IRGenDebugInfoImpl *>(this)->emitOutlinedFunction(Builder, Fn,
name);
}
void IRGenDebugInfo::emitVariableDeclaration(
IRBuilder &Builder, ArrayRef<llvm::Value *> Storage, DebugTypeInfo Ty,
const SILDebugScope *DS, Optional<SILLocation> VarLoc,
Expand Down
10 changes: 10 additions & 0 deletions lib/IRGen/IRGenDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ class IRGenDebugInfo {
void emitArtificialFunction(IRBuilder &Builder,
llvm::Function *Fn, SILType SILTy = SILType());

inline void emitOutlinedFunction(IRGenFunction &IGF,
llvm::Function *Fn,
StringRef outlinedFromName) {
emitOutlinedFunction(IGF.Builder, Fn, outlinedFromName);
}

void emitOutlinedFunction(IRBuilder &Builder,
llvm::Function *Fn,
StringRef outlinedFromName);

/// Emit a dbg.declare intrinsic at the current insertion point and
/// the Builder's current debug location.
void emitVariableDeclaration(IRBuilder &Builder,
Expand Down
5 changes: 3 additions & 2 deletions test/IRGen/async/get_async_continuation.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// 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
// RUN: %target-swift-frontend -enable-objc-interop -primary-file %s -emit-ir -sil-verify-all

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

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

sil @async_continuation : $@async () -> () {
entry:
Expand Down